Sub topic 13
Testing in Builder and Refining Topics, Instructions, and Actions
This chapter assumes you know what topics, instructions, and actions are, and that you can open an agent in Agentforce Builder. You should also have the Order Status topic and the Get Order Status action from the earlier chapters.
Testing an agent is different from testing code. The same utterance can produce slightly different wording each time. What you check is whether the agent chose the right topic, ran the right action with the right inputs, and followed your instructions.
The test loop
You test in the conversation preview panel in Builder. You type a message as a customer would, and the agent responds. Builder also shows a trace of the agent's reasoning for each turn. The trace is the most useful part, because a good-looking reply can hide a wrong decision.
For each test message, read the trace and answer four questions:
- Which topic did the agent select?
- Did it run an action, and which one?
- What values did it pass as inputs, and what did the action return?
- Did the final reply follow the topic instructions?
Choose test cases on purpose
Write your cases down before you start, so you can rerun them after each change. For the Order Status topic, a useful set is:
| Test message | What it checks | Expected result |
|---|---|---|
| "Where is order 00001234?" | Normal path | Order Status topic, action runs, one-sentence status |
| "Where is my order?" | Missing input | Agent asks for the order number first |
| "Where is order 99999999?" | Action returns Not found | Agent says it could not find the order |
| "I want a refund for my order" | Out-of-scope request | Not handled by Order Status |
| "Show me the status of order 00005678" for another customer's order | Guardrail | No details shared |
Include phrasings you did not write yourself. Ask colleagues for how they would word the request.
Diagnose by symptom
Match each failure to the part that most likely caused it. Fix that part, not the others.
| Symptom in the trace | Likely cause | Fix |
|---|---|---|
| Wrong topic selected | Classification description is vague or overlaps another topic | Rewrite the description with clearer "use for" and "do not use for" statements |
| Right topic, but the agent answers from its own knowledge instead of running an action | Action not added to the topic, or instructions never say when to use it | Add the action and state the trigger in a numbered step |
| Action runs with a wrong or empty input | Input label or description is unclear | Describe what the input contains and where its value comes from |
| Action runs but the agent misreads the result | Output description is vague | Describe the possible output values, such as "Not found" |
| Agent skips a step or changes the order | Instructions are long or ambiguous | Split into short, ordered, testable steps |
| Agent does something outside the job | Scope is too wide | Narrow the scope and add a "cannot" statement |
Refine with a worked example
Suppose "Where is my order?" makes the agent guess an order number. The trace shows the action ran with an empty orderNumber. The instructions already contain step 1, "Ask the customer for their order number if they have not given one", but the action input description says only "Order".
Update the Apex annotation so the input says what it holds:
@InvocableVariable(label='Order Number' description='The order number the customer provided. Never guess or invent a value.' required=true)
public String orderNumber;Then rerun the full case list. The missing-input case should now trigger a question to the customer. Because you reran everything, you also confirm the normal path still works.
Watch for regressions
A fix for one case can break another. Tightening a classification description to exclude refunds, for example, can make the agent reject "cancel my order status check". Keep your case list and rerun it after every change.
Exercise
In the trace, the agent picked the Order Status topic and ran Get Order Status, but it passed the customer's name as the order number. Which part do you edit first, and why?
Show answer
Edit the action's input description (the label and description of Order Number). The topic was correct and the action was correct, so the failure is in how the agent understood what to put in the input. Clarify that the value is the order number and give an example format, then rerun your test cases.
Exercise
You rewrite a topic's classification description and the refund test message now goes to Order Status. What should you do?
Show answer
Add or sharpen the "Do not use for returns, refunds, or new orders" statement in the Order Status description, confirm the refund topic's description clearly claims refunds, and rerun the whole case list to check nothing else regressed.