Sub topic 2
How the Agent Chooses a Topic for a Request
This chapter assumes you know the basics of Salesforce Setup, you know what an agent and a large language model (LLM) are, and you can open Agentforce Builder and preview a conversation. It covers the routing step: how the agent picks a topic for each customer message. Later chapters cover how to write the descriptions and instructions themselves.
Why routing comes first
Every message a customer sends has to land somewhere. An Agentforce agent usually has several topics, and each topic holds its own instructions and actions. The agent can only follow a topic's instructions after it has chosen that topic. If the wrong topic is chosen, well-written instructions in the right topic never run.
When you debug an agent that "ignores my instructions," check the routing first. Many of these problems are routing problems. The agent followed the instructions of a different topic.
What the agent compares
The agent is driven by an LLM. For each customer message, the LLM receives the conversation so far and a list of the topics available to the agent. It then chooses which topic best fits the request.
The topic information it uses for this choice is mainly:
- The topic name.
- The classification description, which says what kinds of requests belong to the topic.
The scope and the instructions describe how the topic behaves once it is active. Treat them as guidance for the work after routing, not as the main routing signal. In practice, a clear scope can still help the model's overall picture of a topic, but you should not rely on it to fix a weak classification description. Verify this in your own org by testing, as described later in this chapter.
Routing is a judgment, not a rule match
Topic selection is not keyword matching. The agent does not search for the word "order" and jump to a topic with "order" in its name. It reads the request, infers what the customer wants, and decides which description best matches that intent.
This has three consequences.
- Paraphrases usually work. "Where's my package?" can match a topic described as "where an existing order is", even though the words differ.
- The result is probabilistic. The same borderline message can route differently across runs or after small wording changes. You reduce this by writing descriptions that leave little room for doubt, not by adding more words.
- You cannot force a match. Writing "always choose this topic when the customer says refund" in a description is not a reliable control. If a rule must always hold, it belongs in deterministic logic, which a later chapter covers.
Context from the conversation
The agent does not look at each message in isolation. It sees the conversation history, so short or vague messages can still route correctly.
Consider this exchange:
Customer: I ordered a blender last week.
Agent: I can help with that. What would you like to know?
Customer: When will it get here?The last message, "When will it get here?", has no noun the agent could match. With the history, the agent can tell the customer is asking about delivery timing for an existing order. A topic described as "when an existing order will arrive" fits.
History also works against you. Suppose a customer starts by asking about an order, then says "Actually, I want to send it back." The topic that fits the new intent is a returns topic. The agent should switch topics. If the order-status topic describes itself too broadly, for example "anything about an order", it may keep the conversation. Broad descriptions pull in follow-ups that belong elsewhere.
Topic switches mid-conversation
Routing is not a one-time choice at the start of the chat. The agent can change topics when the customer's intent changes. This is useful, because customers rarely stay on one subject. It also means each topic needs clear edges, since a topic can be entered from the middle of any conversation.
Design with this in mind:
- Do not assume the customer arrived at your topic from a greeting. They may arrive after several turns on another subject.
- Do not assume the agent will stay in your topic. If the customer changes subject, the agent can leave.
- If a topic needs information from earlier turns, such as an order number, write its instructions to ask for it when it is missing.
A worked example: three topics, six requests
Here are three illustrative topics with distinct descriptions:
Topic: Order Status
Classification description: Looks up the status and delivery date of an existing order.
Topic: Returns and Refunds
Classification description: Starts a return or refund for an order the customer says arrived damaged or incorrect.
Topic: Product Questions
Classification description: Answers questions about product features, sizes, materials and compatibility.Here is how an agent should route six customer messages:
| Customer message | Expected topic | Why |
|---|---|---|
| "Has my order shipped yet?" | Order Status | Asks about the state of an existing order. |
| "The mug I got is cracked." | Returns and Refunds | The order arrived damaged. The customer did not say "return". |
| "Does this jacket come in a large?" | Product Questions | Asks about sizes. |
| "Where is my refund?" | Ambiguous | The request is about an existing refund, and no topic covers refund status. |
| "Tell me a joke." | None | No topic fits. Fallback handling applies. |
| "I need help." | None, until clarified | There is not enough information to choose. |
The fourth row shows a gap that is easy to miss. A topic that starts refunds does not cover tracking a refund that already exists. The agent may route it to Returns and Refunds because that is the closest match, or to Order Status. Neither description says it handles this case. Gaps like this are a design problem. You fix them by adding coverage or by deciding that the request should go to a human, not by hoping the model guesses right.
What happens when no topic fits
When a request fits no topic, the agent needs somewhere to go. Depending on how your agent is set up, this can be a standard fallback topic or a general response that tells the customer what the agent can help with. Check which fallback behavior your agent has in Agentforce Builder.
The two failure modes differ in cost:
- Wrong topic chosen. The agent confidently handles the request with the wrong instructions or actions. This is the worse failure, because the customer gets an answer that sounds right.
- No topic chosen. The agent redirects or asks a question. This is more visible and usually safer.
When you are unsure which failure you are tuning against, prefer descriptions that are narrow and specific. A narrow description may let more requests fall through to the fallback. A broad one lets more requests land in the wrong topic.
What affects the choice, and what you control
| Factor | You control it? | Effect on routing |
|---|---|---|
| Topic name | Yes | Gives the model a first signal of the topic's purpose. Use a plain, specific name. |
| Classification description | Yes | The main statement of which requests belong. |
| Other topics' descriptions | Yes | Overlap with your topic causes competition between topics. |
| Number of topics | Yes | More topics means more competing choices, and more chance of overlap. |
| Customer's wording | No | Vague or multi-part messages are harder to route. |
| Conversation history | Partly | Earlier turns shape how a short follow-up is read. |
The number of topics deserves attention. Each topic you add is one more candidate for every request. Adding a topic can lower routing accuracy for existing ones, because the new description may overlap with them. After adding or editing any topic, retest requests for its neighbors, not just for the new topic.
Seeing which topic was chosen
You do not need to guess which topic the agent selected. Use the conversation preview in Agentforce Builder to send a test message, then look at the reasoning or trace details the preview offers for that turn. The names of these views can change between releases, so look for the section that shows the selected topic and the actions the agent planned.
A reliable routing check follows these steps:
- Write the message a customer would plausibly send, in their words and not yours.
- Send it in the preview with no prior history.
- Record the topic selected.
- Repeat the same message two or three times, because the choice can vary.
- Repeat with the message placed after a few turns on a different topic.
A message that routes correctly once is not proof. A message that routes correctly in every run, both at the start and after a context switch, is much stronger evidence.
Common routing symptoms
| What you see | Likely cause | First thing to try |
|---|---|---|
| Two topics alternate for the same request. | Their descriptions overlap. | Rewrite both around different customer intents. |
| A topic receives requests it should refuse. | The description is too broad. | State the specific intent, not the general subject. |
| A valid request lands in fallback. | No description covers it, or the wording is too narrow. | Check whether the request is in scope. If it is, widen the description slightly. |
| A short follow-up routes strangely. | The agent relied on earlier turns that point elsewhere. | Test the follow-up with the real preceding turns. Check the neighboring topics. |
| A new topic broke an old one. | The new description overlaps an existing one. | Retest the old topic's sheet and separate the two descriptions. |
Key points
- The agent chooses a topic by comparing the customer's request and the conversation so far with each topic's name and classification description.
- Routing happens before a topic's instructions apply, so a routing error cannot be fixed with better instructions.
- Selection is a judgment by an LLM, so test borderline requests more than once.
- The agent can change topics mid-conversation, so every topic should have clear edges.
- Narrow, intent-based descriptions fail more safely than broad ones.
Exercise
A customer first asks, "Where is my order?" and the agent correctly uses Order Status. The customer then writes, "It came broken, I want my money back." The agent stays in Order Status and keeps giving shipping details. Name the most likely cause, and say where you would make the fix.
Show answer
The most likely cause is a routing problem. The Order Status classification description is probably too broad (for example, "anything about orders"), or the Returns and Refunds description does not clearly cover damaged items and refund requests, so the agent keeps the earlier topic. Fix it in the classification descriptions of the two topics. Narrow Order Status to looking up the status and delivery date of an existing order, and make Returns and Refunds explicitly cover orders that arrived damaged or incorrect. Then retest the message in the preview after the same earlier turns. Adding instructions to Order Status would not help, because the problem occurs before those instructions apply.
Exercise
You add a fourth topic named "Order Problems" with the description "Helps customers with order problems." Existing topics are Order Status and Returns and Refunds. Describe what is likely to happen to routing and what you would do before publishing.
Show answer
The new description overlaps with both existing topics, because late deliveries, damaged items and wrong items could all be called "order problems". Requests that used to route cleanly may now alternate between topics, and the new topic may take requests from the older ones. Before publishing, rewrite the description around one distinct customer intent, or drop the topic if its requests are already covered. Then run each topic's test sheet again, including the similar-but-different requests for its neighbors, and repeat borderline messages several times to check that the routing is stable.