Sub topic 8
The reasoning loop from request to response
This chapter assumes you know what topics, instructions, and actions are in an Agentforce agent, and that you have a general idea of what a large language model (LLM) does. Here you will follow one request through the whole loop, from the user's message to the agent's reply.
What the loop is
The reasoning loop is the cycle the reasoning engine runs for each user message. The engine does not run a fixed script. It asks the LLM what to do next, carries out the answer, looks at the result, and asks again. It stops when the LLM decides it can reply.
The loop has four repeating steps:
- Classify. Match the request to a topic.
- Plan. Using the topic's instructions and the list of its actions, decide the next step.
- Act. Run the chosen action, or ask the user for a missing input.
- Check. Read the action's result and decide whether another step is needed or the agent can answer.
A worked example
Take the Order Support topic from the earlier chapters. A customer writes: "Where is my order?"
- Classify. The request matches the classification description "questions about the status of an existing order", so the engine enters Order Support.
- Plan. The instructions say to ask for the order number if it is missing. The message has none, so the next step is a question to the user.
- Act. The agent replies: "Sure, what is your order number?" This ends the first pass.
- The customer answers "10482". This is a new message, and it runs through the loop again with the earlier conversation as context.
- Plan and act. The number is now available, so the engine selects the Get Order Status action and passes
10482as the order number input. - Check. The action returns a status such as "Shipped". The engine adds this to its context and asks the LLM what to do next. Nothing else is needed, so it drafts the reply.
Notice that one action can happen within one pass, and several can happen if the first result raises a new need. The LLM decides this each time, based on the instructions and what it has seen so far.
What the LLM sees at each step
Each time the engine asks "what next?", the prompt is built from several parts:
| Part | Where it comes from |
|---|---|
| Topic scope and instructions | The topic you configured |
| Available actions with labels and descriptions | The actions added to the topic |
| Conversation history | Earlier messages in this session |
| Variables | Values stored during the session |
| Results so far | Output from actions already run in this pass |
The model can only choose among actions listed in the current topic. This is why a precise scope matters. An action outside the topic is never a candidate.
Common errors
- Wrong topic, so wrong actions. If classification picks the wrong topic, the right action is not even on the list. Check the topic description first.
- Loops that do not end. Vague instructions can make the agent call the same action repeatedly. State when to stop, such as "answer once the status is returned".
- Guessing instead of asking. If instructions do not say what to do about a missing input, the model may invent a value. Tell it to ask.
- Ignoring a failed action. An action may return "Not Found". Instructions should say how to respond to that result, as in the Order Support example.
Exercise
A customer asks "Can I get a refund?" while the agent is in the Order Support topic, which has only the Get Order Status action. What will the reasoning loop most likely do, and what should you change so the request is handled properly?
Show answer
The engine can only choose among the actions in the current topic, and the topic scope excludes refunds. The agent will most likely explain that it cannot help with refunds, or it may misuse Get Order Status. To fix this, create a Returns and Refunds topic with its own description and refund action, so classification routes the request there instead of staying in Order Support.
Exercise
In the worked example, why does the loop run twice for one conversation?
Show answer
The first message had no order number, so the instructions led the agent to ask for it. That reply ended the first pass. The customer's answer was a new message, which started a second pass where the action could run with the number.