Sub topic 2
The Reasoning Engine Behind the Agent
This chapter assumes you know what an Agentforce agent is and that it is built from topics, instructions, and actions. It also assumes you have a general idea of what a large language model (LLM) does. Here you will learn what the reasoning engine is, what it receives, what it decides, and what it does not do. Later chapters cover topic classification, the reasoning loop, and action selection in detail.
What the reasoning engine is
The reasoning engine is the component that interprets a user's request and decides what the agent should do next. In Agentforce it is called the Atlas Reasoning Engine. It uses an LLM to read natural language, but it is more than the model alone. The engine does four things:
- It assembles the text the LLM reads: the agent's configuration, the conversation so far, and relevant data.
- It sends that text to the LLM and reads back the model's proposed decision.
- It runs the actions the decision calls for, such as a Flow or an Apex method.
- It feeds the results back to the model so the model can decide whether to act again or answer.
Your configuration (topics, instructions, action descriptions) is the material the engine works from. You do not write code that branches on the user's words. You write text, and the engine hands that text to the model to interpret.
What the LLM does and does not do
Keeping the roles apart helps with debugging. The LLM only reads text and produces text. It cannot query your org, update a record, or call an API. All of that happens in your actions, which run on the Salesforce platform under your org's permissions.
| Responsibility | Handled by |
|---|---|
| Understanding what the user wants | LLM |
| Choosing a topic and an action | LLM, guided by your descriptions |
| Filling in action inputs from the conversation | LLM |
| Running a Flow, Apex method, or prompt template | Salesforce platform |
| Enforcing record and field access | Salesforce platform |
| Writing the reply in natural language | LLM, from the action results |
Two consequences follow:
- A wrong decision is usually a text problem. The model chose using the descriptions you wrote, so unclear descriptions lead to unclear choices.
- A wrong fact in a reply is usually a data problem. If an action returned bad data, or no action ran, the model may fill the gap with plausible wording. Grounding, covered in a later chapter, addresses this.
What the engine sends to the model
On each turn the engine builds a prompt. The exact format is internal to Salesforce and can change, so treat the following as a simplified picture and not a specification.
[Agent-level instructions and role]
You are a support agent for Example Co. ...
[Topics available]
- Order Support: Handles customer questions about the status of an existing order.
- Returns: Handles requests to return or exchange an item.
[Selected topic: Order Support]
Scope: Look up order status and explain it. Does not process returns.
Instructions:
- Ask for the order number if the customer has not given one.
- Use the order status action to look up the order before answering.
Available actions:
- Get Order Status: Looks up the current status of an order by its order number.
Input: Order Number (The order number the customer provided)
[Conversation so far]
Customer: Where is my order 10482?
[Task]
Decide the next step: call an action, ask a question, or answer.The example shows three points about how you influence the engine:
- The model sees only what is in the prompt. Anything you did not write down, such as an unstated business rule, is invisible to it.
- Action labels and descriptions are part of the prompt. This is why the Apex example in the plan puts
labelanddescriptionon the method and its variables. - Prompt size is finite. Long instructions, many topics, and many actions compete for the same space and for the model's attention.
The decision cycle at a glance
The engine does not make one decision and stop. It repeats a cycle until it has something to say to the user. This chapter only sketches that cycle. The reasoning loop chapter covers it step by step.
The model is called at least twice in this turn: once to decide, and once to turn the result into a reply. A request that needs two lookups needs more calls. Each call adds latency, and each can take a different path.
Probabilistic behavior
An LLM generates text by choosing likely next tokens. It does not execute rules. In practice:
- Two identical requests can lead to slightly different wording, and occasionally to a different choice.
- Instructions work as strong guidance, not as guarantees. A rule like "never promise a delivery date" can still be violated, especially if it conflicts with other text in the prompt.
- Ambiguous requests tend to produce inconsistent behavior, because several choices are about equally plausible to the model.
Because of this, put hard requirements in the layer that enforces them. For example, check eligibility in the Flow or Apex that runs the action, and do not rely only on an instruction saying "only refund eligible orders". Use instructions to steer the model, and use deterministic logic to guarantee outcomes.
The model and the Einstein Trust Layer
The reasoning engine does not call an LLM directly. Requests to the model pass through the Einstein Trust Layer, which handles protections such as masking sensitive data before it leaves Salesforce and checking responses. A later chapter covers it. For now, remember that the engine's prompt is not sent raw to a model provider. The layer sits between them.
Which model is used depends on how your org is set up. Salesforce provides default models, and some orgs can connect other supported models. Check Salesforce's current documentation for what is available in your org, because options change between releases. Whatever the model, your configuration stays the same, but behavior can differ between models. If you change the model, retest your agent.
Failure modes
These are the common ways the engine's behavior surprises people, with the usual cause of each.
- The agent answers without calling an action. The model decided it could reply from the conversation alone. The instructions probably never say to look data up first. Add a line such as "Use the order status action before answering."
- The agent picks the wrong action. Two action descriptions overlap, or a description is vague. Rewrite them so each states what it does and when to use it.
- The agent invents an input. The model filled in a required value it did not have. Mark the input as required, describe it clearly, and add an instruction to ask the user when it is missing.
- Behavior changes between runs. The request is ambiguous, or the instructions conflict. Narrow the scope and remove contradictions.
- Quality drops as you add content. Too many topics, actions, or long instructions dilute the prompt. Keep each topic focused and split large ones.
- A change in model changes results. Descriptions that worked for one model may read differently to another. Rerun your test cases after any model change.
Practical guidance
- Write for a reader who knows nothing about your business. The model has only the prompt.
- Say what each action does, and when it should not be used.
- Keep decisions that must be correct in Flow or Apex, where they are deterministic.
- Test with varied phrasings of the same request, not just one example.
- When behavior is wrong, ask what text the model saw. The testing chapter shows how to view that.
Exercise
A customer asks an agent to refund an order. The refund action has the description "Handles refunds". The agent sometimes refunds orders that are past the 30-day limit, even though a topic instruction says "Only refund orders within 30 days." Why does this happen, and what are two changes that would reduce it?
Show answer
The LLM treats the instruction as guidance, not as an enforced rule, and the action description gives it no hint about the limit. It can overlook or misapply the instruction. First, make the action itself enforce the limit: have the Flow or Apex check the order date and return a clear "not eligible" result. This guarantees the outcome. Second, improve the text the model reads: describe the action as "Refunds an order placed within the last 30 days" and add an instruction to explain the policy when the action reports an order is ineligible.
Exercise
In the sequence diagram, why does the engine call the LLM a second time after the action returns?
Show answer
The action result is data, not a reply. The engine sends it back to the model so the model can decide whether another action is needed or write the natural-language response to the user.