Sub topic 1
How agents, topics, and actions fit together
Prerequisites
This chapter assumes you already know the following:
- The Salesforce data model: objects, fields, and records.
- Flow Builder basics: variables, elements, and resources.
- Where to find Setup and how permission sets grant access.
- A general idea of what an AI agent is: a program that uses a language model to decide what to do next.
You do not need to have built an Agentforce agent before. This chapter gives you the working model that the rest of the tutorial builds on.
The three building blocks
An Agentforce agent is made of three layers. Each layer narrows what the agent can do, and each layer is something you configure in Setup.
- Agent: the assistant as a whole. It has a role, a company-specific tone, and a set of topics. A customer service agent is one example.
- Topic: a category of work the agent can handle, such as "Case Management" or "Order Status". A topic holds a description, a scope, instructions, and a list of actions.
- Action: a single task the agent can run, such as "Get Case Status". An action wraps something that executes: a flow, an Apex method, or a prompt template.
The agent decides what to say. Actions do the actual work against your data. A language model cannot query your org on its own. It can only call the actions you made available to it.
What happens during a conversation
The agent works in a loop. Understanding the loop explains most of the design choices in later chapters.
- The user sends a message, for example "What is the status of case 00001026?"
- The agent's reasoning engine compares the message with the descriptions of all topics and picks the best match.
- Inside that topic, the engine reads the topic instructions and the list of actions. It decides whether an action is needed and which one.
- If an action needs inputs, the engine fills them from the conversation. If a required input is missing, it asks the user.
- The action runs. For a flow action, Salesforce starts the autolaunched flow with those input values.
- The flow returns its output values. The engine reads them and writes a reply in natural language.
The important point is step 3. The model chooses actions by reading text: topic descriptions, action names, instructions, and variable descriptions. It does not read your flow's logic. If those texts are vague, the agent picks the wrong action or passes bad inputs, even when the flow itself is correct.
Topics: scope and routing
A topic does two jobs.
Routing. The topic description and its scope tell the reasoning engine when this topic applies. A description like "Answer questions about the status of existing customer cases" is specific. A description like "Help with customer stuff" overlaps with every other topic and causes misrouting.
Boundaries. Instructions in a topic limit what the agent does once it is inside. They can say things like "Never share internal case notes" or "Always confirm the case number before updating a case". Actions that are not in the topic are not available there.
Keep topics distinct. When two topics could match the same request, the engine has to guess. Prefer a few well-separated topics over many overlapping ones.
Actions: what the agent can do
An action has these parts:
| Part | Purpose |
|---|---|
| Name and description | Tell the model what the action does and when it applies |
| Target | The thing that runs: a flow, an Apex method, a prompt template, and others |
| Inputs | Values the model must supply from the conversation |
| Outputs | Values the model reads back and uses in its reply |
| Instructions | Extra guidance on when to call the action and how to use each input and output |
Actions are the only way an agent touches your data. This makes them the main place where you control safety. An action that can only read a case status is far less risky than one that can update any field on any case.
Why a flow as the target
Flow is a common target because it runs inside the platform with your existing data model and security. An autolaunched flow, which is a flow with no screen and no user interaction, is the type that can be called by an agent. It takes input variables, does its work, and returns output variables. That fits the action shape exactly: inputs in, outputs out.
The next chapters compare Flow with Apex and prompt templates. For now, remember that the flow is only the target. The action is the wrapper that makes the flow visible to the agent.
How a flow variable becomes an action input or output
Flow variables are the link between the flow and the agent. A variable only appears as an action input if it is marked "Available for input". It only appears as an output if it is marked "Available for output". The description you add on the variable is what the model reads.
This flow metadata shows one input and one output:
<variables>
<name>caseNumber</name>
<dataType>String</dataType>
<isCollection>false</isCollection>
<isInput>true</isInput>
<isOutput>false</isOutput>
<description>The Case Number of the case to look up, for example 00001026.</description>
</variables>
<variables>
<name>caseStatus</name>
<dataType>String</dataType>
<isCollection>false</isCollection>
<isInput>false</isInput>
<isOutput>true</isOutput>
<description>The current Status of the case, or a short message if no case was found.</description>
</variables>The name caseNumber and its description tell the model what to collect. The example value "00001026" shows the expected format. The output description tells the model what it will get back, including the "no case was found" case, so the reply can handle it.
Registering the flow as an action
After the flow is active, you add it to a topic in Agent Builder. You choose the flow as the action target, then enter the action's name and instructions and set how each input is handled. This sketch shows the values:
Action name: Get Case Status
Flow: Get_Case_Status (autolaunched flow)
Action instructions: Use this action when the customer asks about the status of an existing case and has given a case number.
Input caseNumber: Collect from the user. Ask for it if it was not provided.
Output caseStatus: Tell the customer the status in plain language.Three things in this sketch matter:
- The action instructions say when to use the action, not how the flow works inside.
- The input setting says where the value comes from. Here the model collects it from the user and asks if it is missing.
- The output setting says how to use the result in the reply.
Later chapters cover each of these settings in detail.
Common mistakes at this level
- One large action that does everything. An action that looks up, updates, and closes cases gives the model too many ways to go wrong. Prefer single-purpose actions.
- Treating the flow name as documentation. The model sees the action name and descriptions you write. Technical flow names and empty descriptions give it little to work with.
- Overlapping topics. If two topics could each handle "check my case", routing becomes unreliable.
- Assuming the model sees flow logic. It sees only the inputs, outputs, and text you provide. If the flow behaves in an unexpected way, the agent cannot explain why.
- Returning raw errors. If a flow fails and returns nothing useful, the agent has no safe thing to tell the user. A later chapter shows how to return a clear message instead.
Where the rest of the tutorial goes
The next chapters follow the order in which you would build an action. You will see how action types compare, how an autolaunched flow works, how to scope an action, and how to define inputs and outputs. After that you will build the flow logic, handle errors, set the run context and permissions, register the action, test it, and plan its deployment.
Exercise
A customer asks the agent, "Can you close my case 00001026?" The agent has a topic whose only action is Get Case Status, built from a read-only flow. Explain what the agent can do and why.
Show answer
The agent can look up the status, but it cannot close the case. Actions are the only way an agent changes or reads Salesforce data, and the topic offers only Get Case Status, whose flow does not update records. The language model has no direct access to data, so it cannot do anything the available actions do not cover. To support closing cases, you would add a separate, single-purpose action (for example Close Case) with its own flow, inputs, and instructions, and decide whether it belongs in this topic.
Exercise
A flow has a text variable named tempValue that stores an intermediate calculation. It is not marked "Available for input" or "Available for output". Will the agent be able to see or set it, and which two pieces of text does the model rely on for variables that are exposed?
Show answer
No. Variables that are not marked for input or output stay internal to the flow, so the agent cannot see or set them. For exposed variables, the model relies on the variable name and the variable description, plus any input and output instructions you add when registering the action.