---
title: "How to Test AI Agents: Evals That Catch Regressions"
description: "How to test AI agents when output is non-deterministic: the three layers worth testing, building a golden set from real traces, and where evals belong in CI."
date: "2026-11-23"
tags: ["AI","Agents","Reliability","Engineering Strategy"]
canonical: "https://www.kuaray.tech/en/articles/how-to-test-ai-agents"
source: "Kuaray Tech"
---
# Your Agent Passed. Passed What, Exactly?

Ask a team how to test AI agents they already have running and you usually get one of two answers. The first is a spreadsheet of prompts someone ran by hand in August. The second is a dashboard of scores between 0 and 1 that nobody can map to a decision — nobody knows what 0.82 means, whether 0.79 is a regression or noise, or which of last week's eleven merges moved it.

Both are the same failure: the test suite grades vibes instead of behaviour. So the question of *how to test AI agents* keeps getting answered with tooling when it's a specification problem. A conventional test suite works because the system is deterministic and the assertion is exact. An agent is neither, and the instinct that follows — "you can't really test this, you just have to watch it" — is how unattended systems end up with no acceptance bar at all.

At **Kuaray** we build agentic systems that run unsupervised against real production credentials, and the suite is usually the first artifact we write, before any agent logic. Not because we enjoy test infrastructure, but because an agent without an independent checker is just a very articulate intern with database access.

## How to Test AI Agents: Separate What's Deterministic From What Isn't

The single most useful move is to stop treating the agent as one testable unit. Most of an agentic system is ordinary software and should be tested with ordinary tests — fast, exact, in CI on every commit.

What's deterministic, and therefore cheap to assert:

- **Tool contracts.** Every tool has a schema in and a schema out. Contract tests against the real API (or a recorded fixture) catch the drift that makes an agent improvise over a renamed field.
- **Guardrail enforcement.** If a filesystem tool must refuse paths outside an allowlist, that's a unit test with a hostile input, not an eval. Same for budget ceilings, idempotency keys and permission scoping.
- **State machine transitions.** Checkpointing, resume-after-interrupt, retry policy, circuit breaker trip — all deterministic given a fixed input, all testable without a model in the loop.
- **Parsers and validators.** Structured output handling, including what happens on malformed JSON on the third attempt.

In the systems we audit, roughly two thirds of real incidents trace to this layer, and almost none of it was covered. Teams skip straight to LLM evaluation because that's what feels novel, then ship a probabilistic test suite over an untested deterministic substrate. That's backwards. Non-deterministic testing is slow and expensive; spend it only on the part that is genuinely non-deterministic — the model's choices.

## Three Layers Worth Measuring

For the probabilistic part, there are three distinct questions, and conflating them is why scores are uninterpretable.

| Layer | Question it answers | Assertion style | Where it runs |
|---|---|---|---|
| Unit / tool | Does the scaffolding behave? | Exact, deterministic | Every commit, seconds |
| Trajectory | Did it take an acceptable path? | Tool-call sequence, constraint violations | Pre-merge on a fixed set |
| Outcome | Is the end state correct? | Programmatic checker, then judge | Pre-merge + sampled in production |

**Trajectory evaluation** is the layer teams most often lack and the one that catches the most. You don't assert an exact sequence — there are several acceptable paths — you assert properties of the path: the required tool was called before the write; no tool outside the allowed set was touched; no more than N calls; the search step preceded the answer; nothing was emailed externally. These are cheap, deterministic assertions over a trace, and they catch the quiet failures described in [why AI agents fail in production](https://kuaray.tech/articles/why-ai-agents-fail-in-production) long before a human notices the output looks fine.

**Outcome evaluation** should start programmatic and only fall back to a judge. For a surprising share of real tasks, correctness is machine-checkable: the ticket moved to the right state, the generated code compiles and passes its own tests, the extracted fields match the source document, the invoice total reconciles. A model grading prose is the last resort, not the default. Every task where you reach for a judge is a task whose definition of done was never written down — which is worth knowing in itself.

## Building the Golden Set From Traces You Already Have

An AI agent evaluation framework is only as good as its cases, and synthetic cases are close to worthless: they encode what you imagined, and the model already handles what you imagined. The set has to come from production.

1. **Instrument for traces first.** Every run writes prompts, tool calls, arguments, responses, timings and cost as spans. Without this you have no case source and no way to reproduce a failure. This is standard [observability and platform work](https://kuaray.tech/services/all?service=devops), applied to a component most teams ship without it.
2. **Harvest the interesting tail.** Pull runs that errored, hit budget, escalated, got a thumbs-down, or ran unusually long. Boring successes teach nothing.
3. **Freeze each case as input plus expectation.** The input is the full starting state, not just the prompt. The expectation is whatever an independent checker can assert — a path property, a final state, a forbidden action.
4. **Add the adversarial cases by hand.** Prompt injection inside retrieved content, a tool returning a 500 mid-run, a tool returning plausible garbage, contradictory instructions, the ambiguous request where halting is the correct answer.
5. **Keep it small and curated.** Thirty to sixty live cases, maintained. A thousand auto-generated cases nobody prunes produce a number that drifts for reasons unrelated to quality.
6. **Promote every incident.** A production failure becomes a case the same day it's diagnosed. This is the only mechanism that makes the suite get better rather than staler.

Fixture the tool layer so cases are replayable: record real responses once, replay them deterministically, and keep a smaller live-integration subset for the contract tests. Otherwise every eval run is also a test of someone else's uptime.

## LLM-as-a-Judge, With the Caveats Nobody Puts in the Slide

A judge model is a legitimate instrument and a bad default. Where it earns its place — tone, helpfulness, whether a summary omitted something material — it needs the same treatment as any other measurement device.

Give the judge a rubric with discrete labels and a required justification, not a 1–10 score; numeric scores from models cluster and drift. Show it the reference answer where one exists — grading against a reference is far more reliable than grading in the abstract. Keep the judge's model and prompt version-pinned, because changing either silently rebaselines your entire history. Don't let the agent's own model family grade its own output on anything subjective. And calibrate: have a human label fifty cases, measure agreement with the judge, and quote that agreement number whenever you quote a score. An uncalibrated judge is an opinion with a decimal point.

## Making Non-Determinism Survive CI

The practical objection to agent testing in CI is flakiness, and it's real: the same input can pass four times and fail the fifth. The answer isn't to abandon the gate, it's to make it statistical and tiered.

Set temperature to zero where the task allows, and seed everything you can. Accept that this reduces variance rather than removing it. Then run each case a handful of times and gate on a pass rate against a recorded baseline, not on a single run — a case that passed 5/5 last release and 2/5 today is a regression, and you only see that if the suite is built to count. Hold the deterministic layer at 100%: those tests are allowed to be strict, and a flaky one is a bug.

Tier by cost. Unit and contract tests on every commit. The trajectory suite and a fast outcome subset pre-merge, with a hard token budget so the suite can't quietly become the largest line on the AI bill. The full suite nightly and before release. Then keep measuring after deploy: sample live runs, assert the same trajectory properties online, and alert on the distribution shifting — escalation rate, tool-error rate, cost per task, steps per task. Offline evals catch regressions you shipped; online evals catch the world changing underneath you, which is the more common cause of an agent that was fine in March.

## What This Buys You

A suite built this way changes the conversation from "does it feel better?" to "which cases moved, and why". It makes model upgrades a measurement instead of a leap of faith — swap the model, run the set, read the diff. It makes prompt changes reviewable. And it gives you the one artifact an enterprise buyer, an auditor or a nervous CTO actually wants: evidence, per release, that the system still does what you claim.

Strip away the tooling question and how to test AI agents reduces to one unglamorous rule: if you cannot name the independent checker for an agent task, the task is not ready to be delegated. Write the checker first. It usually reveals that the requirement was underspecified for a human too, which is the real finding.

**[Have Kuaray build or audit your agent evaluation suite](https://kuaray.tech/contact)** — we instrument traces, build the golden set from your own production runs, and wire the gates into CI. See how we approach [AI and agent engineering](https://kuaray.tech/services/all?service=ai-machine-learning), or our [MVP approach](https://kuaray.tech/mvp-approach) if you're taking a first agent from prototype to something you can leave running.
