Sub topic 8
Topics and the kinds of actions an agent can call
This chapter assumes you know how an agent is built from topics, instructions, and actions, and that you can create an agent from a spec with sf agent create. It covers how the agent chooses a topic, what kinds of actions a topic can hold, and the mistakes that cause wrong choices.
How a request reaches an action
A topic is a group of related work. It has a name, a description that says when the topic applies, a scope, instructions, and a list of actions. An action is one thing the agent can do, such as look up a record or run a Flow.
When a user sends an utterance, the agent works in two steps. It first picks the topic whose description best matches the request. Then, inside that topic, it follows the instructions and picks which actions to call, if any.
Both choices depend on text you write. The agent reads topic descriptions and action descriptions as natural language. It does not match keywords.
Kinds of actions
Actions differ in what runs behind them. The table lists the common kinds.
| Kind | What runs | Typical use |
|---|---|---|
| Apex | An invocable Apex method | Custom logic or queries that need code |
| Flow | An autolaunched Flow | Declarative logic your admins already maintain |
| Prompt template | A prompt template | Generating or summarizing text |
| Standard action | A built-in action from Salesforce | Common tasks such as answering from knowledge or summarizing a record |
| External service | An API exposed through an external service registration | Calling systems outside Salesforce |
The names and availability of standard actions depend on your org and release. Check the action list in your org before you rely on one in a spec.
What the agent sees
For an Apex action, the agent sees the labels and descriptions, not your code. In the CaseStatusAction class from earlier, the @InvocableMethod label and description, and the @InvocableVariable labels, are what tell the agent that this action takes a case number and returns a status. Vague text such as "Process request" gives the agent nothing to match against.
A topic's scope has the same role. State what the topic handles and what it does not. For a case status topic, say that it answers questions about the status of existing cases and does not create or close cases.
Common errors
- Overlapping topics. Two topics with similar descriptions make the choice unstable. Merge them or narrow each scope.
- Too many actions in one topic. The agent has more options to confuse. Keep each topic to the actions it needs.
- Missing permissions. An action can exist and still fail at run time if the agent's running user cannot access the Apex class, Flow, or objects behind it.
- Name mismatch in tests. A test case that expects
case_statusorGetCaseStatusfails if the topic or action name in your org differs. Copy the names from the org, not from memory. - Instructions that contradict scope. If the instructions tell the agent to do something the scope excludes, behavior becomes unpredictable.
Checking your choices
Use sf agent preview to send an utterance and see which topic and action the agent selects. If the wrong one is chosen, change the description text first, then preview again. Once the behavior is right, record it as a test case so a later edit cannot silently break it.
Exercise
A user asks "Where is my order?" and the agent answers with case status information. Which text do you review first, and why?
Show answer
Review the topic description and scope for the case status topic, and the descriptions of its actions. The agent chooses topics and actions from that text, so a description that is too broad can pull in unrelated requests. Narrow the scope to existing support cases, then preview the same utterance again.