Education › Evals & Harness › Stage 2: Evals in practice

Evaluating agents

Outcome vs trajectory, environments with state checks, benchmarks, flakiness and cost.

Intermediate ~45 min read Module 7 of 20

An agent does not produce one answer: it takes a sequence of actions in an environment, calling tools, reading results and deciding what to do next. That makes evaluation harder in three ways. There are many valid paths to the same goal, so comparing to one reference trajectory is too strict. Runs are long and non-deterministic, so one success proves little. And the agent changes things, so you need an environment you can reset. This lesson covers outcome-based grading with end-state checks, trajectory checks for safety and efficiency, reliability metrics such as pass^k, simulated users, and how to build environments that make all of this repeatable.

After this module you can
  • Grade agents by verifying the end state of the environment
  • Add trajectory checks for forbidden actions, efficiency and policy
  • Compute pass@k and pass^k and explain what each says about reliability
  • Design resettable environments with fake tools and simulated users
  • Measure cost, steps and latency alongside success

Grade outcomes, not paths

The most robust way to grade an agent is to check what is true at the end. Did the order get refunded in the database? Do the repository's tests pass? Does the file contain the right content? This end-state check is written as code against the environment, so it is objective and tolerant of the many different routes an agent might take. Benchmarks such as SWE-bench (do the hidden tests pass after the agent's patch?) and tau-bench (does the database match the expected state?) are built this way.

An end-state check for a support-agent task
python
def check_refund_task(db) -> dict:
    order = db.get_order("A-1042")
    return {
        "refunded": order["status"] == "refunded",
        "correct_amount": order["refund_amount"] == 59.00,
        "other_orders_untouched": db.count_changed(exclude=["A-1042"]) == 0,
    }


def passed(result: dict) -> bool:
    return all(result.values())

Note the third check. Agents can reach the goal while causing collateral damage, so good end-state checks also verify that nothing else changed.

Trajectory checks: how it got there

Outcomes are not everything. An agent that refunds the right order but first emails the customer's details to the wrong address has failed. Record the full trajectory (every message, tool call, argument and result) and add checks on it.

  • Forbidden actions: never called delete_account; never wrote outside the workspace.
  • Required actions: verified identity before changing an order; asked for confirmation before an irreversible step.
  • Policy compliance: did not offer a refund outside the policy window, even when the user pushed.
  • Efficiency: number of steps, tool calls and tokens compared with a reasonable budget.
  • Tool-call validity: share of calls with schema-valid arguments; repeated identical calls indicate loops.
Trajectory checks over a recorded run
python
def trajectory_checks(steps: list[dict]) -> dict:
    calls = [s for s in steps if s["type"] == "tool_call"]
    names = [c["name"] for c in calls]
    verified_before_write = (
        "verify_identity" in names
        and names.index("verify_identity") < names.index("refund_order")
    ) if "refund_order" in names else True
    return {
        "no_forbidden": "delete_account" not in names,
        "verified_first": verified_before_write,
        "within_budget": len(calls) <= 12,
        "no_loops": len(calls) - len({(c["name"], str(c["args"])) for c in calls}) <= 2,
    }

Reliability: pass@k versus pass^k

Run every task several times. pass@k asks whether at least one of k attempts succeeds; it suits settings where you can check and retry, such as generating code against tests. pass^k asks whether all k attempts succeed; it measures consistency, which is what a customer-facing agent needs. An agent that succeeds 70% of the time per attempt has a much lower chance of succeeding on every one of 8 conversations in a row.

Unbiased estimates from n trials with c successes
python
from math import comb


def pass_at_k(n: int, c: int, k: int) -> float:
    """P(at least one of k sampled attempts succeeds)."""
    if n - c < k:
        return 1.0
    return 1 - comb(n - c, k) / comb(n, k)


def pass_hat_k(n: int, c: int, k: int) -> float:
    """P(all k sampled attempts succeed)."""
    return comb(c, k) / comb(n, k)


print(pass_at_k(10, 7, 3), pass_hat_k(10, 7, 3))   # about 0.99 and 0.29

Environments and simulated users

Agent evals need an environment: the tools, the data behind them and a way to reset to a known state before each run. Use fake implementations backed by an in-memory or containerised database for business tools, a fresh container or temporary directory for coding and file tools, and recorded or stubbed responses for external APIs. Never point evals at production systems.

goalcallsread / writeasksrepliesrecorded callsfinal stateresetTask specgoal, start stateAgentunder testFake toolssame schemasTest DBreset per runSimulated userpersona + goalTrajectory checkforbidden, budgetEnd-state checknothing else changed
An agent eval runs the agent against fake tools over a resettable test database, with a simulated user, then grades the end state and the recorded trajectory.

Conversational agents also need a counterpart. A simulated user is a model prompted with a persona and a hidden goal ("you want a refund for order A-1042, you are impatient, you only reveal the order number when asked"). It makes multi-turn evals repeatable, but it is itself a model: check samples of simulated conversations to make sure the user behaves realistically and does not leak the answer or give up too early.

Tip

Give every task an ID, a starting state, the user goal, the end-state check and the trajectory checks. With those five things you can rerun any task at any time and compare agents fairly.

What to report

Report task success with confidence intervals, pass^k for reliability, and per-slice results (task type, difficulty). Next to them, report the costs of success: median and p90 steps, tokens and wall-clock time per task, and the rate of forbidden or unsafe actions, which should be zero. Finally, read failed trajectories and label the cause (wrong tool, bad arguments, misread result, gave up, looped, policy violation), because those labels tell you whether to change tools, prompts, context or the model.

Hands-on practice

A five-task agent benchmark

  1. Write five tasks for a support agent over a small SQLite database: refund, address change, order lookup, a refused request and a two-step task.
  2. For each, write the starting data, the user goal and an end-state check that also verifies nothing else changed.
  3. Add trajectory checks: identity verified before writes, no forbidden tools, a step budget.
  4. Run any agent (or a scripted stand-in) 5 times per task, resetting the database each time.
  5. Compute success rate, pass^3 and median steps per task.
  6. Label the cause of every failure and write down which change would fix the largest group.
Cheat sheet

Evaluating agents — at a glance

Main things to focus on

  • Grade the end state of the environment, not a reference path.
  • Check that nothing else changed (collateral damage).
  • Trajectory checks for forbidden actions, policy and budgets.
  • pass@k for retryable tasks, pass^k for consistency.
  • Resettable environments with fake tools; never production.
  • Report cost, steps and unsafe-action rate alongside success.

Grading

end-state check (code)Objective, path-tolerant
nothing else changedCollateral damage
hidden tests passCoding tasks
judge on final messageCommunication quality

Trajectory

forbidden tools never calledSafety
required order of stepsPolicy, verification
steps / tokens <= budgetEfficiency
repeated identical callsLoop detection

Reliability

pass@k = 1 - C(n-c,k)/C(n,k)At least one success
pass^k = C(c,k)/C(n,k)All k succeed
n trials per taskNeeded for both
CI on success rateUncertainty

Environment

reset to known state per runRepeatability
fake tools over test DBSafe and fast
simulated user + hidden goalMulti-turn
task: id, state, goal, checksTask record

Common pitfalls

  • Grading by exact match against one reference trajectory.
  • Running each task once and calling it reliable.
  • Evaluating against production systems.
  • Ignoring side effects outside the task's target.
  • Simulated users that leak the answer or give up instantly.
Quiz

Check your understanding

5 questions · 4 to pass · answers are explained as you go. Your best score is saved on this device only.

Progress and quiz scores are saved in this browser only. Back up or restore on the hub.

Was this lesson useful? Tell me what to improve →