Sub topic 1
How an Agent Uses Actions
An Agentforce agent does not run your Flow or Apex code on its own initiative. It reads text, decides whether an action fits the request, builds the input values, and runs the action. It then reads what comes back and writes a reply. Each step depends on what you defined. This chapter describes that loop so the later chapters on inputs, outputs, and errors have a model to build on.
Prerequisites
This chapter assumes you:
- Can navigate Salesforce Setup and Agentforce Builder.
- Know what an agent, a topic, and an action are at a basic level.
- Have worked with Flow variables or Apex classes.
- Know that the agent uses a large language model (LLM) to decide what to do.
What an action is
An action is a unit of work the agent can ask the platform to perform. Examples include looking up an order, updating a case, or drafting an email. An action has three parts:
- A target, which is the Flow, Apex method, or prompt template that does the work.
- Inputs, which are the values the target needs.
- Outputs, which are the values the target returns.
The agent never sees your implementation. It sees a description of the action and of each input and output, plus any values you pass back at run time. For the agent, the metadata is the action. If the metadata is vague, the agent has nothing better to work from.
The reasoning loop
When a user sends a message, the agent's reasoning engine works through several steps. The exact internals are managed by Salesforce, but the observable flow looks like this:
- Choose a topic. The agent compares the message with the descriptions of the topics assigned to it and picks the best match.
- Read the topic's instructions and actions. Only the actions assigned to the selected topic are candidates.
- Decide whether to call an action. The LLM weighs the user's request against the action names and descriptions, the topic instructions, and the conversation so far.
- Fill the inputs. The agent takes values from the conversation, from context it already holds, or from the output of an earlier action. If a required value is missing, it asks the user.
- Run the action. The platform calls the Flow, Apex method, or prompt template with those values.
- Read the outputs. The result goes back to the agent as data.
- Respond or continue. The agent writes a reply, asks a follow-up question, or calls another action.
Two points follow from this loop:
- Steps 3, 4, and 7 are decisions made by a language model reading your text. They are not rule-based lookups. The same wording can produce slightly different behavior across conversations, so clarity matters more than cleverness.
- Steps 5 and 6 are deterministic. Your Flow or Apex code behaves as written. The risk sits at the boundary, where the agent turns words into input values and turns output values back into words.
What the agent reads
The agent works from the following text and data. Each item is covered in its own chapter.
| What you define | How the agent uses it |
|---|---|
| Action name, label, and description | Decides whether this action fits the request |
| Input label and description | Decides what value to supply and where to find it |
| Input data type and required flag | Shapes the value and decides whether to ask the user |
| Output label and description | Interprets the result and decides what to say |
| Output visibility settings | Decides what the agent can use and what the user sees |
| Topic instructions | Guides when and how to combine actions |
The agent does not read your Apex comments, your Flow element names, or your SOQL. A well-commented method with a vague @InvocableVariable description is still a vague action from the agent's point of view.
Action targets at a glance
An action can wrap one of three kinds of target:
- Flow. An autolaunched flow, with input and output variables exposed to the agent.
- Apex. An invocable method, with
@InvocableVariablefields on request and response classes. - Prompt template. A template that produces generated text from record data and other inputs.
The choice of target does not change the loop above. The agent sees the same kinds of metadata for each. The next chapter compares the targets in detail.
A small example
Here is the same lookup action described two ways. The first leaves the agent to guess. The second tells it what the value is, where it comes from, and what to do when it is missing.
Weak input description:
Label: Id
Description: The id
Stronger input description:
Label: Order Number
Description: The order number the customer provided, for example 00000101. Ask the customer if it was not given. Do not guess.Suppose a customer writes, "Can you check on my order?" with no number.
- With the weak description, the agent may have no idea what "the id" refers to. It might pass a record ID from context, invent a value, or call the action with an empty string.
- With the stronger description, the agent knows it needs an order number from the customer. It has an example of the format. It also has an explicit instruction to ask instead of guess, so the likely reply is "What is your order number?"
The Apex code is identical in both cases. Only the text the agent reads changed.
How the agent uses outputs
After the action runs, the agent receives the output values. It uses them in three ways:
- To answer the user. The agent turns the values into a natural-language reply. It can only report what the outputs contain.
- To decide the next step. An empty status or an error message may lead the agent to ask for a different value or to try another action.
- As inputs to a later action. A record ID returned by one action can be passed to the next one in the same conversation.
This matters for design. If an output field is named Result with the description "Output of the action," the agent has to infer what it means. If the field is called Order Status and states that it is empty when no order was found, the agent can word the reply accurately in both cases.
The agent also cannot use data you do not return. If a customer asks about the shipping date and the action returns only the status, the agent has no reliable way to answer. It may say it cannot help, or it may produce a guess. You decide which fields to return, so you decide which questions the agent can answer.
Common mistakes at this stage
- Writing for developers instead of the agent. Labels like
IdorFlag1make sense to the author but give the agent nothing to match against a user request. - Overlapping actions. Two actions with similar descriptions, such as "Get order" and "Look up order," force the agent to guess between them. Each action should have a distinct purpose.
- Relying on code behavior the agent cannot see. If your Apex returns an empty list when nothing matches, the agent only sees an empty result. Say in the description or output message what empty means.
- Assuming the agent will ask. An input only triggers a question to the user if the agent knows the value is needed and cannot find it. Describing it clearly and marking it required both help.
- Treating the agent as deterministic. Test with several phrasings of the same request. A description that works once may still fail on a differently worded message.
What the rest of the tutorial covers
The chapters that follow work through each point where your text shapes the loop. They cover choosing a target, writing names and descriptions, designing inputs and outputs, controlling visibility, implementing in Apex and Flow, handling errors, aligning with topic instructions, and testing. Keep the loop in mind as you read: the agent picks, fills, runs, reads, and replies, and every part of your definition feeds one of those steps.
Exercise
A user asks, "What's the status of my order?" without giving a number. The action has a required input labeled "Id" with the description "The id". Name two things the agent might do wrong, and describe a rewrite of the label and description that reduces the risk.
Show answer
The agent might guess or invent a value, or pass an unrelated ID from the conversation context, because "Id" does not say which ID is meant. It might also call the action with an empty value instead of asking the user. A better version uses the label "Order Number" and a description such as "The order number the customer provided, for example 00000101. Ask the customer if it was not given. Do not guess." This names the value, shows its format, and tells the agent to ask the user when the value is missing.
Exercise
In the seven-step loop, which steps are decided by the language model reading your text, and which are run deterministically by your Flow or Apex code?
Show answer
The model decides on the topic, whether to call an action, how to fill the inputs, and how to respond or continue. That covers steps 1 to 4 and step 7. Your Flow or Apex runs deterministically in step 5, and step 6 returns its outputs unchanged to the agent. The boundary between the two is where well-written labels, descriptions, and data types matter most.