Sub topic 1
How an Agent Uses Actions
Prerequisites
Assume you know the basics of Salesforce Setup, Agentforce Builder, topics, and actions. You should also understand that a large language model (LLM) chooses what to do from the conversation and the action metadata.
How an Agent Uses Actions
An action is an operation an Agentforce agent can call, such as looking up an order or creating a case. The agent uses the action's name, labels, descriptions, input fields, and output fields to decide:
- Whether the action matches the user's request.
- Which input values it can extract from the conversation.
- Which values it must ask the user to provide.
- How to explain the result.
Choosing an Action Target
Choose the implementation that fits the work:
| Target | Use it when | Typical example |
|---|---|---|
| Flow | The process uses declarative Salesforce steps | Find an order and format its status |
| Apex | You need custom logic, bulk processing, or integrations | Call an external service |
| Prompt template | The main task is generating or transforming text | Summarize a case |
The target affects execution, but the agent still depends on clear metadata to select and use the action.
Names, Labels, and Descriptions the Agent Reads
Treat metadata as instructions for action selection. A vague description gives the agent little guidance. A specific description identifies the trigger, required context, and result.
public with sharing class GetOrderStatus {
public class Request {
@InvocableVariable(label='Order Number'
description='Order number supplied by the customer. Do not guess.'
required=true)
public String orderNumber;
}
public class Response {
@InvocableVariable(label='Order Status'
description='Current order status, or empty when no order matches.')
public String status;
}
@InvocableMethod(label='Get Order Status'
description='Use when a customer asks for the status of an order.')
public static List<Response> run(List<Request> requests) {
return new List<Response>();
}
}Designing Inputs the Agent Can Fill
Use an input for each value the action genuinely needs. Give it one clear meaning and a useful type. Mark it required when execution cannot continue without it. Tell the agent how to obtain it, and say “Do not guess” for identifiers, dates, or amounts.
Exercise
What should an action description say when it needs an order number?
Show answer
It should say that the action looks up an order by number, explain where the number comes from, and tell the agent to ask the user rather than guess.