Short answer: shipping an AI agent safely requires four layers of testing — component (tool) testing, trajectory evaluation, LLM-as-judge scoring, and adversarial red-team scenarios. Skip any one layer, and the failure class it was supposed to catch shows up in production instead of in QA.
Why aren't regular unit tests enough for agents?
Short answer: because an agent doesn't return the same output for the same input every time (non-determinism), calls tools, and follows a multi-step path — while unit tests are built to check a single input-output pair. LangChain's 2026 State of AI Agents report found that 57% of organizations now have agents in production, and quality is the number-one barrier to deployment.
An agent can reach "the right answer" through multiple paths, and some of those paths involve an unnecessary tool call, an unsafe intermediate step, or a cost-inflating loop. The final answer being correct doesn't mean those intermediate steps are safe or cheap.
How do you build fixtures and simulated tools?
Short answer: build mock tools and fixed scenario files (fixtures) so the agent runs without touching real APIs or a live database — every test run then starts from the same state, and variability in external services never contaminates the result. A simulated environment stops you from hitting a real payment API or a production database on every test run.
These fixtures also become the backbone of regression testing: once a bug is fixed, the scenario that triggered it gets saved as a permanent "golden transcript" and re-run automatically on every new version.
What does trajectory evaluation actually catch?
Short answer: trajectory evaluation scores every step the agent takes to reach an answer, not just the final answer — which tools it called, in what order, whether arguments were passed correctly, and whether any call was redundant or duplicated. This catches an entire failure class that output-only evaluation misses completely.
A customer support agent can reach the correct answer while repeating the same database query three times along the way — a cost and latency problem that a final-answer-only test will never see. Trajectory metrics are built exactly for this: tool choice, reasoning quality, argument correctness, and decision order.
How reliable is LLM-as-judge scoring?
Short answer: LLM-as-judge (one model scoring another model's output) can be reliable, but the scoring scale matters a lot — the January 2026 "Grading Scale" paper found a 0–5 scale gives the strongest alignment with human judgment (Pearson correlation of 0.89), while binary (0/1) or 10-point scales weaken that alignment.
That said, LLM-as-judge alone isn't sufficient — without periodic human spot-checks, you can't catch the judge model's own systematic biases. In practice, reviewing at least 5–10% of judged outputs by hand is a reasonable target.
How many test cases do you actually need?
Short answer: aim for at least 500 cases before you trust aggregate metrics — but volume alone isn't the deciding factor, quality matters more. 100 carefully curated cases with precise expected trajectories are worth more than 1,000 auto-generated cases with vague expected outputs.
Test layer | What it catches | Example tool/method |
|---|---|---|
Component testing | Single tool-call errors | Mock APIs, fixed fixtures |
Trajectory tracking | Redundant/duplicate/unsafe steps | Step-by-step assertions |
LLM-as-judge | Final answer quality, tone, accuracy | 0–5 scale scoring + human spot-checks |
Adversarial testing | Prompt injection, jailbreaks, privilege escalation | Red-team scenarios |
Why can't you skip adversarial testing?
Short answer: because an agent has access to tools and external data, a malicious input or a poisoned document can steer it into an unexpected action — so prompt injection and privilege-escalation scenarios need to be part of the test suite from day one. An agent performing flawlessly on "normal" scenarios says nothing about how it behaves against an adversarial input.
The most commonly missed scenario is indirect prompt injection: the agent executing instructions buried inside a tool's own output — for example, summarizing a web page and treating a hidden command embedded in that page as a real user request. Testing for this belongs in the same pipeline as wiring AI agents into your CI/CD safely.
How do golden transcripts go stale over time?
Short answer: once a model provider ships a new version or a tool schema changes, previously recorded golden transcripts can end up referencing behavior that no longer matches reality — so a golden transcript set needs to be managed as a living asset under regular review, not a static file. A reference transcript recorded three months ago can silently start producing false positives once the model provider changes its tool-calling behavior.
A practical fix is re-running a subset of the golden transcript set and getting human re-approval on every model version bump. That keeps the set from growing unbounded while stopping you from missing a behavioral drift in the underlying model.
How do you gate agent tests in CI?
Short answer: set thresholds on trajectory and LLM-as-judge scores and automatically block a deploy that falls below them, and give every test run a cost budget (a token/request cap), since a 500+ case suite against real model calls gets expensive fast. A common cost-saving pattern is using a small, cheap model as the judge and routing only borderline results to a stronger model or a human.
My take: teams tend to stand up LLM-as-judge first and assume they're done, then skip the trajectory layer entirely — and only discover the real production cost blowup (redundant tool calls) months later. Building all four layers up front avoids that delayed discovery.
If you're unsure when to reach for an agent versus a simpler workflow, AI agents vs workflows covers that decision; when building your first connector, it's worth applying this same four-layer test structure to the tool definitions in the MCP connector guide.
Frequently Asked Questions
What's the most commonly skipped layer in AI agent testing?
The trajectory (step-tracking) layer is skipped most often because it takes more engineering effort to set up than LLM-as-judge. Without it, you never see the unnecessary or unsafe intermediate steps an agent takes on the way to a correct final answer.
Which scoring scale works best for LLM-as-judge?
The January 2026 Grading Scale paper found a 0–5 scale gives the strongest alignment with human judgment, at a Pearson correlation of 0.89. Binary (0/1) and 10-point scales weaken that alignment.
How many test cases do I need?
Aim for at least 500 cases before trusting aggregate metrics, but quality matters more than volume. 100 carefully curated cases with precise expected trajectories beat 1,000 vague, auto-generated ones.
Why is adversarial testing more critical for agents than for unit-tested code?
Because an agent has access to external tools and data, a poisoned document or malicious input can steer it into an unexpected action. That risk creates an attack surface that classic unit test coverage never encounters.
