Write the eval harness (~15 min)
eval_harness.py is a help-desk agent with three tools: search_kb, get_ticket, and reset_password, which has a real side effect. run_agent works and returns a RunResult: the answer, a trace with one {"name", "input", "is_error"} entry per tool call in order, and the number of model_calls.
The team keeps changing the system prompt and wants to know, before each release, whether the agent still behaves. CASES holds a few test cases; grade and run_eval are stubs.
Part 1. grade(case, result) -> list[str] returns one message per failed check, or [] if the case passed. A case may have any of these keys (a missing key means no check):
| Key | The run passes when |
|---|---|
must_call | every listed tool appears in the trace with at least one call that did not error |
must_not_call | none of the listed tools appears in the trace at all, even as a failed call |
answer_includes | every string appears in the answer, ignoring case |
max_tool_calls | the trace has at most this many entries |
Each message names what failed, for example the tool name or the missing string.
Part 2. run_eval(cases, client=None) -> dict runs run_agent(case["prompt"], client=client) for every case and returns:
{"total": 4, "passed": 3, "pass_rate": 0.75,
"failures": {"vpn-self-help": ["answer is missing '5.2'"]}} # only failing cases, by id
A case whose run raises (RuntimeError from max_turns, an API error, anything) is a failed case, with a message that it crashed and why, and the remaining cases still run.
Be ready to discuss: what these checks can't tell you (a correct-looking answer with a wrong fact, a different but valid tool path), why you'd run each live case several times, when a model-graded check is worth its cost, and which case you'd add next. Also: unknown-ticket can't check that the agent tried the lookup (the lookup is supposed to fail, and must_call only counts successes). What key would you add?
Try it: python -m eval_harness (needs a key)
Check it: pytest tests/test_eval_harness.py