Sub topic 5
How the reasoning engine picks topics and actions
This chapter assumes you know what topics, instructions, and actions are, and that you have a general idea of what a large language model (LLM) does. It explains how the reasoning engine uses those pieces to answer one customer or employee message.
The agent loop
The reasoning engine is the part of Agentforce that decides what the agent does next. It does not follow a fixed script. For each user message it repeats a loop until it has an answer to return.
- Read the message and the conversation so far.
- Choose a topic.
- Read that topic's instructions and see which actions it offers.
- Either call an action or reply to the user.
- If an action ran, read its result and decide again.
How a topic is chosen
The engine compares the message with the classification description of every topic on the agent. It picks the topic whose description fits best. The match is made by an LLM, so it is a judgment about meaning, not a keyword test.
Take the Order Status topic from earlier chapters. Its classification description is "Customer asks where an order is or what state it is in." The message "Has my package shipped yet?" contains none of those words, but it still fits that description. The engine can route it to that topic.
Two consequences follow:
- The classification description is the most important text for routing. Keep it short and specific to one job.
- Two topics with overlapping descriptions compete. The engine may choose either one, and may choose differently on different runs.
How an action is chosen
Once a topic is selected, only that topic's actions are available. The engine reads the topic's instructions and the description of each action, then decides whether to call one.
For an action to be called, the engine needs to fill in its inputs. In the Apex example from the previous chapter, the action Get Order Status needs an order number. If the customer has not given one, an instruction such as "Ask for the order number if the customer has not given one" makes the engine ask before calling. The engine takes input values from the conversation. It should not invent them.
After the action returns, the engine reads the output and applies the instructions again. In the Order Status topic, the instruction says to report only the returned status. The 'Order not found' branch is handled the same way: the engine reads the result and follows the matching instruction.
Why the same engine serves both agent types
Service agents and employee agents run the same loop. What differs is the content around it: the topics, the actions, and the identity under which actions run. An employee agent's "My Open Cases" topic is routed and executed exactly like Order Status. Only the data its actions can return changes, because it depends on the user's permissions.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Agent picks the wrong topic | Overlapping classification descriptions | Rewrite descriptions so each covers one distinct job |
| Agent never calls an action | Instructions do not say when to use it, or the action description is vague | Name the action in the instructions and state the trigger |
| Agent answers from its own knowledge instead of calling an action | Topic scope is too broad | Narrow the scope and add "report only what the action returns" |
| Agent asks for information repeatedly | Instructions do not say what to do after one failed attempt | Add a limit, such as asking once and then offering a human |
Exercise
A customer writes "I want my money back for order 1042." The agent has two topics: Order Status ("Customer asks about an order") and Refunds ("Customer asks for a refund or return"). The agent keeps choosing Order Status. What is the most likely cause, and what is one fix?
Show answer
The Order Status classification description is too broad. "Asks about an order" also matches a refund request that mentions an order number, so the two descriptions overlap. Narrow it to "Customer asks where an order is or what state it is in", and make the Refunds description explicitly cover requests for money back.
Exercise
In the agent loop, what happens after an action returns its result?
Show answer
The engine reads the result and applies the topic's instructions again. It then either calls another action or sends a reply to the user.