Sub topic 8
Writing Topic Instructions That Call the Action
This chapter assumes you can already build a prompt template in Prompt Builder and have added it to an agent as an action. It also assumes you know what an Agentforce topic is. Here you will write the topic text that makes the agent call that action at the right time, with the right input, and return the output without distorting it.
What topic text does
A topic groups a job the agent can do. Each topic has four parts that matter for this chapter:
- A classification description. The reasoning engine reads it to decide which topic fits the user's message.
- A scope. It states what the topic covers and what it does not.
- Instructions. They tell the agent how to behave once the topic is selected.
- Actions. These are the things the agent can run, such as a prompt template action.
The prompt template holds the text-generation logic. The topic holds the decision logic: when to call the template, what to ask the user first, and what to do with the result. Keep these two jobs apart. Rules about the shape of the summary belong in the template. Rules about when to run it belong in the topic.
A worked example
The topic below wraps a prompt template named Summarize Case. The template takes a Case record and produces a short hand-off summary.
Topic: Case Hand-off
Classification description: Handles requests to summarize a support case for a colleague or a customer call.
Scope: Summarizing existing cases only. Does not create or update cases.
Instruction 1: When the user asks for a case summary, ask for the case number if it was not given.
Instruction 2: Once the case is identified, use the Summarize Case action and return its output to the user without rewriting the facts.Each part has a purpose.
- The classification description names the user's intent in plain words ("summarize a support case"). It does not describe the implementation.
- The scope sets a boundary. "Does not create or update cases" stops the agent from drifting into work that this topic has no actions for.
- Instruction 1 handles missing input before the action runs.
- Instruction 2 names the action and says what to do with its output.
Classification description
The classification description is the main signal the agent uses to pick a topic. Treat it like a label for a bin that user messages fall into.
Good descriptions:
- Describe what the user wants, in the user's terms.
- Stay specific enough to separate this topic from its neighbors.
- Avoid words that also describe other topics in the same agent.
Suppose an agent has topics for Case Hand-off and Case Management. If both descriptions say "handles case requests", the agent has no basis to choose between them. Rewrite them so the difference is clear: one summarizes cases, the other creates and updates them.
Scope
The scope tells the agent where the topic ends. It matters most in two situations:
- A user asks for something close to the topic but outside it, such as "summarize this case and refund the customer".
- Two topics could plausibly handle the same message.
A scope that names exclusions ("Does not create or update cases") gives the agent a reason to decline or hand off instead of improvising.
Writing instructions that call the action
Name the action explicitly
Use the action's label as it appears in the topic. "Use the Summarize Case action" is clear. "Generate a summary" is not, because the agent may write the summary itself instead of calling the template.
If you rename an action later, update every instruction that mentions it. A stale name is a common reason an action stops being called.
State the trigger condition
Say when the action runs. Good triggers are tied to something the agent can check:
- "Once the case is identified, use the Summarize Case action."
- "If the user gives an email address, use the Find Contact action before summarizing."
Weak triggers depend on judgment: "when appropriate" or "if helpful". They produce inconsistent behavior.
Handle missing inputs before the call
The action needs inputs, and the agent may not have them yet. Write an instruction that asks the user for each required value, as Instruction 1 does for the case number. Without it, the agent may guess a value or call the action with empty input, and the template will either fail or generate text from nothing.
Control what happens to the output
A template's output is generated text. If the agent paraphrases it, facts can change. Decide which behavior you want and say so:
- To pass the text through: "Return its output to the user without rewriting the facts."
- To add framing: "Return the output, then ask whether the user wants anything else."
Do not ask the agent to both repeat the output exactly and reformat it. Those two instructions conflict.
Keep one instruction per behavior
Short instructions that each describe one behavior are easier to test than a long paragraph. When a result is wrong, you can tell which instruction failed.
Instructions versus template rules
Both the topic and the template can contain rules. Put each rule where it belongs.
| Concern | Put it in | Example |
|---|---|---|
| Length and format of generated text | Prompt template | "Use at most five sentences." |
| What data the text may use | Prompt template | "Use only the information above." |
| What not to promise in the text | Prompt template | "Do not promise refunds or dates." |
| When to call the action | Topic instructions | "Once the case is identified, use the Summarize Case action." |
| What to ask the user first | Topic instructions | "Ask for the case number if it was not given." |
| Whether to rewrite the output | Topic instructions | "Return the output without rewriting the facts." |
The template from the earlier chapters shows the split. Its rules limit the output, and it does not decide when it runs.
You are a service assistant. Write a short, factual summary of the case below for a customer call hand-off.
Case number: {!$Input:Case.CaseNumber}
Subject: {!$Input:Case.Subject}
Status: {!$Input:Case.Status}
Description: {!$Input:Case.Description}
Rules:
- Use at most five sentences.
- Use only the information above. If something is missing, say it is unknown.
- Do not promise refunds or dates.The same template can also run outside an agent. This Apex call uses the same API name, so the template stays the single source of truth for the summary text.
ConnectApi.EinsteinPromptTemplateGenerationsInput input =
new ConnectApi.EinsteinPromptTemplateGenerationsInput();
input.isPreview = false;
input.additionalConfig = new ConnectApi.EinsteinLlmAdditionalConfigInput();
input.additionalConfig.applicationName = 'PromptBuilderPreview';
ConnectApi.WrappedValue caseValue = new ConnectApi.WrappedValue();
caseValue.value = new Map<String, String>{ 'id' => caseId };
input.inputParams = new Map<String, ConnectApi.WrappedValue>{
'Input:Case' => caseValue
};
ConnectApi.EinsteinPromptTemplateGenerationsRepresentation result =
ConnectApi.EinsteinLlm.generateMessagesForPromptTemplate(
'Summarize_Case', input);
String summary = result.generations[0].text;Because the agent and the Apex code share one template, a fix to the template rules fixes both. A fix to topic instructions affects only the agent.
Common mistakes
- Vague trigger. The instruction says "summarize when needed". The agent sometimes writes its own summary. Name the action and the condition.
- Overlapping classification descriptions. Two topics claim the same requests, so the agent picks one unpredictably. Make the descriptions distinct and add exclusions to the scope.
- Missing-input handling. The agent calls the action with a guessed or empty case number. Add an instruction to ask first.
- Template rules repeated in instructions. Copying "at most five sentences" into the topic creates two places to maintain. Keep it in the template.
- Contradictory instructions. "Return the output exactly" and "make it friendlier" cannot both be followed. Pick one.
- Scope too wide. A topic that says "handles anything about cases" will collect requests that it has no action for.
Checking the result
After you write the instructions, test them in Agent Builder with messages that cover these situations:
- A message that gives the case number, such as "Summarize case 00001234".
- A message with no case number, such as "Summarize my case". The agent should ask.
- A message that goes outside scope, such as "Summarize case 00001234 and refund the customer". The agent should summarize and decline the refund, or hand off.
- A message that belongs to a different topic. The agent should not select Case Hand-off.
For each test, look at which topic was selected, whether the action ran, and what input it received. If the wrong topic was selected, fix the classification description or scope. If the right topic ran but the action did not, fix the instruction wording. If the action ran with the wrong input, review the input mapping, which the next chapter covers in detail.
Summary of the writing pattern
A reliable topic for a prompt template action follows this order:
- Write a classification description that names the user's intent.
- Write a scope that states what is in and out.
- Write an instruction that collects missing inputs.
- Write an instruction that names the action, states the trigger, and states how to handle the output.
- Test with at least four messages, covering the success path, missing input, out-of-scope requests, and another topic.
Exercise
A topic has the instruction "Summarize the case when appropriate." In testing, the agent sometimes writes its own summary and never calls the Summarize Case action. Name two problems with the instruction and rewrite it.
Show answer
The instruction does not name the action, and "when appropriate" gives no checkable trigger, so the agent may generate text itself. A better version is: "Once the case number is known, use the Summarize Case action and return its output to the user without rewriting the facts." Adding "If the case number was not given, ask for it first" also covers missing input.
Exercise
You want summaries to be at most three sentences. Should that rule go in the topic instructions or in the prompt template? Give one reason.
Show answer
Put it in the prompt template. The template controls the generated text, so the rule applies whenever the template runs, including from Flow or Apex. A copy in the topic would apply only to the agent and would need to be maintained in two places.