By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
A chatbot's output is a message. An agent's output is a set of actions, of which the message is only the summary. If you only assert on the message, an agent that claims 'your refund has been processed' without calling the refund tool passes your test and fails your customer.
| Assertion | Catches | Example |
|---|---|---|
must_call set | The agent skipped a required step | get_order before create_return |
must_not_call set | Unauthorised or dangerous actions | issue_refund, delete_account |
| Argument equality | Acting on the wrong entity | create_return.order_id == 4521 |
| Call order | Acting before verifying | get_order must precede create_return |
| Step count | Loops and runaway cost | len(trace) <= 6 |
| Termination | The agent never stops | trace ends with a message, not a tool call |
| Final message vs trace | Claims that are not backed by actions | 'refund processed' requires a refund call |
def assert_trace(trace: list[dict], spec: dict) -> list[str]:
"""Return a list of problems; empty means the trace is acceptable."""
problems = []
called = [step["tool"] for step in trace]
for tool in spec.get("must_call", []):
if tool not in called:
problems.append(f"missing required tool: {tool}")
for tool in spec.get("must_not_call", []):
if tool in called:
problems.append(f"forbidden tool was called: {tool}")
if len(trace) > spec.get("max_steps", 10):
problems.append(f"trace too long: {len(trace)} steps")
for check in spec.get("args", []):
for step in trace:
if step["tool"] == check["tool"]:
actual = step.get("args", {}).get(check["arg"])
if actual != check["equals"]:
problems.append(
f"{check['tool']}.{check['arg']} was {actual!r}, expected {check['equals']!r}")
return problemsThe most common production agent bug is a loop: the agent calls a tool, dislikes the result, and tries again with the same arguments. Detect it by looking for repeated consecutive calls, and cap iterations at the executor level as a hard stop.
def has_loop(calls: list[str], repeat: int = 3) -> str | None:
"""Return the tool name if any tool appears `repeat` times in a row."""
run_tool, run_len = None, 0
for tool in calls:
if tool == run_tool:
run_len += 1
else:
run_tool, run_len = tool, 1
if run_len >= repeat:
return tool
return NoneAgent scenarios are conversations, and conversations need a user. Two approaches work: scripted turns (deterministic, fast, good for regression) and a simulated user (an LLM playing the customer, good for exploration). Use scripted turns in CI and simulated users when you are hunting for new failure modes.
Key takeaways
Assert on the tool-call trace, not only the final message.
Cover must_call, must_not_call, argument equality, order, step count and termination.
Detect loops by repeated consecutive calls and cap iterations in the executor.
Use scripted turns in CI; use a simulated user for exploratory testing.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.