Sub topic 1
How an Agentforce agent decides what to do
An Agentforce agent does not follow a fixed script. For each message, a large language model (LLM) decides which part of its configuration applies, what to do about it, and when it has enough information to answer. This chapter describes that decision process. The rest of the tutorial builds on it when you add standard actions and write instructions for them.
Prerequisites
This chapter assumes you already know the following:
- The basic Salesforce data model: objects, fields, and records.
- How to move around Setup and the Lightning Experience UI.
- What an AI agent and a large language model are, at a general level.
- That permission sets and profiles control what a user can see and change.
You do not need to have built an agent before. You do not need to have used Agentforce Builder yet.
The building blocks
An agent is assembled from a few configured pieces. Each one has a different job in the decision process.
| Piece | What it is | Role in the decision |
|---|---|---|
| Agent | The assistant as a whole, with a role and company context | Sets overall behavior and tone |
| Topic | A defined area of work, such as account support | Narrows what the agent considers for a request |
| Instructions | Natural-language rules written inside a topic | Guide how the agent uses actions and when it asks the user questions |
| Action | A prebuilt or custom capability the agent can run | Does the work: reads, writes, summarizes, drafts |
| Conversation context | The messages so far, plus action results | Gives the agent what it needs for the next step |
The LLM reads the text of these pieces. It does not run code to decide anything. That is why the wording of topic names, descriptions, and instructions has a direct effect on behavior.
The reasoning loop
For each user message, the agent repeats a loop until it can reply. The Salesforce reasoning engine runs this loop, and the LLM makes each judgment inside it.
- Interpret the request. The agent reads the user's message together with the conversation so far.
- Choose a topic. It compares the request to each topic's name and classification description, then selects the best match.
- Plan within the topic. It reads that topic's instructions and the list of actions available in the topic.
- Run an action, or ask. If it has the inputs an action needs, it runs the action. If an input is missing or ambiguous, it asks the user.
- Evaluate the result. The action's output is added to the conversation. The agent decides whether another action is needed or whether it can answer.
- Reply. It writes a response grounded in the action results and the instructions.
Two parts of this loop explain most surprising agent behavior. The first is topic selection, because everything after it depends on it. The second is the check for missing inputs, because it decides whether the agent asks or guesses.
Step 1: Topic selection
The agent can only use actions from the topic it selected. A wrong topic therefore means the right action is not even considered.
Topic selection relies on the classification description. This is a short statement of what requests belong to the topic. It works best when it names the kind of request and the kind of data involved.
A weak description:
Handle account stuff.A stronger description:
Handle questions about a customer's account, such as looking up an account, summarizing it, or updating basic fields.Overlap causes most topic errors. If two topics both claim "questions about customers", the agent may pick either one, and the choice can differ between runs. Write each description so that a given request fits one topic better than any other. Name what a topic excludes when the boundary is not obvious.
Step 2: Instructions steer action use
Inside a topic, instructions tell the agent how to behave. The agent is not forced to follow them like code. It weighs them as guidance, so clear and specific rules work better than broad ones.
Good instructions cover three things:
- When to use each action.
- In what order to use actions when one depends on another.
- When to ask the user for confirmation or clarification.
Here is an example topic with all three:
Topic: Account Support
Classification description:
Handle questions about a customer's account, such as looking up an account, summarizing it, or updating basic fields.
Instructions:
1. When the user names an account, first find the account record, then use the result for any later step.
2. Use the summary action when the user asks for an overview of an account.
3. Before updating a record, restate the field and the new value and ask the user to confirm.
4. If you cannot find exactly one matching record, ask the user to clarify instead of guessing.Instruction 1 sets an order. Instruction 2 maps a kind of request to an action. Instruction 3 adds a confirmation step before a change. Instruction 4 defines what to do when a lookup is ambiguous, so the agent asks and does not pick a record at random.
Keep the instructions short and testable. Each one should describe a behavior you can check in a test conversation.
Step 3: Inputs decide whether an action runs
Every action declares inputs, which are the values it needs, and outputs, which are the values it returns. When the agent chooses an action, it tries to fill each input from the conversation. This is called slot filling. A later chapter covers it in detail. For now, note the three possible outcomes:
- The user's message or an earlier action result supplies the value, and the action runs.
- The value is missing, and the agent asks the user for it.
- The value is ambiguous, and the agent may guess unless the instructions tell it not to.
The third outcome is the main source of wrong results. Instruction 4 in the example above exists to prevent it. Without it, "update the Acme account" could match several accounts, and the agent could pick one.
Step 4: Results feed the next decision
An action's output goes back into the conversation as context. The agent reads it before deciding what to do next. This is how steps connect. A lookup action returns a record ID, and the agent passes that ID to a later action that needs it.
Two consequences follow:
- The agent can only chain on information that appeared in an earlier output or message. If an action does not return a field, later steps cannot use it.
- The final reply is based on what the actions returned. If an action returns nothing, the agent should say so. A good instruction tells it to do that, so it does not fill the gap with invented content.
Why results vary between runs
The reasoning engine uses an LLM, so the same request can produce slightly different wording or, with weak instructions, different action choices. You reduce this variation through configuration, not code:
- Make classification descriptions distinct from each other.
- Give each action a clear name and description, because the agent reads these to choose.
- Put ordering rules and confirmation rules in the instructions.
- Keep the number of actions per topic small, so fewer options compete.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| The agent says it cannot help, or answers generically | The request matched no topic well | Broaden or sharpen the classification description |
| The agent uses the wrong topic | Two descriptions overlap | Rewrite them so each request fits one topic |
| The agent skips an action you expected | The instructions never say when to use it | Add a rule that maps the request to the action |
| The agent updates the wrong record | The lookup was ambiguous and nothing told it to ask | Add a "find exactly one match or ask" rule |
| The agent changes data without asking | No confirmation rule | Add a restate-and-confirm instruction |
Summary of the model
For each message, the agent picks a topic, reads that topic's instructions, fills action inputs from the conversation, runs actions, reads their outputs, and replies. You control each step through the text you write in topic descriptions, instructions, and action definitions. The next chapters cover topics and instructions in more detail and then move on to actions.
Exercise
A user asks, "Give me an overview of the Acme account." Your agent has an Account Support topic and an Order Support topic. It answers with a general apology and runs no action. Name two configuration problems that could cause this, and one fix for each.
Show answer
First, topic selection may have failed. The Account Support classification description may be too vague, or it may overlap with Order Support, so the agent did not match the request to a topic. Fix it by rewriting the descriptions so that account lookups and summaries clearly belong to Account Support. Second, the selected topic's instructions may never say to use the summary action for overview requests, or the topic may not include a summary action. Fix it by adding the action to the topic and an instruction such as "Use the summary action when the user asks for an overview of an account."
Exercise
Why does the example topic say "If you cannot find exactly one matching record, ask the user to clarify instead of guessing"? What step of the reasoning loop does it affect?
Show answer
It affects the input check, where the agent decides whether it has all the inputs for an action. A name such as "Acme" can match several records, so the input is ambiguous. Without the rule, the agent may pick one and run a later action, such as an update, on the wrong record. The rule makes the agent ask the user instead.