Sub topic 13
Diagnosing a failing test
This chapter assumes you can write a test case with an utterance, an expected topic, expected actions, and an expected outcome. It also assumes you can run a suite and open the per-case results. Here you learn what to do when a case fails: decide whether the agent is wrong or the test is wrong, and change the right one.
Why a failure is not always a bug
A failing case means the agent's behavior did not match what the test expected. Either side can be wrong:
- The agent is wrong. A topic description is vague, an action is missing or poorly described, or an instruction gives bad guidance.
- The test is wrong. The expectation uses a name that does not exist, asks for something the agent was never meant to do, or describes the outcome too narrowly.
- The environment is wrong. The test data is missing, a permission blocks the action, or the agent version differs from the one you thought you were testing.
If you fix the wrong side, you either hide a real defect or break a working agent. The steps below keep you from doing that.
A diagnosis workflow
Work through the layers in the order the agent works: first topic selection, then action selection, then the response. A wrong topic usually causes wrong actions, and wrong actions usually cause a wrong response. Fix the earliest failure first.
Step 1: Read the result for the failing case
Open the results for the run and look at the failing case. Compare three things side by side:
- The expected value from your test.
- The actual value the agent produced.
- The result for each assertion (topic, actions, outcome).
A case can fail on one assertion and pass on the others. That tells you where to look. If the topic passes and the actions fail, do not touch the topic description.
You can get the same data from the CLI, which is useful when you diagnose from a terminal or a CI log:
sf agent test results --job-id <JOB_ID> --result-format human --target-org my-orgUse --result-format json when you want to save the output with a bug report or compare two runs.
Step 2: Check the topic
Topic failures come from four main causes.
The name in the test does not match. The expectedTopic value must match the developer name of the topic in your agent, not its display label. A test that expects Order Status when the topic's developer name is Order_Status fails every run, whatever the agent does. Check the name in the agent before you change any agent logic.
Two topics overlap. If the utterance fits two topic descriptions, the agent may choose either one. Compare the descriptions. If both mention "orders", the agent has no clear rule for choosing. Narrow each description so that it states what the topic covers and what it does not cover.
The utterance is ambiguous. "Can you check on it?" gives the agent nothing to route on. This is a test problem. Rewrite the utterance so that a person would also know where it belongs.
The request is out of scope but no topic catches it. For an off-topic request, the agent needs a topic or instruction that handles it. If the expected topic is an out-of-scope topic and the agent picked a real one, the real topic's description is probably too broad.
Step 3: Check the actions
If the topic is correct, look at the actions. Typical causes:
- Wrong action name. As with topics, the name must be the developer name of the action.
- The agent skipped the action. It answered from the conversation alone. Improve the action description so it says when to use it, or add an instruction to the topic such as "Always look up the order before answering a status question."
- The agent called an extra action. Decide whether the extra call is harmful. If it is acceptable, your test may be too strict. If it is not, tighten the instructions.
- The action ran but failed. A missing record, a missing input value, or a permission gap can stop an action. The agent may then recover with a different path. The test sees the wrong action list, but the real cause is data or access.
Check that the record your utterance refers to exists in the org you are testing. A test for order 1001 fails for reasons that have nothing to do with the agent if order 1001 was deleted from the sandbox.
Step 4: Check the outcome
The expected outcome is compared against what the agent actually said, so wording matters. Outcome failures fall into two groups.
The outcome is too narrow. An expectation such as "The agent says the order shipped on May 3" fails when the data changes or the agent words things differently. Describe the behavior, not the exact text: "The agent tells the customer the current status of the order."
The agent really answered badly. It gave the wrong status, made up a detail, or ignored a refusal rule. Here the test is right. Fix the instructions or the action, then rerun.
# Before: fails when data or wording changes
- utterance: Where is my order 1001?
expectedTopic: Order_Status
expectedActions:
- Get_Order_Status
expectedOutcome: The agent says order 1001 shipped on May 3 via UPS.
# After: describes the behavior the test is meant to protect
- utterance: Where is my order 1001?
expectedTopic: Order_Status
expectedActions:
- Get_Order_Status
expectedOutcome: The agent tells the customer the current status of the order.Step 5: Rerun before you conclude
Agent responses are not identical from run to run. Before and after any change, rerun the failing case. Use these rules:
| Observation | Likely meaning | What to do |
|---|---|---|
| Fails every run, same assertion | Deterministic problem | Follow the steps above |
| Passes sometimes, fails sometimes | Ambiguous utterance, overlapping topics, or loose instructions | Make the utterance or the agent's rules clearer |
| Fails only on the outcome, with a correct response | Expectation too narrow | Rewrite the outcome |
| Many cases fail at once after a change | A shared cause such as a renamed topic, a deactivated action, or a missing permission | Look for what all failing cases have in common |
A case that flips between pass and fail is a signal about the agent, not just noise. Treat it as a defect in routing or instructions.
Common errors to avoid
- Changing the agent and the test in the same step. You then cannot tell which change fixed it.
- Fixing one case while ignoring the others. After a change to a topic description or instruction, rerun the whole suite, because the same text affects other cases.
- Testing a stale agent version. Confirm that the version you changed is the one the test run targets.
- Editing the expectation to match a wrong answer. The test then records the bug as correct behavior.
A short checklist
- Read expected and actual values for each assertion.
- Find the earliest assertion that failed.
- Check names, data, and permissions before changing agent logic.
- Decide: test, agent, or environment.
- Change one thing.
- Rerun the case, then the full suite.
Exercise
A test case expects topic Order_Status and action Get_Order_Status. The results show the topic passed, but the actions list is empty. The agent's response says "Your order is on its way." What do you check first, and what would you change if the cause is in the agent?
Show answer
Check whether the order record from the utterance exists and whether the action's name matches the developer name in the test. Also confirm the action is active and the running user can use it. If the cause is in the agent, the agent skipped the action and answered without a lookup. Change the action description so it says when to use it, or add a topic instruction such as "Always look up the order before answering a status question." Then rerun the failing case and the full suite.
Exercise
A case passes on topic and actions, and fails on the outcome "The agent says the order shipped on May 3." The agent's actual reply states the correct, current status in different words. Is the fault in the test or the agent, and how do you fix it?
Show answer
The fault is in the test. The expected outcome is too specific, since it depends on one date and exact wording. Rewrite it to describe the behavior, for example "The agent tells the customer the current status of the order," and rerun.