Evaluation
“An agent without evaluation is a guess with a good presentation.”
Objective
Understand why evaluating text is the wrong strategy, build a suite that checks properties of the trace, and prove that the suite detects regressions — a condition without which it is mere decoration.
10.1 The wrong question
“Did it work?” has no answer without an operational definition of “worked”. And the intuitive definition — comparing the answer with an expected answer — fails for three reasons:
-
The text changes with every model version. A suite that compares strings breaks with every update.
-
There is more than one correct answer. Two different phrasings can be equally right.
-
The answer can be right with the wrong process — and the process is what you want to guarantee.
The right strategy is to evaluate properties of the behavior, verified from the trace.
| Property | Check |
|---|---|
| Used the right tool | name in trace.tools_called() |
| Respected the policy | trace.blocked() >= 1 for malicious input |
| Stopped within budget | answer != "step limit" |
| Reached a final answer | did not give up before the limit |
| Produced a verifiable effect | file exists with the expected hash |
Table 10.1. Evaluable properties and how to check them.
These properties can be checked from the trace, and the trace is deterministic even when the model is not.
10.2 An evaluation suite
Listing 10.1. Structure of an evaluation case over the trace.
@dataclass
class Case:
name: str
script: list[dict] # calls the scripted model will make
checks: list
def run(self) -> tuple[bool, list[str]]:
trace = Trace()
answer = loop(self.script, trace)
failures = []
for check in self.checks:
fn, msg = check if isinstance(check, tuple) else (check, "check failed")
if not fn(trace, answer):
failures.append(msg)
return not failures, failures
The checks are functions over the trace:
Listing 10.2. Expressive checks over the trace.
def used_tool(name: str):
return (lambda t, a: name in t.tools_called(),
f"expected use of {name}")
def blocked_at_least(n: int):
return (lambda t, a: t.blocked() >= n,
f"expected >= {n} policy block(s)")
def no_side_effect(fragment: str):
return (lambda t, a: not any(fragment in e.get("command", "")
for e in t.events if e["kind"] == "tool"),
f"dangerous command '{fragment}' got executed")
Three cases cover the essentials: the happy path, the destructive attempt and the infinite loop.
Listing 10.3. Suite output.
[PASS] simple query
[PASS] destructive attempt is blocked
[PASS] infinite loop is cut off by the budget
3/3 cases passed
10.3 Prove that the suite detects failure
A suite that always passes is not a suite — it is an ornament. You need to prove that it fails when it should. This is done with a deliberately broken case, or with a check known to be impossible.
Listing 10.4. Output: the suite fails a case that should fail.
detected failure: True | reason: ['expected use of run_shell']
This test of the test is what separates a real suite from one that only prints green.
Why this matters so much. It is common to build a suite and discover, months later, that it has never failed — because the checks were loose, or because the scripted model never exercised the bad path. Having a case you expect to fail is the only objective proof that the failure mechanism works.
10.4 Evaluation with a real model
The suite above uses a scripted model, which is great for testing the harness. To evaluate the behavior of a real model, you need two extra things: cases with real inputs and a judge — human or model — for the cases where the answer is not binary.
The pattern that works:
-
A small set (10 to 30 cases) of representative tasks.
-
Deterministic checks where possible; human review where not.
-
Run the suite on every change of prompt, tool or model.
-
Treat a regression as a bug, with the same rigor as a unit test.
The set is small on purpose. Thirty well-chosen cases are worth more than three hundred loose ones, and a small set is the only one you will actually run on every change.
Common pitfall
Evaluating only happy cases. An agent that always succeeds on the happy path and fails catastrophically on malformed input is the worst kind of system: it looks ready. Half of the cases should be bad input — forbidden command, invalid argument, nonexistent tool, empty response.