Sub topic 14
Evaluating multi-step and tool-using systems
This chapter assumes you have a working harness, programmatic checks, and an LLM judge from earlier chapters. It also assumes you know how an agent loop calls tools.
Why a final-answer score is not enough
An agent plans, calls tools, reads results, and repeats. Scoring only the final answer hides most of what can go wrong. A run can reach the right answer by luck, by a wasteful path, or by a dangerous action. A run can also fail after a long chain of correct steps. Errors compound too: if each of five steps succeeds 90% of the time, the whole run succeeds only about 59% of the time.
Evaluate at three levels, and record all of them in the harness.
What to record
Your harness must save the full trace, not only the output. Each step needs the tool name, the arguments, the result, and any error. Without the trace, you cannot do error analysis later.
Checks at each level
- Step level: Did the agent pick the right tool? Are the arguments valid and in schema? These are deterministic checks.
- Trajectory level: Were required tools called? Were forbidden tools avoided? Did the run stay within a step or cost budget? Did it loop?
- Outcome level: Did the task actually succeed? Check the state of the world when you can. For example, query the database to see whether the row was created. Do not trust the agent's claim that it did it.
Prefer state checks over text checks. Use an LLM judge only for qualities you cannot code, such as whether the final message honestly reports a failure.
A trace checker
def check_trace(trace, required_tools, max_steps, forbidden_tools=()):
names = [step["tool"] for step in trace]
checks = {
"required_tools_called": all(t in names for t in required_tools),
"no_forbidden_tools": not any(t in names for t in forbidden_tools),
"within_step_budget": len(trace) <= max_steps,
"no_tool_errors": not any(step.get("error") for step in trace),
}
checks["passed"] = all(checks.values())
return checks
trace = [
{"tool": "search_orders", "args": {"customer": "c42"}, "result": "o9"},
{"tool": "refund", "args": {"order": "o9"}, "result": "ok"},
]
print(check_trace(
trace,
required_tools=["search_orders", "refund"],
max_steps=4,
forbidden_tools=["delete_account"],
))This prints a dictionary where every check is True. Keeping each check as a separate key shows you which rule failed, not only that something did.
Common errors
- Over-constraining the path. Agents often have several valid routes. Require the tools that every correct run must use, and do not demand one exact sequence.
- Ignoring variance. Agent runs differ more than single calls. Run each task several times and report the pass rate with a confidence interval.
- Unsafe side effects. Run tools against sandboxes or mocks. Mocked tools also make runs repeatable.
- Blaming the wrong part. A failure may come from planning, tool choice, bad arguments, or a faulty tool. Label the failing step so error analysis can group failures.
- Ignoring cost. Track steps, tokens, and latency. An agent that passes in 30 steps may be too expensive.
Exercise
An agent passes 90% of tasks on final-answer match. After inspecting traces, you find that it often calls a payment tool twice. Which level of evaluation would have caught this, and what check would you add?
Show answer
The trajectory level. Add a check that counts calls to the payment tool and fails the run if it is called more than once. Better still, add an outcome check on the sandbox state, such as the number of charges recorded, because a duplicate payment is visible there.