How to Test AI Agents: Evaluation Frameworks & Quality Metrics

COMPLETE guide to AI agent testing in 2026. Unit tests, LLM evals, tracing, CI/CD gates — real tools, real metrics. Build agents that don't fail in prod.

Quick answer: Testing AI agents requires four distinct layers — deterministic unit tests for routing logic, LLM evaluation tests for non-deterministic behavior, integration tests for real tool calls, and production monitoring to catch drift. Use DeepEval or LangSmith for automated evals, build a golden dataset from real failures, and gate deployments with score thresholds. A single output-only check misses the 80% of failures that happen in intermediate steps.


Only 52% of teams running AI agents in production have any form of evaluation in place, according to LangChain's 2026 State of Agent Engineering survey of 1,300+ practitioners. Meanwhile, Gartner predicts that 40% of agentic AI projects will be canceled by end of 2027 — largely due to reliability problems that nobody measured until it was too late.

The agents that survive production aren't necessarily smarter. They're tested better.

This guide walks through every layer of AI agent testing — from deterministic unit tests to adversarial red-teaming — with the exact tools, metrics, and CI/CD patterns used by engineering teams shipping agents at scale. If you're building on cowork.ink or any other platform, this is the quality infrastructure your agent needs before it touches real users.


Why AI Agent Testing Is Different

Traditional software has one property that makes testing straightforward: determinism. Given the same input, you get the same output. Write an assertion, done.

AI agents break all of this at once.

The same task prompt can produce different tool selections, different reasoning paths, and different outputs across runs — and multiple outcomes can all be "correct." An agent completing a customer support task might search the knowledge base in a different order, use different phrasing in its reply, or take slightly different steps through a multi-turn conversation. Each variation is valid. Exact-match assertions fail on all of them.

There is also the multi-step failure compounding problem. An agent doing five reasoning steps accumulates errors: a slightly wrong document retrieval in step 1 leads to a wrong tool selection in step 3, which produces a hallucinated final response. Output-only testing catches the final symptom but misses where it actually went wrong — which is why AI agent debugging techniques like step-level trace replay are essential complements to testing.

A τ-bench study by Sierra AI illustrated this starkly: state-of-the-art agents, including GPT-4o, achieved around 60% pass@1 (single-run success) on realistic customer service tasks — but their pass^8 score (succeeding eight consecutive times on the identical task) dropped below 25%. Customers experience that inconsistency directly. It cannot be caught by testing once.

The consistency trap

A 60% task completion rate sounds acceptable. But pass^8 below 25% means three out of four users hitting the same task will see a failure at some point. Pass@1 hides the variance that actually determines user experience.


The Four-Layer Testing Stack

Think of AI agent testing as four layers, each with different tools and different cadences.

🔩
Layer 1: Unit Tests

Deterministic tests with the LLM mocked out. Validates routing logic, tool schema validation, error handling, and output parsing. Runs on every commit. Uses standard Pytest.

🧪
Layer 2: LLM Evals

Non-deterministic evaluation of LLM behavior: tool selection accuracy, hallucination rate, answer relevancy. Runs nightly or on PRs to main. Uses DeepEval, RAGAS, or Braintrust.

🔌
Layer 3: Integration Tests

Full agent runs with real tools, real APIs, and real databases in a staging environment. Tests fault tolerance, timeout handling, and schema compatibility. Runs before deploys.

📡
Layer 4: Production Monitoring

Continuous eval on sampled live traffic. Catches prompt drift, model degradation, and edge cases that test suites never anticipated. Uses LangSmith, Langfuse, or Arize Phoenix.


Layer 1 — Unit Tests (Deterministic)

Unit tests mock out the LLM entirely and test the deterministic scaffolding around it.

What to test at this layer:

  1. Routing logic — Does the right intent trigger the right agent or tool chain?
  2. Tool call schema — When a tool is invoked, does the argument structure match the expected JSON schema?
  3. Error handling — Does the agent handle API timeouts, 404s, and auth failures gracefully rather than crashing?
  4. Output parsing — Does the structured output parser correctly handle edge cases (empty responses, extra whitespace, nested JSON)?
  5. Memory retrieval — Does the agent correctly retrieve and format context from its memory store?

These tests use standard Pytest with mocked LLM responses. They are fast (milliseconds), cheap to run, and should block every commit that breaks them.

# Example: testing that a tool call produces the correct schema
from unittest.mock import patch
import pytest

def test_search_tool_schema(agent):
    with patch("agent.llm.invoke") as mock_llm:
        mock_llm.return_value = '{"tool": "search_kb", "args": {"query": "refund policy"}}'
        result = agent.run("What is the refund policy?")
        assert result["tool"] == "search_kb"
        assert "query" in result["args"]
Mock the LLM, not the tools

At this layer, mock the LLM but leave the tool logic real. You want to test your routing and parsing code — not the LLM's decision-making. That comes in Layer 2.


Layer 2 — LLM Evaluation Tests

This is where standard testing frameworks break down. The LLM is live, outputs vary, and "correct" is often a gradient not a binary.

The key conceptual shift: replace assertions with graders.

Anthropic's evaluation framework distinguishes three types of graders:

Grader TypeHow It WorksWhen to Use
DeterministicRegex, string match, schema validation, outcome checkTool call format, factual claims with known answers
LLM-as-judgeA strong model (GPT-4, Claude) scores the output against a rubricRelevancy, reasoning quality, tone, safety
Human reviewA human evaluator rates the outputNuanced cases, calibrating LLM judges, ambiguous edge cases

GPT-4-class LLM judges align with human judgment roughly 85% of the time when given clear rubrics and constrained scoring outputs. That alignment drops significantly without chain-of-thought prompting and explicit scoring criteria.

Key Metrics to Track

Task Completion Rate (TCR): The percentage of tasks the agent completes without requiring human intervention. Set a production threshold — many teams use 65% as a minimum before deployment.

Tool Selection Accuracy: Whether the agent selects the correct function/API at each step. A tool that gets called with slightly wrong arguments can cause cascading failures across the entire task.

Step-Level Success Rate: Grade each intermediate step in the agent's execution, not just the final output. This is where multi-step failure compounds become visible.

Hallucination Rate: Does the agent fabricate facts, citations, or tool outputs? For RAG-enabled agents, also track context faithfulness (did the response stay grounded in retrieved documents?).

Answer Relevancy: Is each response on-topic given the conversation history and current task state?

The Best Frameworks

DeepEval is the closest thing to Pytest for LLM agents. It is open-source, integrates directly with your test suite, and provides built-in metrics for G-Eval, hallucination detection, task completion, tool-call accuracy, and answer relevancy. Scores are expressed as floats, and you set thresholds for pass/fail.

RAGAS is specialized for RAG pipeline evaluation. If your agent retrieves documents before responding, RAGAS gives you context precision, context recall, answer faithfulness, and answer relevancy as first-class metrics.

LangSmith provides dataset management, evaluation runs, and score tracking tightly integrated into the LangChain/LangGraph ecosystem. Run your eval set against multiple prompt versions to compare performance before deploying a change.

Braintrust focuses on collaborative eval iteration — useful for teams where prompt engineers and developers both need to review and annotate eval results.

Build a golden dataset first

Before running any evals, build a curated set of test cases: representative prompts + expected outcomes. Source them from real production failures, edge cases, and intentionally tricky inputs. This golden dataset is the source of truth for every future eval run. Version it alongside your prompts.


Layer 3 — Integration Tests

Integration tests run the full agent against real tools and real APIs in a staging environment, without the LLM mocked out.

The goal is to catch failures that only emerge when components interact: an API that changed its response schema, a database query that returns empty results the agent doesn't handle, a tool that times out under load.

What to test here:

  1. API compatibility — Does the agent still work after an upstream API changed its response format?
  2. Timeout handling — If a tool call takes 30 seconds instead of 1, does the agent fail gracefully or hang forever?
  3. Empty/null responses — Does the agent degrade gracefully when a search returns zero results instead of crashing?
  4. Authentication failures — Does the agent surface a clear error instead of silently returning wrong data?
  5. Multi-turn coherence — In a long conversation, does the agent correctly maintain context across tool calls?

For fault injection testing, intentionally fail individual tools and verify the agent's fallback behavior. Many critical production failures are "the tool returned an error" scenarios that developers never think to test.


Layer 4 — Production Monitoring

Only 44.8% of teams run online evaluations on live production traffic, according to LangChain's survey. This is the biggest gap in most organizations' testing strategies.

Production monitoring catches what no test suite anticipates: the real user queries that don't resemble your golden dataset, prompt drift as context accumulates, model degradation after an LLM provider silently updates a model, and edge cases that emerge from usage patterns you didn't design for.

What to Instrument

Trace every step. Capture every prompt, every tool invocation, every model response, every latency value, and every cost across the complete execution graph. Tools like LangSmith, Langfuse, and Arize Phoenix provide full session replay — you can watch exactly what the agent did on any production run.

Run online evals on sampled traffic. You cannot evaluate 100% of production requests with an LLM judge (the cost would be prohibitive). Instead, sample 5–10% of traffic and run the same eval rubrics you use offline. Track score distributions over time. A sudden drop in answer relevancy often precedes a flood of user complaints by 24–48 hours.

Set alerting thresholds. Alert when task completion rate drops below your SLA, when tool error rates spike, or when average cost per task exceeds budget. These metrics are early warning signals for model or prompt regressions.

Recommended Observability Stack

ToolBest ForOverhead
LangSmithLangChain/LangGraph ecosystems, tight eval integration~0%
LangfuseSelf-hosted, full data ownership, cost tracking~15%
Arize PhoenixEnterprise, deep LLM eval, multi-model comparisonsLow
AgentOpsLightweight monitoring, fast setup~12%
HeliconeProxy-based, easy drop-in for OpenAI-compatible APIsMinimal

For most teams, Langfuse (open-source, self-hostable) or LangSmith (tightest developer experience) are the right starting points. See our guide to AI agent observability for a full setup walkthrough.


Adversarial Testing and Red-Teaming

For agents that handle sensitive data, financial transactions, or external communication, adversarial testing is not optional.

Adversarial testing probes specific known attack vectors: prompt injection (can a malicious document override the system prompt?), jailbreaks (can a user get the agent to ignore its instructions?), tool misuse (can the agent be tricked into calling a destructive API?), and PII leakage (does the agent inadvertently surface private user data?).

Red-teaming goes further: it simulates a threat actor with a goal, a set of capabilities, and a multi-step attack path. A red team session maps what an attacker would actually do — not just isolated prompt tricks — and tests the full chain of agent defenses.

Microsoft Foundry has an AI Red Teaming Agent product that automates adversarial scenario generation. For most teams, manual red-teaming sessions before major releases, combined with automated prompt injection tests in CI, provides a reasonable baseline.

Prompt injection is the #1 agentic attack vector

A malicious document retrieved by your RAG agent that says "IGNORE ALL PREVIOUS INSTRUCTIONS" is a prompt injection attack. Test for this explicitly. Check our AI agent security guide for a full treatment of injection defenses.


Integrating Tests into CI/CD

Testing without deployment gates is just logging. The real leverage comes from blocking deployments when agent quality drops below a threshold.

A practical CI/CD pipeline for agent quality:

  1. On every commit — Run Layer 1 unit tests (Pytest, deterministic). Block merge if any fail.
  2. On every PR to main — Run a subset of Layer 2 evals (10–20 critical test cases). Block merge if any metric drops >5% from baseline.
  3. Before every deploy — Run full Layer 2 eval suite against the golden dataset. Block deploy if TCR drops below threshold or hallucination rate spikes.
  4. Post-deploy — Run Layer 3 integration tests against production environment. Rollback automatically if integration tests fail.
  5. Continuously — Layer 4 production monitoring. Alert on anomalies; create new test cases from observed failures.
✓DO
  • •Set numeric score thresholds, not just pass/fail
  • •Run each eval 3+ times and average scores
  • •Version your golden dataset alongside prompts
  • •Trace every intermediate step in production
  • •Create new test cases from every production failure
✕DON'T
  • •Use exact-match assertions on LLM outputs
  • •Test only the final output and ignore intermediate steps
  • •Run evals once and treat it as done
  • •Deploy without observability in place
  • •Build a static golden dataset that never updates

How Benchmarks Help (and Where They Fall Short)

Industry benchmarks give useful external reference points when setting internal quality thresholds.

SWE-bench tests agents on resolving real GitHub issues. Claude 3.7 Sonnet achieved 62.3% on SWE-bench Verified — a significant milestone that establishes what best-in-class looks like for code agents. If your coding agent scores below 20% on a comparable subset, you have a baseline problem before worrying about optimization.

GAIA measures general AI assistant capabilities on real-world multi-step tasks requiring web browsing, file reading, and extended reasoning. Frontier agents currently reach around 60% on the hardest level.

τ-bench is the most useful benchmark for evaluating production readiness. Its retail and airline service scenarios use LLM-simulated users, measure pass^k consistency across multiple runs, and expose the gap between theoretical capability and reliable real-world performance. Use it as a calibration tool for your internal task completion rate targets.

However, benchmarks measure capability on curated tasks — not your specific domain. A 60% GAIA score tells you nothing about whether your agent will correctly process invoices for your finance team. Benchmarks calibrate ambition; golden datasets measure reality.


Where to Go from Here

Build your testing stack incrementally. The highest leverage starting point is instrumentation — you cannot improve what you cannot measure.

  1. Week 1: Add trace logging to your agent (LangSmith or Langfuse). Every step, every tool call, every latency.
  2. Week 2: Build a 20-case golden dataset from real production queries or your known edge cases.
  3. Week 3: Write 5 LLM eval tests with DeepEval measuring TCR and tool selection accuracy. Run them manually.
  4. Week 4: Integrate evals into your CI pipeline. Block deploys on score regressions.
  5. Month 2: Add production sampling, alerting thresholds, and a red-teaming session before your next major release.

If you're running multi-agent workflows where reliability compounds across teams, cowork.ink gives every team member shared visibility into agent traces, evaluation scores, and production health — without each developer needing to configure observability independently.


Get Started

The agents that make it to production — and stay there — are built on a feedback loop: instrument, measure, gate, improve. Start with tracing. Add your first five eval tests. Gate your next deploy on a TCR threshold.

That gap between 52% of teams running evals and 89% running observability is where production AI agents go to die. Close it before your agents do.

Visit cowork.ink to set up shared agent workspaces with built-in observability for your whole team.

Frequently Asked Questions

How do you evaluate the performance of an AI agent?
Evaluate AI agents across four dimensions: task completion rate (did it finish the job?), tool selection accuracy (did it pick the right APIs?), quality (were outputs relevant and hallucination-free?), and cost/latency. Use frameworks like DeepEval or LangSmith to run these evaluations systematically against a curated golden dataset. See our full breakdown in the [metrics section below](#what-metrics-actually-matter-for-ai-agents).
What is the difference between LLM testing and AI agent testing?
LLM testing checks a single prompt-response pair — is the output correct? AI agent testing evaluates a multi-step execution graph: did the agent pick the right tool? Did it reason correctly at each step? Did it complete the full task without accumulating errors? Agent testing requires step-level tracing, not just output scoring.
How do you handle non-determinism when testing AI agents?
Run each test case multiple times and average the scores. Use semantic similarity metrics instead of exact-match assertions. Set score thresholds (e.g., pass if ≥70% of 5 runs succeed) rather than binary pass/fail. Track the pass^k metric — how often an agent succeeds k consecutive times — since a 60% pass@1 rate can hide a sub-25% consistency rate.
What tools do developers use to test AI agents?
The most widely adopted tools are LangSmith (best for LangChain ecosystems), DeepEval (open-source Pytest-style evals), Langfuse (self-hosted observability), and Braintrust (collaborative eval iteration). For lower-level testing of deterministic components, standard Pytest with mocked LLMs works well.
What is a golden dataset for AI agent evaluation?
A golden dataset is a versioned, curated collection of representative prompts paired with expected outcomes — your evaluation source of truth. Build it from real production queries, edge cases, and known failure modes. Update it whenever you add new agent capabilities or observe a new failure category in production.
Home Blog Company