AI Agent Evaluation: How to Test Agents Before Production

Nov 23, 2026 | AI Agents

AI Agent Evaluation: How to Test Agents Before Production

AI agent evaluation means running your agent against a fixed set of realistic tasks, scoring both the end result and the path it took, and repeating those runs every time the prompt, model or tools change. In practice that means a versioned test set of 50 to 200 cases drawn from real work. Code-based checks decide pass or fail wherever they can, a model-based judge handles only what code cannot score, and every case runs several times because agents do not behave the same way twice. If scores drop against the last known-good baseline, the change does not ship.

The rest of this piece covers what to measure, how to build the test set, how to wire agent evals into CI as regression tests, and where evaluation usually goes wrong.

Why testing AI agents is different from testing software or prompts

A normal unit test assumes the same input produces the same output. Agents break that assumption in three ways.

First, the model is stochastic. Even at temperature zero, providers do not guarantee identical outputs across calls, and a model update can shift behaviour without any change on your side.

Second, agents take multiple steps, and errors compound. Suppose each step in a ten-step task is right 95% of the time and the steps fail independently. The whole task then succeeds only about 60% of the time. A model that looks excellent on single questions can still produce an agent that fails one run in three.

Third, agents act on the world. They call APIs, write to databases and send emails. A wrong answer from a chatbot is embarrassing. A wrong tool call from an agent can refund the wrong customer.

Prompt testing, the kind people do in a playground, checks one input against one output. LLM agent reliability depends on the trajectory: which tools the agent picked, in what order and with what arguments, how it recovered when a tool returned an error, and whether it knew when to stop. Testing only the final answer misses agents that got the right result by luck, or by a path that would have caused damage in a slightly different situation.

Architecture matters too. A single agent with five tools is far easier to evaluate than a planner handing work to three sub-agents, because every hand-off is another place for context to get lost. If you are still choosing, our comparison of single-agent vs multi-agent systems covers the trade-off. Ease of testing is one of the strongest arguments for starting simple.

What to measure in agent evals

There are four dimensions worth scoring. Most teams start with the first and stop, which is how agents reach production with dangerous habits nobody tested for.

Outcome

Did the task end in the correct state? For an invoice-processing agent, that means the right supplier, amount, VAT treatment and cost code landed in the ledger. Check the state of the system after the run, not the agent’s account of what it did. Agents will report success on tasks they did not complete. The database is the source of truth.

Trajectory

Did the agent take an acceptable path? You rarely want to require one exact sequence of steps, because there are often several valid orders. Assert properties instead:

  • it calls the lookup before the write;
  • it never calls delete;
  • it finishes in under a set number of tool calls;
  • it asks for approval before any payment above a threshold.

These rules are cheap to check in code, and they catch the dangerous failures that outcome checks miss.

Cost and latency

Track tokens, tool calls and elapsed time per case. Some agents solve the task only after looping twelve times. That is a cost and latency problem, and the loop is often an early sign of a reasoning failure. A change that doubles tokens per task with no gain in accuracy is still a regression, even if every case passes.

Safety and robustness

Does the agent behave when inputs are hostile or malformed? Include cases with prompt injection hidden in documents or emails the agent reads, as well as missing fields, tool timeouts and contradictory instructions. Resistance to injection varies a lot between models. Published results such as Gemini 4 Carbon’s prompt-injection score show why you test this for each model rather than assume it carries over.

Each kind of check has a different cost and catches different failures:

Method What it catches Cost per run Use it for
Code-based assertions Wrong final state, forbidden tool calls, schema errors, step limits Negligible Anything you can express as a rule. This should be most of your checks
Trajectory rules Wrong tool order, skipped approval steps, unnecessary calls Negligible Workflows with known required or forbidden steps
LLM-as-judge Completeness, tone, whether a summary is faithful to its source One extra model call per case Free-text output that code cannot score, once checked against human labels
Human review Subtle domain errors, judge drift, edge cases nobody anticipated High, and slow Labelling the first test set, auditing samples, sign-off before release
Adversarial cases Prompt injection, data leakage, unsafe actions Low once written Any agent that reads untrusted input or has write access

Lean towards code. An LLM judge is useful, but it is another model with its own blind spots. If you grade a model with a model, you need to know how often the grader is wrong. Before trusting a judge, have a person label 30 to 50 cases and compare. If the judge disagrees with the person on a meaningful share of them, fix the rubric before you rely on its numbers.

Building the evaluation set

The evaluation set is the asset that lasts. Prompts and models will change several times a year, and a good set of labelled cases outlives all of them.

Start with real inputs. Pull historical examples of the work the agent will do, and anonymise them where they contain personal data. GDPR applies to test data as much as to production data. Choose the cases deliberately: the common ones, the awkward ones staff complain about, and the ones that went wrong in the past. Then add synthetic cases for events that are rare but matter, such as an invoice in a foreign currency, an email containing instructions aimed at the agent, or a tool that returns a server error halfway through a task.

Each case needs an expected outcome a machine can check. That might be the final record, the set of allowed tool calls, or the fields that must appear in the output. Writing these is the slow part, and it is where your domain experts are worth their time. A finance clerk can tell you in ten minutes which cases are genuinely tricky. An engineer working alone will guess.

Next, decide how tools behave during tests. Mocked tools are fast, free and predictable, but they are too clean. Real systems return partial data, rate-limit you and time out. A sandbox with seeded data is closer to reality but slower to run. A sensible pattern is mocked tools for the quick suite and a sandbox for the full one. Either way, freeze the data, so that a case means the same thing next month as it does today.

Keep a holdout. If you tune prompts against every case, you will overfit to your own test set, and the scores will look better than the agent really is. Set aside around a fifth of the cases and run them only before a release.

Running evals: once is not enough

Run each case several times; three to five is a reasonable default. Then report two numbers.

  • Succeeded at least once: this tells you what the agent is capable of.
  • Succeeded every time: this tells you how reliable it is, which is what production needs.

The gap between the two is the flakiness you will be supporting.

Look at where failures fall, too. Suppose two agents both pass 90% of runs. If the first agent’s failures are scattered randomly across cases, it is flaky. If the second agent always fails the same tenth of cases, it has a specific gap. The second is the easier problem: you can fix it, or route those cases to a person.

Set pass thresholds before you look at results, and set them by category. For example:

  • zero tolerance for forbidden actions;
  • a high bar for outcomes on common cases;
  • a looser bar for rare edge cases that already go to a human.

Pin model versions to dated identifiers where the provider offers them. Otherwise a vendor update can change your results overnight and you will spend a day blaming your own prompt.

Regression tests for agents in CI

Treat agent behaviour like code behaviour: any change that can affect it triggers a test run. That covers more than people expect:

  • prompt edits;
  • model version changes;
  • changes to tool schemas and tool descriptions, which the model reads as instructions;
  • framework upgrades;
  • updates to the search index behind retrieval.

Two tiers work well. A smoke suite of 20 to 30 cases with mocked tools runs on every pull request, costing minutes and a small amount of API spend. The full suite, with sandbox tools and repeated runs, runs nightly and before every release.

Compare each run against a stored baseline from the last release, and show the differences case by case. A flat overall score can hide five cases that got fixed and five that newly broke, and the newly broken ones may be the ones that matter. Store the full trace of every run, so that when a case fails someone can read exactly what the agent did instead of re-running it and hoping to reproduce the problem.

Keep the test harness separate from the agent framework. Whether you build on LangGraph, CrewAI or custom code, the harness should only need to know three things: the inputs, how to call the agent, and how to inspect the resulting state. That way you can swap frameworks or models and keep the same test set as your yardstick.

After launch: production is your best source of test cases

No pre-production test set covers everything. The aim is to make sure that what slips through is caught quickly and never slips through twice.

Start in shadow mode. The agent runs alongside the existing human process and records what it would have done, without acting, and you compare its decisions with what people actually did. Then roll out in stages, with approval gates on anything irreversible. In our own lab we use human-in-the-loop action tags so agents can be steered from a phone. Approval points like these double as natural checkpoints for logging and review.

Every production failure should become a new test case within days, labelled with the correct outcome. That is how the evaluation set grows towards the real distribution of your work. Pair it with clear rules for what the agent does when it is unsure: flag the item, route it to a person, or escalate. Our guide to exception handling in automated workflows covers that design.

Missing evaluation is also one of the quieter reasons AI pilots stall before production. Without a test set, nobody can say whether the agent is good enough, so the decision drifts. And if your agent falls under the EU AI Act’s high-risk categories, documented testing for accuracy and robustness is an obligation, not just good practice. The EU AI Act checklist for SMEs sets out the deadlines.

Build, buy or wait: a quick decision checklist for agent evals

Build your own harness if the agent touches money, customer records or regulated data. The same applies if success depends on checking specific system state that a generic tool cannot inspect, or if you have an engineer who will own the test set. A simple harness is a few hundred lines of code; the labelled cases are the real work.

Buy an evaluation or observability platform if you run several agents and need trace storage, dashboards and judge tooling without maintaining them yourself. You will still need to write your own cases. No platform knows what correct means for your invoices.

Wait if nobody can yet agree what a correct outcome looks like, if the underlying process changes weekly, or if you have no real examples to test against. Fix the process definition first. An evaluation set built on shifting ground measures nothing.

Where D3X Solutions LABS fits

We treat evaluation as part of the build, not a phase at the end. We start by agreeing with your domain experts what a correct outcome is, then turn your historical work into a labelled test set, write code checks for state and trajectory, and wire smoke and full suites into your release process. The first thing to check on any agent is whether its riskiest actions sit behind a rule or an approval gate. That usually tells you how much testing is still missing. If you have an agent heading for production, or one that is already there with no test set behind it, book a free 30-minute call and we will work through where your evaluation gaps are.

Frequently Asked Questions

What is AI agent evaluation?

AI agent evaluation is the practice of running an agent against a fixed set of realistic tasks and scoring the result. It checks both the final outcome and the steps the agent took, including tool choice, order, arguments and cost. Unlike testing a single prompt, it accounts for multi-step behaviour and the fact that agents do not produce the same output every time.

How many test cases do I need to evaluate an AI agent?

For a single workflow, 50 to 200 well-chosen cases is a practical starting range. Coverage matters more than volume: include common cases, known awkward ones, past failures and adversarial inputs. Grow the set by adding every production failure as a new labelled case.

Should I use an LLM as a judge for agent evals?

Use code-based checks wherever you can, and keep an LLM judge for free-text output that code cannot score, such as whether a summary is faithful to its source. Before trusting a judge, compare its scores with human labels on 30 to 50 cases. If they disagree often, fix the rubric before relying on the judge's numbers.

Why does my agent pass tests sometimes and fail other times?

Language models are stochastic, and small differences early in a multi-step task compound into different outcomes later. Run each case three to five times. Report both whether it succeeded at least once and whether it succeeded every time. Reliability across repeated runs is the number that matters for production.

When should regression tests for agents run?

Run them on any change that can alter behaviour: prompt edits, model version changes, tool schema or description changes, framework upgrades and updates to retrieval data. A small suite with mocked tools can run on every pull request. The full suite, with repeated runs and sandbox tools, should run nightly and before each release.

Do I need to document agent testing for the EU AI Act?

If your agent falls into a high-risk category under the EU AI Act, you need documented testing for accuracy, robustness and cybersecurity as part of your risk management. Even if it does not, a versioned test set with stored results is strong evidence that you deployed responsibly. It also makes audits and incident reviews much faster.

Want this working in your business?

D3X Solutions LABS builds AI agents and automation that pay back fast. Bring one process to a free 30-minute call and we will sketch what automating it would take.

Get in touch

Blog

What We Do

Product

Consumer and enterprise software, built with taste and shipped fast.

Infrastructure

AI agents, automation, and orchestration - production systems, not demos.

Advisory

Hands-on engineering and strategy for teams shipping AI into production.