Sub topic 1
How an agent turns a request into a response
An Agentforce agent does not run a fixed script. It reads what the user said, picks the job that fits, and decides which steps to take. This chapter gives you the working model of that loop. Later chapters cover each part in detail.
Prerequisites
This chapter assumes you know the following:
- Basic Salesforce concepts: objects, fields, and records.
- Where to find Setup in a Salesforce org.
- What a large language model (LLM) does at a high level: it reads text and produces text.
- Flow or Apex are helpful for the action discussion, but you don't need them yet.
The three building blocks
An agent is built from three parts that work together.
- Topics group a job the agent can do, such as "Order Status" or "Password Help." A topic has a name, a classification description, a scope, and instructions.
- Instructions are natural-language guidance inside a topic. They tell the agent's reasoning how to handle requests in that topic.
- Actions are the things the agent can do: read or change data, run logic, or generate text. An action is a Flow, an Apex method, a prompt template, or a standard action.
A useful way to hold the model in your head:
| Part | Question it answers | Who reads it |
|---|---|---|
| Topic name and classification description | Is this request mine? | The agent, when choosing a topic |
| Scope | Where does my job start and end? | The agent, while working inside the topic |
| Instructions | How should I handle this request? | The agent, while planning its steps |
| Actions | What can I actually do? | The agent, when it needs data or needs to change something |
Everything the agent "knows" about your business comes from these parts, from the data its actions return, and from the conversation so far. If a behavior is missing, one of these parts is missing or unclear.
The request-to-response loop
Each time the user sends a message, the agent runs through the same stages.
- Receive the request. The agent takes the user's message along with the conversation history.
- Classify the topic. The agent's reasoning compares the request against the name and classification description of every topic. It selects the best match.
- Load the topic's context. Once a topic is selected, the agent works with that topic's scope, instructions, and actions. Other topics' instructions and actions are not in play for this step.
- Plan. The reasoning decides what to do next. It might ask the user for a missing value, call an action, or answer directly.
- Run actions. If the plan calls for an action, the agent fills the action's inputs, runs it, and reads the outputs.
- Re-evaluate. The agent looks at the results. It may call another action, ask a follow-up question, or decide it has enough to answer.
- Respond. The agent writes a reply for the user, based on the instructions and the action results.
Steps 4 to 6 can repeat several times for one message. The agent keeps planning until it can respond.
A worked trace
Suppose your agent has two topics: Order Status and Returns. The Order Status topic has one action, Get Order Status, and these instructions:
1. Ask the customer for their order number if they have not given one.
2. Use the Get Order Status action with that order number.
3. If the action returns 'Not found', tell the customer you could not find the order and ask them to check the number.
4. Otherwise, state the status in one sentence.A customer writes: "Hi, can you tell me where my package is?"
Turn 1
User: Hi, can you tell me where my package is?
Topic: Order Status (request is about the location of an existing order)
Plan: Instruction 1 applies. No order number yet.
Action: none
Reply: Sure. What is your order number?
Turn 2
User: It's 1042
Topic: Order Status (conversation already about this job)
Plan: Instruction 2 applies. Order number is available.
Action: Get Order Status(orderNumber = "1042") -> status = "Shipped"
Plan: Instruction 4 applies.
Reply: Your order 1042 has shipped.Three things to notice:
- The agent asked a question instead of calling the action. Its action needs an input, and the instruction told it to collect that input first.
- The topic was chosen again on turn 2. Topic selection is not a one-time decision. The agent considers the topic on each message, using the new text and the history.
- The reply came from the action's output, not from the model's memory. The agent did not guess the status.
Why classification comes first
Topic classification is the most sensitive step in the loop. Everything after it depends on the topic being right. If the agent picks the wrong topic, it uses the wrong instructions and the wrong actions, and the reply can be wrong even when each later step works correctly.
The agent decides using the text you write in each topic's name and classification description. That has practical consequences:
- Vague descriptions such as "Handle customer questions" match almost everything and cause overlap.
- Two topics that describe similar jobs make the choice a coin flip.
- A request that fits no topic has no good home. Depending on your setup, the agent may fall back to a general response or ask for clarification.
You will learn how to write names and descriptions that stay distinct in the chapters on topics. For now, remember that classification is a text-matching judgment, not a keyword lookup. The agent is reasoning about meaning, so clear and specific wording matters more than the exact words.
What the agent decides and what you decide
The agent is non-deterministic in its wording and flexible in its choices. You can't specify every path. You steer it with the text and configuration you provide.
| You control | The agent decides |
|---|---|
| Which topics exist | Which topic fits a given message |
| What each topic covers and excludes | Whether the message is in scope |
| The steps and rules in instructions | How to apply those steps to this conversation |
| Which actions are available in a topic | Whether and when to call them, and with what input values |
| What an action does and returns | How to phrase the result for the user |
Common errors at this stage
These problems come from misunderstanding the loop, not from bugs in a single part.
- The agent answers from general knowledge. The topic has no action for the data, or the instructions don't say to use one. The agent fills the gap with plausible text.
- The wrong topic handles the request. Two classification descriptions overlap, or the right one is too narrow.
- The agent never calls an action. The action's name or description doesn't match the situation, or the instructions don't say when to use it.
- The agent calls an action with a wrong or empty input. The input wasn't described clearly, or the agent didn't collect the value from the user first.
- The agent drifts out of scope. The scope doesn't say what the topic must not do, so the agent tries to be helpful anyway.
When you test an agent, trace the failure back through the loop: Was the right topic chosen? Did the plan follow the instructions? Was the right action called with the right input? Did the reply reflect the result? Finding the first stage that went wrong tells you which part to edit.
Where Agentforce Builder fits
Agentforce Builder is the workspace where you create and edit these parts, then run the agent to see the loop in action. You define topics, write instructions, attach actions, and use the conversation preview to test. The next chapter walks through the Builder layout. Later chapters return to each stage of the loop and show how to write the part that controls it.
Key points
- An agent has three main building blocks: topics, instructions, and actions.
- For each message, the agent classifies a topic, plans with that topic's instructions, runs actions, re-evaluates, and replies.
- Topic selection can change from one message to the next.
- Replies about your data should come from action outputs.
- Instructions guide the agent but don't guarantee behavior, so enforce critical rules in the action.
- Debug by following the loop in order and fixing the earliest stage that failed.
Exercise
A customer asks, "Can I send back the shoes I bought last week?" Your agent has the topics Order Status and Returns, but it answers using the Order Status instructions and asks for an order number to look up shipping. Which stage of the loop most likely went wrong, and what should you check first?
Show answer
Topic classification went wrong. The agent picked Order Status instead of Returns, so the later stages used the wrong instructions and actions. Check the names and classification descriptions of both topics. Look for an Order Status description that is too broad, or a Returns description that does not clearly cover sending items back. Fix the descriptions before changing any instructions.
Exercise
In the worked trace, why does the agent ask for the order number on turn 1 instead of calling Get Order Status right away?
Show answer
The action needs an order number as input, and the user hasn't provided one. Instruction 1 tells the agent to ask for it first. The agent plans its next step from the instructions and the information it has, so it collects the missing value before it runs the action.