Evaluating agents
Run each task several times in a sandbox; grade the outcome (the end state) and the trajectory (required and forbidden tool calls, steps, cost), and report pass^k: users need reliability, not one lucky run.
Analogy: A driving test: the car must end up parked in the right spot (outcome), the driver must not run a red light on the way (trajectory), and one clean drive doesn't prove a reliable driver.
How it works
- An agent's output is a sequence of actions that changes the world, not a string.
- Grade the outcome on the end state (DB rows, files, passing tests), not the agent's final message.
- Treat the trajectory as constraints: required and forbidden calls, step and cost budgets, never one exact path.
- Run trials in sandboxed, resettable environments with simulated users, so side effects stay safe.
- pass^k collapses fast: at 90% per independent trial, all 8 of 8 succeed only ~43% of the time.
Check yourself
Answer to mark it learned; your answers aren't scored.
Your agent eval asserts the exact tool sequence lookup_order → verify_identity → issue_refund. After a small prompt tweak, scores drop 30%, but manual review shows most "failures" reached the right end state through other valid paths. What should the eval check instead?
Go deeper
Full explanation
An agent's output isn't a string: it's a sequence of actions that changes the world, so grade it at two levels:
- Outcome — did the task succeed? Check the end state, not the agent's final message: DB rows, files, whether tests pass. τ-bench compares the final database to the expected one; SWE-bench runs the repo's tests on the agent's patch.
- Trajectory — how did it get there? Required calls (verify identity before a refund), forbidden ones (delete without confirmation), argument correctness, steps, turns, tokens and cost. Use these as constraints and budgets, not an exact path to match: valid paths vary.
Transcript graders — an LLM-as-a-judge reading the full trace — cover what code can't: policy adherence, tone, asking before acting.
The harness matters as much as the metric:
- Sandboxed, resettable environments (containers, mocked APIs, seeded DBs), so trials are isolated and side effects are safe.
- Simulated users for multi-turn tasks.
- Repeated trials, because agents are nondeterministic. pass@k = P(at least one of k succeeds): fine when a human or a test picks the best. pass^k = P(all k succeed): what a customer-facing agent needs. τ-bench showed reliability collapsing across trials; even independent runs at 90% each give only ~43% for 8 of 8.
Start with 20–50 tasks from real failures; grade the outcome first.
Code Outcome + trajectory checks, pass@k vs pass^k
from math import comb
def run_trial(task) -> dict:
env = Sandbox.from_snapshot(task.seed) # fresh, isolated state every trial
trace = agent.run(task.goal, tools=env.tools, user=task.user_sim)
calls = [step.tool for step in trace.steps if step.tool]
return {
# Outcome: read the world, not the agent's "Done, refund issued!"
"outcome": env.query(task.check_sql) == task.expected_rows,
# Trajectory: constraints, not an exact path (several paths are valid)
"required": all(t in calls for t in task.required_tools), # verify_identity
"forbidden": not any(t in calls for t in task.forbidden_tools), # delete_account
"steps": len(trace.steps),
"cost_usd": trace.cost_usd,
}
def pass_at_k(n: int, c: int, k: int) -> float: # P(at least one of k succeeds)
return 1 - comb(n - c, k) / comb(n, k)
def pass_hat_k(n: int, c: int, k: int) -> float: # P(all k succeed): reliability
return comb(c, k) / comb(n, k)
N, K = 8, 4 # run n trials per task, estimate for any k <= n
for task in tasks:
runs = [run_trial(task) for _ in range(N)]
c = sum(r["outcome"] and r["required"] and r["forbidden"] for r in runs)
avg_cost = sum(r["cost_usd"] for r in runs) / N
print(task.id, f"pass@{K}={pass_at_k(N, c, K):.2f}",
f"pass^{K}={pass_hat_k(N, c, K):.2f}", f"avg_cost=${avg_cost:.2f}")Real example
A refund agent passes 46 of 50 tasks in a single run: 92%, ready to ship? With 8 trials per task, pass^8 is 58% — over 40% of tasks fail at least once in eight attempts. Trajectory checks add a second finding: in 6% of successful runs the agent issued the refund before calling verify_identity. The end state was right; the path broke policy. The team moves that ordering into a hard code guard and gates releases on pass^4 ≥ 85% with zero forbidden-call violations.
Trade-offs +3 · −3
+ You gain
- End-state checks are objective and deterministic, even when the path varies.
- Trajectory metrics catch policy violations and waste that a correct outcome hides.
- pass^k exposes flakiness that single-run scores hide.
− You pay
- Realistic sandboxes, seeded data and user simulators are real engineering work.
- k trials multiply cost and time: 50 tasks × 8 trials = 400 agent runs.
- Simulated users and transcript judges add their own noise and bias.
Use it when
Any system where the model takes multi-step actions with tools: support agents, coding agents, computer use, workflows that write to databases or call external APIs.
Avoid it when
Single-call features (classification, extraction, one-shot answers): plain output evals are simpler. And don't grade an exact tool sequence when several valid paths exist.
Numbers to know 4
- τ-bench (Yao et al., 2024): gpt-4o function-calling agents solved <50% of tasks, and pass^8 was <25% in the retail domain.
- Independent trials at 90% per-trial success: pass^8 = 0.9^8 ≈ 43%, while pass@8 ≈ 100%.
- SWE-bench: 2,294 real GitHub issues from 12 Python repos, graded by the repo's tests; SWE-bench Verified is a 500-task human-validated subset.
- Rule of thumb: start with 20–50 tasks from real failures, 3–10 trials each.
Common pitfalls 4
- Trusting the agent's final message ("Done, refund issued!") instead of checking the end state.
- Asserting one exact tool sequence: it penalizes valid alternatives and breaks on every prompt change.
- Single-trial evals: a flaky agent looks fine until you repeat the run.
- Shared, non-reset environments: one trial's side effects leak into the next.
Interview questions 2
Answer out loud first, then reveal.
How would you evaluate a customer-support agent before launch?Show answer
I'd build 50–100 tasks from real tickets, each with a seeded sandbox — CRM, orders DB, mocked payments API — a simulated user persona and a goal. The primary grade is the end state: the right rows changed and nothing else did. On top I check the trajectory — identity verified before any account change, no forbidden calls, steps and cost within budget — plus an LLM transcript grader for policy and tone. I run every task 5–8 times and gate launch on pass^k and zero critical violations, not on a single-run average.
pass@k or pass^k: which do you report?Show answer
It depends on who consumes the output. pass@k fits when a human or a verifier picks the best of k attempts, like a coding assistant proposing patches that tests then filter. pass^k fits when every run reaches a customer: they experience each attempt, so all of them must work. For production agents I report pass^k, because τ-bench showed reliability collapsing across trials even when single-run success looked acceptable, and the gap between pass@1 and pass^k is my flakiness signal.