Sub topic 14
Evaluating multi-step and tool-using systems
This chapter assumes you have read the earlier chapters on success criteria, datasets, the evaluation harness, programmatic checks, and statistical rigor. It also assumes you have built an application that calls tools, such as a function-calling agent or a workflow of several model calls.
Why a single output score is not enough
A single-call application produces one output, and you score it. A multi-step system plans, calls tools, reads the results, and decides what to do next. It leaves behind a trace: the ordered record of model calls, tool calls, arguments, tool results, and errors.
Scoring only the final answer hides three kinds of problems:
- The agent reaches the right answer by luck or by an unsafe route, for example by calling a destructive tool it did not need.
- The agent fails, but you cannot tell whether planning, tool choice, argument construction, or answer synthesis broke.
- The agent succeeds, but it takes 14 steps where 3 would do. That costs money and latency, and it raises the chance of failure on other inputs.
Errors also compound. If each of five steps is 90% reliable and the steps are independent, the whole chain succeeds about 0.9^5 ≈ 59% of the time. Per-step quality that looks fine can still give poor end-to-end results.
Three levels of evaluation
Evaluate at three levels and keep their scores separate.
| Level | Question | Typical check |
|---|---|---|
| Outcome | Did the task get done? | Final answer match, judge score, or final system state |
| Trajectory | Was the path acceptable? | Required and forbidden tools, order, step budget |
| Step | Was each individual decision correct? | Tool choice, argument validity, handling of tool errors |
Start with the outcome. If you can only build one check, build that one. Add trajectory and step checks where the outcome check cannot see risk or where you need to localize failures.
Outcome checks: prefer state over text
For a tool-using system, the most reliable outcome check often looks at the world rather than the agent's words. If the task was "refund order A123," do not ask the model whether it refunded the order. Query the test database and check whether a refund record exists.
State-based checks have two advantages. They do not depend on how the agent phrases its answer. They also catch agents that claim success without acting. Run each case against a fresh sandbox, such as an in-memory database or mocked services, so that cases cannot contaminate each other.
Use a judge for the final text only when the answer is open-ended. In that case, reuse the judge calibration practices from the earlier chapters.
Trajectory checks
A trajectory check compares the trace against a small specification. Do not require one exact sequence of calls unless the task truly allows only one. Agents often have several valid paths, and an exact-match requirement turns every harmless variation into a failure. Specify constraints instead:
- Required tools: calls that must appear.
- Forbidden tools: calls that must never appear for this case.
- Order: only the ordering that matters, such as looking up an order before refunding it.
- Expected arguments: the key arguments of important calls.
- Step budget: a maximum number of steps.
def is_subsequence(needle, haystack):
it = iter(haystack)
return all(item in it for item in needle)
def check_trajectory(trace, spec):
"""Return a list of failure messages. An empty list means the trace passes."""
failures = []
calls = [step["tool"] for step in trace]
for tool in spec["required_tools"]:
if tool not in calls:
failures.append(f"missing required tool: {tool}")
for tool in spec["forbidden_tools"]:
if tool in calls:
failures.append(f"forbidden tool called: {tool}")
if not is_subsequence(spec["required_order"], calls):
failures.append(f"wrong order, expected {spec['required_order']} in {calls}")
for tool, expected in spec["expected_args"].items():
matches = [
step for step in trace
if step["tool"] == tool
and all(step["args"].get(k) == v for k, v in expected.items())
]
if not matches:
failures.append(f"no call to {tool} with args {expected}")
if len(trace) > spec["max_steps"]:
failures.append(f"too many steps: {len(trace)} > {spec['max_steps']}")
return failures
spec = {
"required_tools": ["get_order", "issue_refund"],
"forbidden_tools": ["delete_account"],
"required_order": ["get_order", "issue_refund"],
"expected_args": {"issue_refund": {"order_id": "A123"}},
"max_steps": 5,
}
good_trace = [
{"tool": "get_order", "args": {"order_id": "A123"}, "error": None},
{"tool": "issue_refund", "args": {"order_id": "A123", "amount": 20.0}, "error": None},
]
bad_trace = [
{"tool": "issue_refund", "args": {"order_id": "A999", "amount": 20.0}, "error": None},
{"tool": "delete_account", "args": {"user": "u1"}, "error": None},
]
print(check_trajectory(good_trace, spec)) # []
for message in check_trajectory(bad_trace, spec):
print(message)The second trace fails four checks: a missing get_order, a forbidden delete_account, the wrong order, and wrong refund arguments. Returning messages instead of a single boolean lets error analysis group failures by cause.
Step-level checks
Step checks look at one decision at a time. Three are worth building first:
- Argument validity. Validate each call's arguments against the tool's schema, using the deterministic checks from the earlier chapter. Invalid arguments are among the most common agent failures.
- Tool selection. For a labeled set of situations, check whether the agent picked the right tool. This is a classification problem, so use accuracy and a confusion table.
- Error recovery. Inject a failing tool, for example a timeout or an empty search result, and check whether the agent retries sensibly, switches strategy, or reports the problem. Agents that loop on the same failing call until the budget runs out are a common failure.
To score a step in isolation, replay a recorded prefix of a trace and ask the model for only the next action. This is cheaper and less noisy than rerunning the whole episode.
Make runs repeatable
Agents amplify nondeterminism, because an early different choice changes everything after it. Handle this in three ways:
- Mock or record tool responses so that differences between runs come from the model, not the world. Keep a few live-tool cases to catch integration drift.
- Run each case several times. Report both the average pass rate and the fraction of cases that passed on every run.
- Set time, cost, and step limits per run, and record runs that hit a limit as failures.
def consistent_pass_rate(runs_per_case):
"""Fraction of cases where every repeated run passed."""
return sum(all(runs) for runs in runs_per_case) / len(runs_per_case)
runs = [[True, True, True], [True, False, True]]
mean_rate = sum(sum(r) for r in runs) / sum(len(r) for r in runs)
print(round(mean_rate, 3)) # 0.833
print(consistent_pass_rate(runs)) # 0.5The gap between 0.833 and 0.5 is the information. A support agent that works 83% of the time per attempt but only half of the cases reliably is not ready for tasks where users expect the same result every time. Add the bootstrap intervals from the statistical rigor chapter, resampling over cases rather than over runs.
Common errors
- Scoring only the final text. The agent claims it refunded the order, and the judge agrees. Check state.
- Over-specified trajectories. Requiring one exact call sequence penalizes valid alternatives and makes tests brittle. Constrain only what matters.
- Shared state between cases. One case's leftover records change the next case's result. Reset the sandbox for every run.
- Single-run results. One pass over the dataset hides variance. Repeat runs and report consistency.
- Ignoring cost. Track step count, tokens, and latency alongside quality. A change that raises accuracy by one point and doubles cost is a trade-off to decide on, not a pure win.
- Blaming the wrong component. When an episode fails, read the trace before changing the prompt. The cause is often a tool returning poor data or a schema that is ambiguous to the model.
Putting it into your harness
Extend the harness record for each case to include the trace, the outcome result, a list of trajectory failure messages, step count, and cost. Your regression suite can then assert on each of these separately. For example, it can fail a change that keeps outcome accuracy flat but increases forbidden-tool calls.
Exercise
An agent's per-step reliability is 95% and a task needs 6 independent steps. Roughly what end-to-end success rate should you expect, and why is checking only the final answer a poor way to improve it?
Show answer
About 0.95^6 ≈ 0.735, or 74%. A final-answer score only tells you that 26% of runs fail. It does not show which step broke, so you cannot tell whether to fix tool selection, argument construction, or error handling. Trajectory and step checks localize the failure.
Exercise
Write the trajectory spec constraints you would use for the task "cancel the user's subscription" with tools lookupuser, cancelsubscription, and deleteaccount. State which are required, which are forbidden, and what ordering matters.
Show answer
Required: lookupuser and cancelsubscription. Forbidden: deleteaccount, since cancelling a subscription does not include deleting the account. Order: lookupuser before cancelsubscription. Also check that cancelsubscription receives the correct user id, and set a small step budget such as 4. Verify the outcome by checking that the subscription's state in the sandbox is cancelled.