Sub topic 9
Improving topics and instructions
This chapter assumes you can build a simple agent in Agentforce Builder and know what topics, actions, and instructions are. It also assumes you have already reviewed a conversation and found that the agent picked the wrong topic or followed the wrong steps. Here you will turn that diagnosis into a change you can test.
Where this fits in the loop
In the monitor-and-improve loop, you observe conversations, classify the failure, change the agent, test, and release. Topic and instruction changes are the most common fix, and they are the cheapest to make. They are also easy to get wrong, because one edit can shift how the agent routes many unrelated requests.
What each piece controls
Topic and instruction fields do different jobs. Mixing them up is the most common cause of fixes that do not work.
| Field | What it controls | Typical failure when it is weak |
|---|---|---|
| Topic name and classification description | Whether the agent routes a request into this topic | The agent picks a neighboring topic, or no topic |
| Topic scope | What the topic is allowed to handle | The topic answers requests it should refuse or hand off |
| Instructions | What the agent does once inside the topic | Steps are skipped, reordered, or invented |
| Action descriptions | When the agent chooses to call each action | An action is called too early, too late, or never |
If the reasoning trace shows the wrong topic was selected, editing instructions will not help. The instructions of the wrong topic never should have run. Fix routing first, then behavior.
Fixing topic routing
Topics compete with each other. The agent reads each topic's description and compares it with the customer's message. A vague description matches too much. Two overlapping descriptions split traffic unpredictably.
Use these rules when you rewrite a topic description:
- Name the specific things the topic handles, using the customer's likely words, such as "status", "tracking", and "delivery date".
- State what the topic does not handle, especially when a neighboring topic does.
- Keep one job per topic. If you need "and" several times in the description, consider splitting the topic.
- Check the neighbors. Every time you narrow one topic, confirm that another topic now covers the requests you removed.
Here is a typical case. A customer wrote, "I want to send back the shoes I bought last week." The trace shows the Order Status topic was chosen, and the agent offered a delivery date.
BEFORE (topic description)
Handle questions about orders.
AFTER (topic description)
Handle questions about the status, tracking, and delivery date of an existing order. Do not handle returns, refunds, or cancellations.
AFTER (instruction)
Ask for the order number if the customer has not given one. Use the order lookup action to get the status. If no order is found, say so and offer to connect the customer to a human agent.The "before" text is a one-line description. The word "orders" also fits a return, so the model had no reason to prefer Returns. The "after" text gives positive examples, a clear exclusion, and a fallback for the case where lookup fails.
Check that the Returns topic exists and describes return requests in the customer's words, such as "send back" and "return". An exclusion in one topic does not help if no other topic claims the request.
Fixing instructions
Instructions tell the agent how to behave inside a topic. The agent follows them as natural-language guidance, not as code, so wording matters.
Good instructions have these properties:
- One action per instruction. "Ask for the order number" and "look up the order" are separate lines. Combined lines are partly followed.
- Explicit conditions. Write "If the customer has not given an order number, ask for it" instead of "get the order number".
- Positive phrasing first. Say what to do. Add a prohibition only for a known failure, and name the thing to avoid.
- A fallback. Every path that can fail, such as no match or missing data, needs a stated next step. Without one, the agent improvises.
- Plain, consistent terms. If the topic says "order number", do not say "order ID" or "reference" elsewhere.
Common instruction problems you will see in reviews:
| Symptom in the conversation | Likely cause | Fix |
|---|---|---|
| Agent gives an answer without checking data | No instruction requires the lookup first | Add "Use the order lookup action before stating any status" |
| Agent asks for the same detail twice | Instruction does not say to skip if already provided | Add a condition: "if not already given" |
| Agent promises something it cannot do | Scope does not exclude it | Add an explicit exclusion and a handoff step |
| Agent ignores a rule | Rule is buried in a long paragraph, or contradicts another line | Shorten, reorder, and remove conflicts |
| Agent never escalates | No trigger defined for handoff | Add the conditions that require a human |
Make one change at a time
Change one thing per iteration when you can. If you rewrite the description, three instructions, and an action description together, a later test failure gives you no clue which edit caused it.
A practical order:
- Fix routing (topic description and scope).
- Fix instructions inside the correct topic.
- Re-read the reasoning trace on the original conversation to confirm the new path.
- Add the regression test.
Turn the failure into a test
Every fix should leave behind a test. Convert the failed conversation into a case with the utterance and the expected topic, action, and response behavior.
Test case: Returns request is not handled by the order topic
User utterance: I want to send back the shoes I bought last week.
Expected topic: Returns
Expected action: none until the order number is confirmed
Expected response: Asks for the order number or return reason, does not give a delivery date.Also add a test for the neighbor you narrowed. For this fix, add "Where is my order 1042?" and expect Order Status with the lookup action. Without that test, a routing fix can quietly break the topic you were trying to protect.
Measure whether the edit helped
After release, compare the same metrics you used to find the problem. The group-by summary below shows how escalations by topic point to the topic that needs review first. Run it on sessions from before and after the change.
from collections import Counter
# Hypothetical export of reviewed sessions. Field names are illustrative,
# not an Agentforce schema.
sessions = [
{"id": "s1", "topic": "Order Status", "resolved": True, "escalated": False},
{"id": "s2", "topic": "Returns", "resolved": False, "escalated": True},
{"id": "s3", "topic": "Returns", "resolved": False, "escalated": True},
{"id": "s4", "topic": "Order Status", "resolved": True, "escalated": False},
]
total = len(sessions)
resolution_rate = sum(s["resolved"] for s in sessions) / total
escalation_rate = sum(s["escalated"] for s in sessions) / total
escalations_by_topic = Counter(s["topic"] for s in sessions if s["escalated"])
print(f"Resolution rate: {resolution_rate:.0%}")
print(f"Escalation rate: {escalation_rate:.0%}")
print("Escalations by topic:", escalations_by_topic.most_common())In this sample, both escalations belong to Returns, so Returns is the topic to review first. After a fix you would expect the Returns resolution rate to rise and the Order Status rate to stay flat. If Order Status drops, your exclusion probably removed requests it should still handle.
Edge cases and gotchas
- Small samples mislead. Four sessions show a pattern, not a rate. Use enough sessions that a single odd conversation does not decide the result.
- Behavior varies between runs. The same utterance can produce slightly different wording. Test for the expected topic, action, and key behavior, not exact text.
- Overfitting to one example. A description that mentions "shoes" fixes one conversation and nothing else. Describe the category, not the instance.
- Overlap returns over time. Adding new topics later can recreate the confusion you fixed. Re-run the full test set after each new topic.
- Changes affect the whole agent. Topic descriptions are compared against each other, so editing one changes routing for the rest.
Exercise
A review shows that a customer asked to cancel an order, and the agent replied with a delivery date from the Order Status topic. The trace shows Order Status was selected and no Cancellations topic exists. Name two changes you would make and the two regression tests you would add.
Show answer
Changes: (1) narrow the Order Status description to status, tracking, and delivery date, and add an exclusion for returns, refunds, and cancellations; (2) either create a Cancellations topic with its own description and instructions, or add an instruction that offers a handoff to a human agent for cancellation requests. Tests: (1) a cancellation request such as "Please cancel my order" that expects the Cancellations topic, or the handoff behavior, and no delivery date; (2) a status request such as "Where is my order 1042?" that expects Order Status and the lookup action, to confirm the narrowing did not break the neighbor topic.
Exercise
Why is it a poor fix to add the rule "Never talk about returns" to the Order Status instructions when returns requests are being routed there?
Show answer
The problem is routing, so the instructions of the wrong topic should not be running at all. The rule treats the symptom, adds a prohibition that can conflict with other lines, and leaves the customer without a path. The better fix is to narrow the topic description, state the exclusion in scope, make sure a Returns topic claims the request, and add a fallback handoff.