Sub topic 3
Topics and Instructions: Defining What an Agent Handles
A topic is the unit that tells an Agentforce agent what kind of request it can handle and how. This chapter covers the parts of a topic, how to write instructions that the agent follows, and the errors that come up most often. It applies to both service agents and employee agents, because both are built from the same pieces.
Prerequisites
This chapter assumes you know:
- Basic Salesforce concepts: objects, records, and permission sets.
- What an agent action is at a high level. Actions are covered in the next chapter.
- That a large language model (LLM) reads text and produces text, and that it follows written guidance without executing code.
What a topic is
An agent does not hold one long prompt that covers every situation. Instead, you split its job into topics. Each topic is a category of work, such as "Order Status" or "My Open Cases". A topic bundles four things:
| Part | Purpose | Who reads it |
|---|---|---|
| Name | Label for you and for reports | Builders |
| Classification description | Short text that helps the agent decide whether the topic fits a request | The reasoning engine |
| Scope | One or two sentences stating what the topic does and does not cover | The reasoning engine |
| Instructions | Natural-language rules for handling the request | The reasoning engine |
| Actions | The tools the topic is allowed to call | The reasoning engine |
The reasoning engine is the LLM-driven component that reads the customer's or employee's message, picks a topic, and then follows that topic's instructions. A later chapter describes the loop in detail. For now, remember that the engine sees the classification descriptions of all topics first. It sees the full instructions and actions only after it has chosen one topic.
This two-stage design explains most of the advice below. The classification description has one job: routing. The instructions have another: behavior once routed.
The classification description
The classification description must separate this topic from every other topic. It should describe the user's intent in the user's terms, not your internal design.
Compare these two descriptions for an order status topic:
- Weak: "Handles orders."
- Better: "Customer asks where an order is or what state it is in."
The weak version overlaps with refunds, cancellations, and order changes. The better version describes one intent. If two topics have descriptions that could both match the same message, the engine may pick either one, and your results will vary between runs.
Scope
Scope is a short statement of the topic's boundary. It says what the topic does, and implicitly what it does not do. A good scope names the action or data the topic relies on. In the example below, the scope is "Look up the status of a single order using the Get Order Status action." That sentence also tells the engine that bulk lookups are out of bounds.
Writing instructions
Instructions are a list of plain-language rules. The engine treats them as guidance, not code. That has two consequences. First, they are followed well when they are specific and short. Second, they are not a security boundary, so you cannot rely on them alone to protect data.
Here is a complete topic for a service agent:
Topic: Order Status
Classification description: Customer asks where an order is or what state it is in.
Scope: Look up the status of a single order using the Get Order Status action.
Instructions:
- Ask for the order number if the customer has not given one.
- Call the Get Order Status action with that order number.
- Report only the status returned by the action.
- If the action returns 'Order not found', ask the customer to check the number once, then offer to connect them with a human agent.
- Do not discuss refunds or cancellations in this topic.Look at how each line works:
- "Ask for the order number if the customer has not given one." This handles a missing input before the action runs. Without it, the engine might guess a value or call the action with nothing.
- "Call the Get Order Status action with that order number." This names the action exactly as it appears in the topic. Use the real action name, not a paraphrase.
- "Report only the status returned by the action." This limits the agent to grounded data. It stops the agent from inventing a delivery date.
- The "Order not found" rule defines a failure path with a fixed number of retries ("once") and an exit (a human). Always give a failure path an exit, or the agent may loop.
- The last rule marks a boundary with a neighboring topic. Such negative rules help when two topics sit close together.
Instruction style that works
- Start each rule with a verb: ask, call, report, offer, do not.
- Put one condition and one outcome in each rule.
- Use the exact names of actions, fields, and values.
- State limits as numbers where you can ("once", "at most two questions").
- Describe the order of steps when order matters.
Instruction style that causes trouble
- Long paragraphs that mix several conditions.
- Vague words such as "appropriately" or "when needed".
- Contradictions between rules, or between instructions and the scope.
- Rules that repeat what another topic already covers.
The same structure for an employee agent
An employee agent uses the same parts. What changes is the audience and the assumptions in the instructions. The user is an internal person, and the data the actions return is governed by that person's own permissions.
Topic: My Open Cases
Classification description: An employee asks about support cases assigned to them or their team.
Scope: Summarize cases the employee already has permission to view.
Instructions:
- Use the Get Open Cases action to retrieve cases for the current user.
- Present each case with its number, subject, and status.
- If the employee asks about data they cannot access, say that you cannot show it and suggest contacting their administrator.Notice what the instructions do not do. They do not tell the agent to check permissions itself. The action runs with the employee's access, so records they cannot see are never returned. The last rule only covers what the agent should say when the result is empty or refused. Access control is the topic of a later chapter. The point here is that instructions shape the conversation, while permissions control the data.
Common errors and how to fix them
| Symptom | Likely cause | Fix |
|---|---|---|
| The agent picks the wrong topic | Overlapping classification descriptions | Rewrite each description around one distinct intent |
| The agent never reaches a topic | Description uses internal jargon that users never say | Rewrite in the words users type |
| The agent skips the action and answers from memory | Instructions do not name the action or require its result | Add "Call the X action" and "Report only what the action returns" |
| The agent asks the same question repeatedly | No retry limit or exit | Add a count and a human handoff |
| The agent drifts into neighboring work | Scope is broad, no negative rules | Narrow the scope and add "Do not discuss..." rules |
| Behavior differs between test runs | Ambiguous wording | Replace soft words with concrete conditions |
How many topics is right
Each extra topic adds another description the engine must compare against. Too many topics, or topics that overlap, make routing less reliable. Too few topics with too many instructions each make the instructions long and contradictory. A practical approach is to create one topic per distinct user intent and merge topics when their instructions are nearly identical. Start small, test, and split a topic only when its instructions grow hard to read.
Edge cases to plan for
- Out-of-scope requests. A message that matches no topic should get a safe, polite response. Decide whether the agent should redirect or hand off, and cover this in your agent-level setup and in topic instructions where relevant.
- Multi-intent messages. A user may ask about an order and a refund in one message. The engine handles one topic at a time, so write boundary rules that tell it to finish one intent and then address the other.
- Missing or malformed inputs. Tell the agent how to ask for the input, and how many times.
- Action failure. Define what the agent says when an action returns an error or an empty result, not only when it succeeds.
- Changing a topic later. After you edit instructions, retest the topics near it. A change in one description can alter routing for others.
Exercise
A service agent has two topics. Topic A has the classification description "Handles orders." Topic B has "Customer wants to cancel an order or request a refund." Customers asking "Where is my order?" are sometimes routed to Topic B. What is the most likely cause, and what would you change?
Show answer
Topic A's description is too vague, so it overlaps with Topic B and does not clearly claim the status-lookup intent. Rewrite Topic A as "Customer asks where an order is or what state it is in," and add "Do not discuss refunds or cancellations in this topic" to its instructions. Then retest both topics.
Exercise
An instruction says "Never show customers another customer's data." Why is this not enough to protect data, and what should you do in addition?
Show answer
Instructions guide the LLM but are not an enforced access rule, so an unusual request may still lead the agent to reveal data. Also limit what the actions can return, through the agent user's permissions and with sharing in Apex, so the data is never available to the agent in the first place.