How to test whether an AI agent really works, not just the model behind it (agent evals)

13 min read

How to test whether an AI agent really works, not just the model behind it (agent evals)

Judge an AI agent, an AI program that plans and uses tools to finish a task, by three things. Did it finish the task? How did it get there? What did it cost? Run the same tasks many times. One success means little. Score the outcome with a fixed rule. Read the failures by category. Log every run so the next eval, a repeatable test of how well the agent does, is cheaper.

New to these terms? Every word is explained in the series glossary.

A driving test, not a written exam

A model score is a written exam. It tests what the model, the AI language program inside the agent, knows. An agent eval is a driving test. It tests whether the system can get you home in traffic, in the rain, five times in a row.

A good model score tells you little about real tasks. An agent is a model plus tools (actions it can take, like looking up a record), plus memory, plus prompts (the text sent to the model), plus retries, plus all the glue in between. Any of those parts can fail while the model itself scores well. The eval has to cover the whole system.

Outcome, trajectory, and cost: three lenses

You need three lenses. Each one catches failures the others miss.

Outcome is the simplest lens. Did the agent finish the task correctly? A refund was issued for the right amount. A ticket was escalated. Outcome is what users care about. It is also the easiest to score.

Its weakness is clear. It says nothing about how the agent got there. An agent that refunds the right amount after calling the wrong tool five times and guessing twice still passes the outcome check.

Trajectory is the path. Which tools did the agent call? In what order? With what arguments? Did it check the policy before deciding? Or did it decide first and justify later? Trajectory catches agents that get the right answer for the wrong reason.

Trajectory is harder to score. A good path can look many ways. So check the steps that matter. The policy lookup happened. The amount was computed from the order record. No step was skipped.

Cost is the bill. Count tokens used (chunks of text the model reads and writes, which you pay for), tool calls made, and time taken. An agent that passes every task at ten times the cost of a simpler setup is not a working agent. It is a demo. Cost is the lens most teams skip. Measure it from the first eval. Do not wait for the invoice.

Think of the three as a triangle. Outcome, trajectory, and cost sit at the corners. Pull toward one corner and you usually give up something at another. The eval has to report all three. If it reports only one, it hides a trade-off.

Triangle with corners Outcome, Trajectory and Cost, each with what it checks, and the line 97 of 100 runs passed, 17 of 20 cases consistent

Outcome, trajectory and cost: each lens catches failures the others miss.

Pass rate is not the same as consistency

One success in five runs is not a working agent. It is a lucky run.

Pass rate is the share of cases the agent passes. If it passes 17 out of 20 cases, the pass rate is 85 percent. That number is useful. It is also easy to game by accident. Run the eval once, on a good day, and the pass rate looks great. Run it again and it falls apart.

Consistency is the share of cases the agent passes every time. Run each case five times. A case that passes five out of five is consistent. A case that passes three out of five is flaky. The difference matters more than the pass rate. Users do not experience averages. They experience one run at a time.

There is a related idea called pass at k, written pass@k. It asks whether the agent passes at least once in k tries. Pass@5 of 100 percent sounds impressive. It sounds less impressive when consistency is 60 percent. The agent can solve every task sometimes, and no task reliably. For a product, consistency is the number that matters.

A short note on terms helps here. In formal eval work, consistency across all k runs has its own name, pass^k. It is the chance that all k runs succeed. The toy eval below reports consistency in plain words: the share of cases that passed all five runs. That is the same idea as pass^5 for this eval. The formal pass@k metric also has an unbiased estimator, a statistics formula for estimating it fairly, in the research literature. My toy eval uses the simple share version: the share of cases that passed at least once in five runs. I say that plainly so no one mistakes a toy share for a formal benchmark estimate.

Build the eval set from real failures

An eval set built from imagined tasks tests your imagination. An eval set built from real failures tests your agent.

Start with your logs. Pull the last month of agent runs. Sort the failures into categories. Wrong tool called. Right tool with wrong arguments. Policy misread. Timeout. Hallucinated record, meaning the model invented one. Add a case for each category. Add the cases that passed but cost too much.

Twenty cases is a good starting size. Fewer than ten and the pass rate jumps around too much to mean anything. More than fifty and you will not maintain the set. Twenty cases, each with a fixed expected outcome and a fixed scoring rule, is enough to see patterns. It is also small enough to read by hand.

Freeze a version of the set. Give it a name and a date. If the set changes every run, you cannot compare last week with this week.

Every case needs three things. The input. The expected outcome. The scoring rule. The scoring rule should be mechanical. Use exact match, a number within tolerance (an allowed margin of error), or a set of required steps. If the scorer needs a language model to judge, say so. A model judge has its own error rate.

The worked example: a real 20-case eval

Here is a small toy eval. The agent is a refund assistant. It takes an order, looks up the refund policy with a tool, and decides whether to refund or escalate, meaning hand the case to a person.

The true policy is simple. Refund if the purchase was 30 days ago or less and the reason is damaged, wrong item, or defective. Otherwise escalate. A refund pays the full order amount.

The agent has two tools. One looks up the policy. One computes the refund amount. The policy lookup is flaky. On 30 percent of calls it returns a stale policy, an old saved copy that no longer matches the real one. That stale policy has a 14-day window left over from an old version. That is the one failure mode in this eval. It is deliberate.

The scorer is exact match on the outcome and the amount.

Here is the setup, stated plainly. No language model is involved. The agent is a small rule-based program in Python, following fixed if-then rules. Each of the 20 cases ran 5 times, with seeds 1 through 5 (starting numbers that make the random parts repeatable), in Python 3.12.

Here is the core of the agent.

python
import random

VALID_REASONS = {"damaged", "wrong item", "defective"}

def lookup_policy(rng):
    # Flaky tool: 30% of calls return a stale 14-day window.
    if rng.random() < 0.30:
        return {"window_days": 14, "stale": True}
    return {"window_days": 30, "stale": False}

def agent(case, rng):
    _, amount, days, reason, _, _ = case
    policy = lookup_policy(rng)
    if days <= policy["window_days"] and reason in VALID_REASONS:
        return "refund", round(amount, 2), policy["stale"]
    return "escalate", 0.0, policy["stale"]

def run(seed):
    rng = random.Random(seed)
    results = []
    for case in CASES:
        outcome, amount, stale = agent(case, rng)
        passed = (outcome == case[4] and amount == case[5])
        results.append((case[0], passed, stale))
    return results

The 20 cases cover the boundary of the policy, the inputs near its 30-day limit. Refunds sit at 0, 1, 5, 7, 10, 12, 14, 15, 25, 29, and 30 days. Escalations sit at 31, 40, 45, and 60 days. Other cases escalate for reasons outside the policy, like changed mind and late delivery.

The results, run by run:

RunPassedPass rate
Run 120/20100%
Run 220/20100%
Run 320/20100%
Run 418/2090%
Run 519/2095%

Overall pass rate: 97 out of 100, or 97 percent. Consistency: 17 out of 20 cases passed all five runs, or 85 percent. Pass@5: 20 out of 20, or 100 percent. Three cases passed some runs and failed others.

Per-case results. P is pass, F is fail, star is a stale policy lookup.

CaseInputExpectedRuns 1 to 5
15 days, damagedrefundP* P P* P* P
212 days, wrong itemrefundP P P P* P
345 days, damagedescalateP P* P P P
43 days, changed mindescalateP* P* P P* P
529 days, defectiverefundP P P F* P
631 days, defectiveescalateP P P* P P
77 days, wrong itemrefundP P P* P P*
860 days, wrong itemescalateP P P P P
91 day, damagedrefundP* P P* P P
1020 days, late deliveryescalateP* P P* P* P
1130 days, damagedrefundP P P P P
1231 days, damagedescalateP P* P P* P*
1310 days, defectiverefundP P P P* P
142 days, changed mindescalateP* P P P* P*
1525 days, wrong itemrefundP P P F* P
1640 days, defectiveescalateP P P* P P
1714 days, damagedrefundP* P P P P*
1815 days, damagedrefundP P P P F*
1928 days, late deliveryescalateP P P P P*
200 days, defectiverefundP* P* P P* P

Three failure examples from the run:

Case 5, run 4. A $250 order, defective, 29 days after purchase. Expected: refund $250.00. The policy lookup returned the stale 14-day window, so the agent escalated instead.

Case 15, run 4. A $150 order, wrong item, 25 days after purchase. Expected: refund $150.00. Same failure. Stale policy, escalated instead of refunded.

Case 18, run 5. A $22 order, damaged, 15 days after purchase. Expected: refund $22.00. Same failure again. Fifteen days is inside the true 30-day window. It is outside the stale 14-day window.

All three failures have the same shape. A stale policy lookup hit a case near the boundary, between 15 and 30 days. The tool failed 33 times out of 100 calls. The agent only failed 3 times. Most stale lookups landed on cases where the answer did not change. A case at 5 days passes under either window. A case at 45 days fails under either window.

That is the lesson of this eval. Read the failures by category, not just by score. The score says 97 percent. The categories say the policy cache is stale a third of the time. They also say the boundary cases are unprotected. The fix is not a better model. The fix is a fresher policy lookup, or a version check on the cached policy.

sequenceDiagram
    autonumber
    participant H as Eval harness
    participant A as Refund agent
    participant P as lookup_policy
    participant S as Scorer
    H->>A: Case 18, run 5: $22, damaged, 15 days
    A->>P: Look up the refund policy
    P-->>A: Stale copy: 14 day window
    Note over A,P: The true window is 30 days
    A->>A: 15 days is over 14, so escalate
    A-->>H: escalate, $0.00
    H->>S: Expected refund, $22.00
    S-->>H: Exact match fails: F
    Note over H,S: 33 of 100 lookups stale, only 3 runs failed

Diagram: How one failure happened: a stale 14-day policy hit a 15-day case and the agent escalated instead of refunding.

What to log on every run

Log enough that the next eval is cheaper than the last. For every run, record the eval set version, the date, the model name and version, the prompt version, the tool versions, and the seed. For every case, record the input, the expected and actual outcomes, the trajectory, the token count, and the tool calls. For every failure, record the category.

The point of the log is comparison. Next month, when the pass rate moves from 97 to 93 percent, you want to know what changed. Did the agent get worse? Or did the model version change under you? Without a log, you cannot tell.

Keep the logs in one place. Use a format you can read without a special tool. A table is enough.

Try this

Take five recent failures of any agent you use. Turn each one into an eval case. Write the input, the expected outcome, and a scoring rule you can check by hand. Run the five cases three times each. If any case fails even once, you have found a flaky case. That flaky case is your next fix.

The eval scorecard

A scorecard is one simple table for all your runs. Copy this table for your own evals. One row per run.

RunDateModelEval setCasesPassedPass rateConsistentTokensSeconds
1
2
3

Fill it in after every run. A filled scorecard beats a vague memory of how the agent used to do.

FAQs

How many cases does an eval need?

Twenty is a good start. Fewer than ten and the pass rate jumps around too much.

Should I use a language model to score the results?

Only if you must. A mechanical scorer is better, because it has no error rate of its own.

What is the difference between pass rate and pass@k?

Pass rate is the share of cases passed in one run. Pass@k is the share passed at least once in k runs. Pass@k measures capability. Consistency measures reliability. Report both, and label them.

How often should I run the eval?

Every time the model, the prompt, a tool, or the eval set changes.

Sources

  • Chen and colleagues, OpenAI, "Evaluating Large Language Models Trained on Code", 2021. Introduces the HumanEval set and the unbiased pass@k estimator. Code and data: https://www.github.com/openai/human-eval
  • Yao, Shinn, Razavi and Narasimhan, Sierra, "tau-bench: A Benchmark for Tool-Agent-User Interaction in Real-World Domains", 2024. Introduces pass^k, the chance that all k trials of the same task succeed, and reports that agents which pass a task once often fail to pass it every time. Code and data: https://github.com/sierra-research/tau-bench