Sub topic 2
Actions: What an Agent Can Actually Do
This chapter assumes basic Salesforce objects, records, and Setup, plus a high-level understanding of Flow or Apex and large language models.
Actions and action types
An action is a configured operation that an Agentforce agent can run. An action might retrieve a record, update data, call a service, or generate text. Topics define the agent’s responsibilities. Actions give the agent concrete ways to fulfill those responsibilities.
Common action types include:
| Action type | Best fit |
|---|---|
| Flow | Declarative business logic, record updates, and multi-step processes |
| Apex | Custom logic, complex queries, or integrations |
| Prompt template | Controlled text generation using specified Salesforce data |
| Standard or connected action | Salesforce features or external services already exposed to the agent |
An action’s label, description, input variables, and output descriptions help the reasoning engine decide when to use it. These descriptions are part of the agent’s decision context, so vague descriptions can cause incorrect action selection.
public with sharing class CaseSubjectAction {
public class Request {
@InvocableVariable(
label='Case ID'
description='The Salesforce case ID to look up'
required=true
)
public String caseId;
}
public class Response {
@InvocableVariable(
label='Subject'
description='The subject of the case, or Not Found'
)
public String subject;
}
@InvocableMethod(
label='Get Case Subject'
description='Looks up a case subject by its Salesforce case ID'
)
public static List<Response> getSubject(List<Request> requests) {
Set<Id> caseIds = new Set<Id>();
for (Request request : requests) {
caseIds.add((Id) request.caseId);
}
Map<Id, Case> casesById = new Map<Id, Case>(
[SELECT Id, Subject FROM Case WHERE Id IN :caseIds]
);
List<Response> results = new List<Response>();
for (Request request : requests) {
Response response = new Response();
Id caseId = (Id) request.caseId;
response.subject = casesById.containsKey(caseId)
? casesById.get(caseId).Subject
: 'Not Found';
results.add(response);
}
return results;
}
}The reasoning loop
The agent first interprets the request, then selects a topic. Within that topic, it compares available actions and checks their descriptions and required inputs.
How action selection works
The agent considers:
- Whether the topic covers the request.
- Whether the action description matches the user’s intent.
- Whether the required inputs are present or can be requested.
- Whether topic instructions allow the operation.
- Whether the action result supplies enough information to answer.
For example, “Where is order 1007?” should match an order-support topic and a status lookup action. It should not select a refund action merely because both actions mention orders. Clear scopes and descriptions reduce that ambiguity.
Exercise
Why might an agent choose the wrong action even when the correct action is available?
Show answer
The topic scope, action description, or input descriptions may be too vague or may overlap with another action.