Sub topic 6
Actions: what an agent can actually do
This chapter assumes you know basic Salesforce concepts (objects, records, Setup), have seen Flow or Apex at a high level, and know roughly what a large language model does. It also assumes you have read the chapter on topics.
What an action is
An action is a unit of work the agent can run. A topic describes an area of responsibility. An action is how the agent does something inside that area. Without actions, an agent can only produce text. With actions, it can read records, update them, send messages, or call other systems.
Each action is a configured wrapper around something that already runs on the platform. The agent does not run your Flow or Apex directly. It reads the action's description and inputs, decides whether the action fits, and then asks the platform to run it.
What an action is made of
An action has four parts the agent works with:
| Part | What it does |
|---|---|
| Name or label | Identifies the action to the agent and to you. |
| Description | Tells the agent what the action does and when it applies. |
| Inputs | The values the agent must supply, such as an order number. |
| Outputs | The values returned, which the agent uses to write its reply. |
The agent never sees your implementation. It sees only these four parts. If the description is vague or the inputs are poorly named, the agent has little to reason from.
Actions belong to topics
An action is attached to a topic. When the agent has chosen a topic, it considers only that topic's actions. This keeps the choice small. An "Order Support" topic that lists only "Get Order Status" cannot accidentally issue a refund, even if the customer asks for one.
An action backed by Apex
Any Apex method marked @InvocableMethod can be added to an agent as an action. The text you put in the annotations is the text the agent reads.
public with sharing class OrderStatusAction {
public class Request {
@InvocableVariable(label='Order Number' description='The order number the customer provided' required=true)
public String orderNumber;
}
public class Response {
@InvocableVariable(label='Status' description='Current status of the order, or Not Found')
public String status;
}
@InvocableMethod(label='Get Order Status' description='Looks up the current status of an order by its order number')
public static List<Response> getStatus(List<Request> requests) {
Set<String> orderNumbers = new Set<String>();
for (Request r : requests) {
orderNumbers.add(r.orderNumber);
}
Map<String, String> statusByNumber = new Map<String, String>();
for (Order o : [SELECT OrderNumber, Status FROM Order WHERE OrderNumber IN :orderNumbers]) {
statusByNumber.put(o.OrderNumber, o.Status);
}
List<Response> results = new List<Response>();
for (Request r : requests) {
Response res = new Response();
res.status = statusByNumber.containsKey(r.orderNumber) ? statusByNumber.get(r.orderNumber) : 'Not Found';
results.add(res);
}
return results;
}
}Three details matter here:
- The method label, "Get Order Status", and its description say what the action does.
- The
required=trueflag on the order number tells the agent it must have a value before it can run the action. If the customer has not given one, the agent should ask. - The response returns
Not Foundrather than failing. The agent can then tell the customer the order was not found, as the topic instructions require.
The method takes and returns lists because invocable methods can be called in bulk. The code builds one query for all requests instead of one per request.
Common mistakes
- Vague descriptions. "Gets data" gives the agent no basis to choose this action over another one.
- Hidden inputs. If an input has no description, the agent may guess what to pass.
- Too many actions in one topic. Overlapping actions make the choice harder. Split them across topics or merge them.
- Actions that exceed the topic's scope. If the scope says "does not process refunds", do not attach a refund action to that topic.
Exercise
A customer in the Order Support topic gives no order number. The "Get Order Status" action has an order number input marked required. What should the agent do, and why?
Show answer
It should ask the customer for the order number before running the action. The input is required, so the agent cannot run the action without a value, and the topic instructions also say to ask for the number when it is missing.
Exercise
Which parts of an action does the agent read when deciding whether to run it, and does it read the Apex code itself?
Show answer
It reads the label, the description, and the input and output descriptions. It does not read the Apex code.