Sub topic 8
Actions: What the Agent Can Do
This chapter assumes you know basic Salesforce concepts (objects, fields, records), have used Setup, and have a general idea of what a large language model does. Familiarity with Flow or Apex helps but is not required. Later chapters cover action types, inputs and outputs, and Apex in detail. Here you build the working model of what an action is and how the agent uses one.
What an action is
An action is a unit of work that an agent can run during a conversation. A topic decides which job the agent is doing. Instructions guide how it reasons about that job. Actions are how it reads data, changes data, or produces content.
A language model alone can only produce text. It cannot look up an order or update a case. An action connects the agent to something that can. When the agent decides a step needs data or a change, it calls an action, receives the result, and uses that result to write its reply.
An action belongs to a topic. The agent can only choose among the actions assigned to the topic it has selected. This is how the topic's scope is enforced in practice: an Order Status topic that has only a "Get Order Status" action cannot cancel an order, because it has no action that does that.
Where actions fit in the request flow
The agent handles each request in a loop. It picks a topic, reads that topic's instructions, and then decides whether an action is needed.
Three points follow from this flow:
- The agent chooses whether to call an action. Your instructions influence that choice but do not run it like a script.
- The agent fills in the action's inputs, usually from the conversation. If the customer has not given an order number, the agent must ask first.
- The action's outputs go back to the agent as data. The agent then decides what to say. It does not paste the output verbatim.
What an action contains
Every action has the same basic parts, no matter how it is built.
| Part | What it does | Why it matters |
|---|---|---|
| Name | Identifies the action in the topic | Appears in your instructions and in test traces |
| Description | Explains what the action does and when it applies | The agent reads it to decide whether to call the action |
| Inputs | Values the action needs to run | The agent must be able to fill each one |
| Outputs | Values the action returns | The agent uses them to compose its reply |
| Underlying implementation | A Flow, Apex method, prompt template, or standard action | Does the actual work |
The description and the input and output labels are not documentation for humans only. The agent reads them. A vague description such as "Gets data" gives the agent little to reason with. A specific one such as "Looks up the status of an order by its order number" tells it exactly when the action fits.
The Apex example from the plan shows this. Each input and output variable has a label and a description, and so does the method itself:
@InvocableMethod(label='Get Order Status' description='Looks up the status of an order by its order number')The label and description on this method become the action's name and description once you add it to a topic. You will build the full method in a later chapter.
Read actions and write actions
Actions fall into two practical groups, and the difference affects how carefully you design them.
- Read actions retrieve information and change nothing. Looking up an order status, finding a knowledge article, or fetching a customer's open cases are examples. Mistakes here are usually recoverable. The agent might call the action with the wrong input and give a wrong answer, but no data changes.
- Write actions create, update, or delete records, or trigger something outside Salesforce such as an email. Mistakes here have consequences. A wrong call can overwrite a field or send a message you cannot recall.
Treat write actions with more caution. Give them narrower descriptions, require the inputs that identify the record, and write instructions that say when the agent must confirm with the customer before proceeding. A later chapter on design practices covers this further.
How the agent decides to call an action
The agent is a language model reading text. It sees the topic instructions and the names and descriptions of the actions available in that topic. From that, it judges whether an action is needed for the current step.
This has several consequences you can design for.
- Descriptions drive selection. If two actions in a topic have overlapping descriptions, the agent may pick the wrong one. Make each description say what is unique about the action.
- Instructions can name actions. Writing "Use the Get Order Status action with that order number" ties a step to a specific action. This is more reliable than hoping the agent infers it.
- Missing inputs stall the call. If a required input has no value, the agent should ask the customer for it. Say so in your instructions, as in step 1 of the sample order instructions: "Ask the customer for their order number if they have not given one."
- Outputs need handling rules. If an action can return a value like "Not found", tell the agent what to do with it. Otherwise it improvises.
Here is how the sample instructions from this tutorial combine these ideas:
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.
5. Never share details about orders that belong to other customers.Step 2 names the action. Step 1 covers the missing input. Step 3 covers a known failure output. Step 5 sets a boundary that no action alone can guarantee, which is why the Apex example also runs its query with WITH USER_MODE, so field and object permissions apply to the data it returns.
The four kinds of action
Actions can be built four ways. The next chapters compare them, so this is only an orientation.
- Flow: a Salesforce Flow exposed as an action. Good when the logic is declarative and an admin maintains it.
- Apex: an invocable Apex method. Good when you need code, complex queries, or integration logic.
- Prompt template: a template that asks the model to generate content, such as a drafted reply or a summary, using grounded record data.
- Standard action: an action Salesforce provides out of the box for common jobs.
From the agent's side, they all look alike: a named action with a description, inputs, and outputs. The agent does not know or care which one you used.
Common errors
- Action never gets called. The description does not match how customers phrase the request, or the instructions never mention when to use it. Revise both.
- Wrong action gets called. Two descriptions overlap. Rewrite them so each states its distinct purpose, or move one action to a different topic.
- Agent invents an input. A required input was missing and the instructions did not say to ask. Add an explicit step to collect it.
- Agent ignores a failure. The action returned an error or "Not found" and no instruction covered it. Add a step for that output.
- Action exposes too much data. The implementation returns fields or records the customer should not see. Limit the outputs, and enforce permissions in the implementation, not only in the instructions.
- Too many actions in one topic. A long list makes selection harder. Keep the list to what that topic's job needs.
Putting it together
When you design a topic, work through actions in this order:
- List the tasks the topic's scope covers.
- For each task, decide whether the agent needs data, needs to change data, or needs generated content.
- Add one action per need, with a description that states what it does and when to use it.
- Label every input and output in plain language.
- Mention each action by name in the instructions, along with what to do for missing inputs and for failure outputs.
- Test with real phrasings and check the action calls.
Exercise
A topic called Order Status has two actions: "Get Order" with the description "Gets order information" and "Get Order Status" with the description "Looks up the status of an order by its order number". Customers report that the agent sometimes returns a long order summary when they only asked where their package is. Name the likely cause and two changes that would fix it.
Show answer
The two descriptions overlap, and "Get Order" is vague, so the agent sometimes selects it instead of the status action. Fixes: rewrite the "Get Order" description to state its distinct purpose (or remove the action from this topic if the topic's scope does not need it), and add an instruction that names "Get Order Status" as the action to use for status questions.
Exercise
Why should the instructions say what to do when an action returns "Not found", even though the action works correctly?
Show answer
The agent receives the output as data and decides what to say. Without a rule, it may guess, invent a status, or give an unhelpful reply. An explicit step tells it to say the order could not be found and ask the customer to check the number.