Sub topic 8
Defining topics and writing instructions
This chapter assumes you have created an agent in Agentforce Builder and can open its topic list. It also assumes you know what an action is at a basic level. Chapters on standard actions and the custom Apex action follow this one, so here you only reference actions from instructions.
What a topic is
A topic is a category of work the agent can handle. It groups three things:
- A description that helps the agent decide whether a user's request belongs to this topic.
- A scope that states what the topic does and does not cover.
- A set of instructions and actions the agent uses once the topic is chosen.
Without topics, the agent has no boundaries. With them, each request is routed to a focused set of rules and tools. This is the main way you control what the agent will and will not do.
How the agent uses a topic
Each user message goes through two stages. In the first stage, the agent compares the message and the conversation so far against the description of every topic and picks the best match. At this point it does not read the instructions. In the second stage, it reads the instructions and actions of the selected topic and decides what to do. It may ask a question, call an action, or answer directly.
This split explains many common problems. A vague description causes the wrong topic to be chosen, and no amount of tuning instructions fixes that. Weak instructions cause the right topic to behave badly. When you debug, first work out which stage failed.
The fields of a topic
In Agentforce Builder, you add a topic from the topic list and fill in a form. Label names vary slightly between releases, so match them by meaning.
| Field | Purpose | Written for |
|---|---|---|
| Name | A short label you and other admins see | Humans |
| Classification description | Tells the agent when this topic applies | Topic selection |
| Scope | States what the topic handles and what it does not | Topic selection and behavior |
| Instructions | Rules for how to carry out the work | The agent, after selection |
| Actions | The tools available in this topic | The agent, after selection |
Name and description
Use a name that identifies the job, such as "Case Status Questions". Write the description as one or two sentences about the user's intent, not about your implementation. "Answer questions about the status of a customer's support cases" works. "Calls the Apex class to count cases" describes how, not when, and gives the selector nothing to match against.
Scope
Scope is a boundary statement. It names what the topic covers and, just as usefully, what it leaves out. If you have two topics that sound alike, such as case status and case creation, write the scope of each so that it excludes the other. Overlapping topics are the most common cause of wrong routing.
Instructions
Instructions are the rules the agent follows inside the topic. Each one is a separate item, written in plain language. Think of them as a short procedure plus guardrails.
A complete example
This is the topic definition from the course material. It pairs with the Apex action built in a later chapter.
Topic: Case Status Questions
Description: Answer questions about the status of a customer's support cases.
Instructions:
1. Ask for the account if the user has not named one.
2. Use the Get Open Case Count action to look up the number of open cases.
3. Report the number in one sentence. Do not guess when the action returns no result.
4. If the user asks about anything other than case status, say you cannot help with that.Look at what each line does:
- Handles missing input. The agent collects what the action needs before calling it.
- Names the action by its label. The name has to match the action's label on the topic, otherwise the agent may not connect the instruction to the tool.
- Controls output format and covers the failure case. "Do not guess" is a guardrail against invented numbers.
- Sets a boundary and gives the agent exact behavior for off-topic requests.
Writing instructions that work
These habits follow from how the agent reads instructions.
- One rule per instruction. A compound instruction is partly followed more often than it is fully followed. Split it.
- Say when, then what. "If the user has not named an account, ask for it" is clearer than "Make sure you have the account."
- Refer to actions by label. Use the exact action name shown in the builder.
- Specify the failure path. Say what to do when an action returns nothing, an error, or an unexpected value.
- Use positive and negative rules together. Tell the agent what to do and add a short "do not" only where you have seen it go wrong.
- State the format of the answer. For example, "Report the number in one sentence."
- Keep the list short. A topic with many instructions competes with itself. If you need a long list, the topic probably covers two jobs and should be split.
Common mistakes
| Symptom | Likely cause | Fix |
|---|---|---|
| Agent answers a case question with a generic reply | Description too vague, or another topic's description overlaps | Rewrite descriptions around user intent and tighten scope |
| Right topic, but the action is never called | Instruction does not name the action, or names it differently from its label | Use the exact label and say when to call it |
| Agent invents a value when the action fails | No failure-path instruction | Add an explicit "if no result, say so" rule |
| Agent helps with unrelated requests | Scope has no exclusion, and no off-topic instruction | Add an exclusion to scope and a refusal instruction |
| Behavior changes after you edit one topic | Edit changed how topics compete during selection | Retest the neighboring topics too |
Iterating
Treat a topic as something you tune against real prompts. A workable loop is:
- Write a description, scope, and short instruction list.
- Test a handful of requests that should match, and a few that should not.
- Open the reasoning details in the conversation preview to see which topic was chosen and which action ran. The next chapters cover testing in more depth.
- Change one thing, then retest the same prompts.
Changing one field at a time tells you which stage was at fault.
Checking your work
Before moving on, confirm that your topic satisfies the following:
- The description states user intent in one or two sentences.
- The scope names at least one thing the topic does not do.
- Every instruction is a single rule.
- Each action is referred to by its exact label.
- At least one instruction covers an action that returns nothing.
- At least one instruction covers an off-topic request.
Exercise
A user asks, "Can you open a new case for Acme?" Your agent has a topic named "Case Status Questions" whose instruction 4 says to refuse anything other than case status. The agent refuses, but you want it to create the case. Describe two changes you would make, and say which stage of the process each change affects.
Show answer
First, create a separate topic such as "Case Creation" with its own description (for example, "Help the user open a new support case"), scope, instructions, and a creation action. This affects topic selection, because the agent needs a description that matches the request. Second, adjust the scope of "Case Status Questions" so it explicitly excludes creating cases, which keeps the two descriptions from overlapping. This also affects selection. Instruction 4 in the status topic can stay as it is, because it governs behavior only after that topic has been chosen.
Exercise
Rewrite this instruction so it is easier for the agent to follow: "Look up the open cases and tell the user the count but make sure you have the account and don't make up numbers."
Show answer
Split it into single rules. 1. If the user has not named an account, ask for it. 2. Use the Get Open Case Count action to look up the number of open cases. 3. Report the number in one sentence. 4. If the action returns no result, say so. Do not guess a number.