Sub topic 4
How a Request Is Matched to a Topic
This chapter assumes you know basic Salesforce concepts (objects, records, Setup), have a high-level familiarity with Flow or Apex, and have a general idea of what a large language model (LLM) does. It also assumes you have read the earlier chapters on what an agent is and what a topic contains. Here the focus is the step that happens first on every turn of a conversation: choosing the topic.
Why topic classification comes first
An agent can have many topics, and each topic has its own instructions and its own actions. If the agent had to weigh every action in every topic on every turn, the choice would be slow and error-prone. Topic classification narrows the problem. The agent first decides which area of responsibility the request belongs to. After that, it considers only the instructions and actions of that topic.
This means a mistake at this step carries forward. If the agent picks the wrong topic, the right action is not even available to it. Many "the agent chose the wrong action" reports are really "the agent chose the wrong topic" reports.
What the classifier reads
The reasoning engine sends a prompt to the LLM. For classification, that prompt contains the following:
- The user's latest message.
- Relevant conversation history, so a short reply such as "yes, that one" can be understood.
- The name and classification description of each topic the agent has.
The model then returns the topic that best fits the request. Note what is not in this prompt: the full instructions and the action list of each topic. Those matter after a topic is chosen. At the classification step, the topic name and classification description carry most of the weight.
Here is the topic from the plan, shown again with the fields the classifier uses marked in the text that follows.
Topic: Order Support
Classification description: Handles customer questions about the status of an existing order, such as where it is or when it will arrive.
Scope: Look up order status and explain it. Does not process returns, refunds, or changes to an order.
Instructions:
- Ask for the order number if the customer has not given one.
- Use the order status action to look up the order before answering.
- If the order cannot be found, say so and do not guess.
Actions: Get Order StatusFor classification, the name "Order Support" and the classification description are the primary signals. The scope, instructions, and actions come into play once the topic has been selected.
The flow of a classification decision
Writing a classification description
A classification description should say what requests belong in the topic, in words a customer might actually use. The best descriptions are short, specific, and written from the point of view of the request.
Compare these two descriptions for the same topic.
| Weak description | Stronger description |
|---|---|
| Order stuff | Handles customer questions about the status of an existing order, such as where it is or when it will arrive. |
| Helps with orders | Answers questions about tracking and delivery timing for orders that were already placed. |
The weak versions overlap with almost any commerce topic. A returns topic, a billing topic, and an order topic could all be described as "order stuff." The stronger versions name the situation (an existing order) and the typical question (where is it, when will it arrive). That gives the model something to separate this topic from its neighbors.
Keep topics from overlapping
Overlap is the most common cause of misrouting. Suppose you have these two topics:
- Order Support: questions about the status of an existing order.
- Returns: requests to send back an item and get money back.
Now a customer writes, "My order arrived damaged, what can I do?" Both topics have a plausible claim. The order has arrived, so status is not the question. The customer wants a remedy, so Returns is the better fit. The model can only reach that conclusion if the descriptions draw the boundary. Adding a clause such as "Does not cover damaged or unwanted items" to the Order Support description, and "Covers damaged, wrong, or unwanted items" to Returns, makes the boundary visible at classification time.
Use the topic's scope for the same purpose. The scope in the example states that the topic "does not process returns, refunds, or changes to an order." That sentence tells both the model and later readers where the edge is.
Ambiguous and off-topic requests
Not every message maps cleanly to one topic. There are three common cases.
- A clear match. The message fits one topic. The agent enters it.
- An ambiguous request. The message could fit two topics, or lacks detail, such as "I have a problem with my order." The agent may ask a clarifying question, or it may choose the topic that fits best. Better descriptions reduce how often this happens, but some ambiguity is normal and asking a question is often the right result.
- No match. The message is outside everything the agent covers, such as a request for a recipe sent to an order agent. The agent should decline or redirect, and should not stretch an unrelated topic to cover it.
Your agent's topic list includes the behavior for requests that fit nothing. Review it. If an out-of-scope request ends up in a loosely described topic, the agent will try to help with tools and instructions that were never meant for it.
Topics are re-evaluated each turn
Classification is not a one-time decision for the whole conversation. The agent considers the topic again as the conversation moves. A customer might ask about an order's status, receive the answer, and then say "Actually, I'd like to return it." The new message belongs to a different topic, and the agent should move to it.
This has two practical consequences.
- Follow-up messages depend on history. A reply like "the second one" is meaningless without the earlier turn. That is why conversation history is part of the classification prompt.
- Topic switches can lose context you assumed. If the Order Support topic found an order number, the Returns topic can use it only if that value was stored somewhere both can reach. Chapter material on variables and conversation context covers how to do that. For now, remember that a topic change is a boundary, and information does not cross it automatically unless you set that up.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| The agent enters the wrong topic for a clear request | Two classification descriptions overlap | Rewrite both so each names what the other excludes |
| Every request lands in one topic | That topic's description is too broad, such as "Handles customer questions" | Narrow it to specific request types |
| A valid request gets treated as off-topic | No description mentions that kind of request | Add the request type to the right topic's description |
| A follow-up reply goes to the wrong topic | The reply was short and depended on history the agent did not weigh | Test multi-turn conversations, not only single messages |
| The topic is right but the agent ignores its rules | The problem is in instructions, not classification | Check instructions and scope, covered in the next chapter |
Checking classification behavior
You can see which topic the agent chose without guessing. In the testing tools in Agent Builder, you send an utterance (a sample user message) and inspect the trace of the turn. The trace shows the topic that was selected before it shows any action. Use this routine:
- Write a set of sample messages for each topic, including a few phrased badly or with slang.
- Add a few messages that should match no topic.
- Run each message and record the topic the agent chose.
- For every miss, read the competing descriptions side by side and adjust the wording.
- Re-run the whole set, not only the failed message, because fixing one boundary can move another.
Step 5 matters. Changing one description affects how the model compares it to all the others, so a fix for one request can break a request that used to work.
Summary of the working model
- Classification runs first and picks one topic from the topic names and classification descriptions, using the latest message and the history.
- Only the chosen topic's instructions and actions are considered afterward, so a wrong topic hides the right action.
- Clear, specific descriptions with stated exclusions reduce overlap.
- Ambiguous and out-of-scope requests need deliberate handling.
- Topic is re-evaluated on each turn, and data does not move between topics on its own.
Exercise
A customer writes, "My package never showed up and I want my money back." The agent has two topics. Order Support has the classification description "Handles questions about orders." Returns has the description "Handles returns." The agent enters Order Support and tries to look up status. Explain why this likely happened and rewrite both descriptions to fix it.
Show answer
Both descriptions are vague, and "orders" is a broad word that overlaps with a missing-package complaint, so the model chose Order Support. The customer's goal is a refund, which belongs to a remedy topic. A fix is: Order Support: "Answers questions about the status and expected delivery date of an existing order. Does not handle refunds, returns, or complaints about lost or damaged items." Returns: "Handles requests to return an item, or to get a refund or replacement for an order that was damaged, lost, or never arrived." The rewrites name the situations and state the exclusions, so the boundary between the topics is visible at classification time.
Exercise
Why can a wrong topic choice make it impossible for the agent to pick the correct action, even if the action is well described?
Show answer
The agent considers only the actions of the selected topic. If the correct action belongs to a different topic, it is never among the candidates, so no action description can rescue the choice. The fix must happen at the topic level.