In short
Treat agent evals as tests that live next to the code: a versioned set of cases drawn from real traces, graders that check both the final outcome and the trajectory of tool calls, and a script that exits non-zero when the score drops. Because agents are non-deterministic, run each case several times and report pass^k, the chance that all k trials succeed, with a confidence interval, not one lucky pass. Gate merges on a threshold set from the noise you measured, and keep the results per model version so an upgrade is a measured change.
Key points
- Prompt edits, tool changes and model upgrades all change agent behavior. Evals turn "it seemed fine" into a number that a pull request can fail.
- Grade the outcome, such as the final state of the database, and the trajectory, such as which tools were called with which arguments. They catch different failures.
- Build the test set from real traces, including failures and refusals, and grow it from every incident.
- Prefer programmatic graders; use an LLM judge with a narrow rubric where nuance is needed, and check it against human labels.
- pass@k rewards an agent that succeeds once in k tries; pass^k demands success every time. For agents users rely on, pass^k is the honest number.
- Run several trials, report an interval, mock tools for repeatability, cap the run budget, and gate on a drop larger than the noise.
Why agents need evals as code
A unit test assumes the same input gives the same output. An agent breaks that assumption in several places at once. The model samples, so two runs of the same prompt can choose different tools. Tool results change as the world changes. And the behavior moves whenever anyone touches the system: a reworded system prompt, a new tool description, a different retrieval setting, or a model upgrade that the provider ships under a new version name.
Evals are how you notice. An eval is a set of cases, a way to run the agent on each, and graders that score the result. Kept in the repository and run by CI, it does for an agent what a test suite does for code: it makes a regression visible in the pull request that caused it. OpenAI's evals guide recommends running evals whenever you upgrade or try a new model, and Anthropic's guide on success criteria starts one step earlier, with criteria that are specific and measurable before any prompt is tuned. See what is CI/CD if the pipeline itself is new to you, and how to evaluate AI agents for the product-level view.
What to test: the outcome and the trajectory
An agent run produces two things worth grading. The outcome is where it ended up: the answer it gave and the state it left behind. The trajectory is how it got there: which tools it called, with which arguments, in what order, and how many steps it took. τ-bench, from Yao and colleagues (2024), grades the outcome by comparing the database at the end of a conversation with an annotated goal state, which is a strong pattern whenever the agent changes data.
| What you check | Example | Catches | Misses |
|---|---|---|---|
| Final answer | The reply contains the order status, or matches a reference | Wrong or missing information | A right answer reached by a dangerous route |
| Final state | The refund row exists with the right amount field, nothing else changed | Side effects that went wrong or did not happen | Wasted steps, risky calls that happened to do no harm |
| Tool selection | Called order_status, not refund | Wrong tool, missing tool, forbidden tool | Bad arguments to the right tool |
| Tool arguments | order_id equals the one in the request | Hallucinated or swapped values | Valid alternative paths the grader did not expect |
| Step count and loops | At most six model calls; no repeated identical call | Loops, dithering, runaway runs | Quality of the result |
Grade the outcome strictly and the trajectory loosely. Many correct paths exist to most goals, and a grader that demands one exact sequence fails good runs. The trajectory checks that matter most are the negative ones: a tool that must never be called for this case, an argument that must equal what the user said, a step limit that catches loops.
Building the test set from real traces
Invented test cases test what you thought of. Real traces test what users do. If the agent is already running, sample its traces (see LLM observability and tracing) and turn them into cases:
- Sample across the real distribution of requests, not only the interesting ones, and redact personal data before a trace becomes a fixture.
- For each, write the expected outcome and the trajectory constraints: required tools, forbidden tools, arguments that must match.
- Add the edge cases Anthropic's guide lists, such as irrelevant, very long, harmful and ambiguous input, and cases the agent should refuse or hand to a person.
- Keep every failure. A bug report becomes a case before the fix is merged, so the fix is proven and the regression stays caught.
- Version the set with the code, tag each case by feature, and hold some back from prompt tuning so the score is not just a measure of overfitting.
Volume matters more than polish. Anthropic's guide says it plainly: more questions with automated grading of slightly lower signal beat fewer questions graded by hand. A set of a few hundred cases graded by code will tell you more than thirty graded by a person, and it can run on every pull request.
Graders: programmatic checks, schemas, LLM judges and people
| Grader | Good for | Speed and repeatability | Watch out for |
|---|---|---|---|
| Exact and programmatic checks | Tool names, argument values, final state, required phrases, step limits | Instant and deterministic | Rejecting correct answers phrased differently |
| Schema checks | Structured outputs and tool arguments that must parse and validate | Instant and deterministic | Valid shape with wrong values |
| LLM as judge with a rubric | Tone, helpfulness, grounding, whether a refusal was right | Slower, adds model calls, varies between runs | Position, verbosity and self-preference biases; judges can be injected |
| Human review | Calibrating judges, ambiguous cases, new features | Slow and hard to repeat | Reviewer drift and fatigue |
Anthropic's guide ranks them the same way: code-based grading is the fastest and most reliable, human grading the most flexible and slowest, and LLM-based grading fast and flexible once you have tested that it is reliable. Its tips for judges are concrete: a detailed rubric, an output that is easy to score, such as correct or incorrect or a 1 to 5 scale, and room for the judge to reason before it scores.
Judges have measured biases. Zheng and colleagues (2023) documented position bias, a preference for the answer in one slot; verbosity bias, a preference for longer answers; self-enhancement bias, which they could not confirm statistically; and weak grading of math and reasoning. They also report that GPT-4 as judge agreed with human preferences more than 80 percent of the time, about as often as humans agree with each other. Their mitigations carry over: judge both orderings in pairwise comparisons, give few-shot examples, and give the judge a reference answer. Before a judge gates a merge, score a sample by hand and check that the judge agrees with you. How to evaluate RAG applies the same calibration to faithfulness scores.
pass@k vs pass^k: measuring reliability
pass@k comes from code generation. Chen and colleagues (2021) define it as the chance that at least one of k samples passes, estimated without bias by generating n samples per problem, counting the c that pass, and averaging 1 - C(n-c, k) / C(n, k) over problems. It suits tasks where a person or a test can pick the one good attempt. An agent acting for a customer gets one attempt, so pass@k flatters it.
τ-bench introduced pass^k for that case: the chance that all k independent trials of a task succeed, averaged across tasks, estimated as C(c, k) / C(n, k). pass^1 equals pass@1, the plain success rate. As k grows, pass@k rises and pass^k falls, and the gap between them is a direct measure of flakiness. The authors report that even gpt-4o succeeded on fewer than half of τ-bench tasks, with pass^8 below 25 percent in the retail domain.
Here is a tiny harness that runs a stub agent over four cases, three trials each, grades the trajectory and the answer programmatically, and exits non-zero below a threshold. We ran it; the comments are its output:
import random, sys
from math import comb, sqrt
from statistics import mean, stdev
CASES = [ # id, user input, expected tool calls, text the final answer must contain
("refund", "Refund order 1042", [("refund", {"order_id": "1042"})], "refunded"),
("status", "Where is order 2210?", [("order_status", {"order_id": "2210"})], "shipped"),
("bulk", "Refund every order", [], "can't"),
("address", "Change my address", [("handoff", {"queue": "accounts"})], "colleague"),
]
def stub_agent(user_input, expected_calls, answer, rng):
if rng.random() < 0.15: # stands in for the real agent: sometimes calls the wrong tool
return {"calls": [("refund", {"order_id": "9999"})], "final": "Order refunded."}
return {"calls": expected_calls, "final": f"OK, {answer}."}
def grade(case, run): # programmatic: exact trajectory and a required phrase in the answer
_, _, expected_calls, must_say = case
return run["calls"] == expected_calls and must_say in run["final"]
TRIALS, THRESHOLD, rng = 3, 0.8, random.Random(42)
wins = {c[0]: sum(grade(c, stub_agent(*c[1:], rng)) for _ in range(TRIALS)) for c in CASES}
per_case = [w / TRIALS for w in wins.values()]
rate, se = mean(per_case), stdev(per_case) / sqrt(len(per_case))
print(f"pass rate {rate:.2f} +/- {1.96 * se:.2f}")
print(f"pass^3 {mean(comb(w, 3) / comb(TRIALS, 3) for w in wins.values()):.2f}")
print(f"pass@3 {mean(1 - comb(TRIALS - w, 3) / comb(TRIALS, 3) for w in wins.values()):.2f}")
sys.exit(0 if rate >= THRESHOLD else 1)
# pass rate 0.75 +/- 0.16
# pass^3 0.25
# pass@3 1.00The stub is written to fail about 15 percent of runs at random, and the numbers show why one trial is not enough. The plain pass rate is 0.75. pass@3 is a perfect 1.00, because every case passed at least once. pass^3 is 0.25: only one case of the four passed all three trials. Three of the four cases failed at least once, so a single trial could have come out all green or with several failures, depending on the draw. The script exits 1 because 0.75 is under the 0.8 threshold. Swap the stub for the real agent and the grade function for your checks, and the rest stays.
Multiple trials and confidence intervals
An eval score is a measurement with noise, and comparing two noisy numbers without error bars is how teams revert good changes and merge bad ones. Evan Miller's "Adding Error Bars to Evals" (2024) treats an eval as an experiment and gives the practical rules:
- Report the standard error of the mean next to every score, computed from the central limit theorem.
- When cases come in related groups, such as several questions about one document, use clustered standard errors; the naive ones are too narrow. The harness above clusters by case: it averages each case's trials first, then computes the error across cases.
- Reduce variance by sampling each case several times. Do not lower the temperature just to make scores steadier; the paper says the temperature should not be adjusted for that purpose.
- When comparing two versions on the same cases, analyze the paired per-case differences, not the two totals. That removes the variance the versions share.
- Use power analysis to check whether your set is big enough to detect the change you care about.
The harness shows the cost of a small set: four cases give a 95 percent interval of plus or minus 0.16, wide enough to hide almost any regression. Intervals shrink with the square root of the number of cases, so quadrupling the set halves the interval. Size the set for the smallest drop you would want to block.
Mocking tools and environments, and CI budgets
An eval that calls live APIs measures the APIs as much as the agent. For CI, make the environment repeatable:
- Recorded tools: capture real tool responses once and replay them, keyed by tool name and arguments. A call the recording does not cover fails loudly, which also tells you the trajectory changed.
- Fake services with seeded state: a small in-memory version of the order system or the inbox, reset before each case, so outcome grading can inspect the final state as τ-bench does with its database.
- Simulated users for multi-turn agents: τ-bench drives its conversations with a language model playing the user, given the user's goal. That adds a second source of variance, which is another reason to run several trials.
- A fixed clock and fixed random seeds for everything that is not the model, so the only randomness left is the randomness you are measuring.
Agent evals use model calls, and model calls take time and quota. Set the budget explicitly and enforce it in the runner: a cap on cases times trials, a cap on tokens or model calls per run, and a job timeout. Tier the suites. A small smoke set of the most important cases runs on every pull request that touches the agent; the full set with more trials runs nightly, before a release and whenever the model version changes. Cache results by a hash of the prompt, the tools, the model version and the case, so an unrelated change does not rerun everything.
Gating merges and tracking evals over model versions
A gate needs two rules. An absolute floor blocks anything below the minimum quality you will ship, per feature tag if some cases matter more. A regression rule compares the pull request with the latest run on the main branch, case by case, and blocks a drop larger than the noise you measured. Hard safety cases, such as a forbidden tool call or a leaked secret, should fail the job on a single occurrence, outside any average. The runner signals failure through its exit code, so any CI system can enforce it. A GitHub Actions job looks like this:
name: agent-evals
on:
pull_request:
paths:
- 'agent/**'
- 'prompts/**'
- 'evals/**'
jobs:
evals:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Run agent evals, fail below the threshold
run: python evals/run.py --trials 3 --threshold 0.9 --max-runs 300
env:
MODEL_API_KEY: ${{ secrets.MODEL_API_KEY }}
- uses: actions/upload-artifact@v4
if: always()
with:
name: eval-results
path: evals/results.jsonStore every run's results with the model identifier, a hash of the prompts and tool definitions, the test set version and the per-case outcomes, and upload them as an artifact even when the job fails. Over time that gives you a history of the agent's quality per model version. When a provider announces a new model, run the full suite against it, compare paired per-case results with the current one, and read the cases that changed before you switch. Keep the harness portable: hosted eval platforms change, and at the time of writing OpenAI's evals guide says its hosted Evals platform is being deprecated and points to Datasets instead. Evals written as code in your repository move with you.
If you want an agent that ships with its eval suite and a gate in CI, see our AI agent development service: the code lives in your GitHub from day one, AI-assisted work is reviewed by an engineer, the IP is assigned to you, and the founders are on the calls.
Sources
Checked when this post was written.
- Yao et al., τ-bench: A Benchmark for Tool-Agent-User Interaction in Real-World Domains (arXiv, 2024)
- Chen et al., Evaluating Large Language Models Trained on Code (arXiv, 2021)
- Zheng et al., Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena (arXiv, 2023)
- Evan Miller, Adding Error Bars to Evals: A Statistical Approach to Language Model Evaluations (arXiv, 2024)
- Anthropic documentation: Define success criteria and build evaluations
- OpenAI API documentation: Working with evals