Launch Week 02 wrapped — explore all five launches
Back

AI Agent Testing: How to Test Tool Calling, Regressions, and Failure Handling

Kritin Vongthongsri, Co-founder @ Confident AI

LLM Evals & Safety Wizard. Previously ML + CS @ Princeton researching self-driving cars.

AI agent testing is the practice of verifying an agent's behavior before it reaches users: that it selects the right tools with the right arguments, follows sensible multi-step trajectories, handles tool failures gracefully, avoids loops, and does not regress when prompts or models change. It differs from single-turn LLM testing because the thing under test is a sequence of decisions with side effects, not one output.

The stakes are different too. A chatbot that answers badly wastes a user's time; an agent that calls the wrong tool issues a refund, books a meeting, or modifies a record. Testing has to cover not just what the agent says but what it does — which is why McKinsey's research on the agentic era consistently finds trust and verification, not capability, to be the binding constraint on agent deployment.

This guide covers the pre-production testing discipline end to end: defining success criteria, writing tool-calling test cases, regression testing, failure simulation, loop prevention, CI/CD integration, and how non-engineers should read the results. It is the testing companion to evaluating AI agents, which covers the evaluation methodology in depth — this guide focuses on the harness.

Why do AI agents break traditional testing?

Traditional tests assert one deterministic output for one input. Agents violate every part of that model: the same input can produce different valid outputs, the behavior under test is a multi-step chain where each step depends on the last, and tool calls have real side effects that a test environment must contain. Testing agents therefore means asserting properties of behavior — right tool, valid arguments, task completed, no loops — rather than exact outputs.

Three specific breaks matter for harness design. Non-determinism means assertions must tolerate valid variation: "the response addresses the refund" rather than "the response equals this string." Quality verdicts come from metrics — deterministic checks where possible, LLM-as-a-judge metrics where nuance is required. Emergent multi-step behavior means single-step assertions miss the failures that matter: each individual decision can look locally reasonable while the trajectory as a whole detours, stalls, or loops. Side effects mean the test environment needs sandboxed or mocked tools — an agent test suite that hits real APIs is either dangerous or untestable, usually both.

None of this means abandoning the testing instincts you have. It means the unit of assertion moves from the output string to the execution trace — which is why everything in this guide presumes your agent is instrumented with span-level tracing.

Define what good looks like before you write a test

The first artifact of agent testing is not a test — it is a written definition of success and failure. For each task the agent handles, define the expected outcome ("refund issued for the order the user named, confirmation message sent"), and define the failure boundaries: the things that must never happen, like hallucinated tool calls, actions on the wrong entity, fabricated confirmations, or safety violations.

These definitions become golden examples — concrete cases pairing an input scenario with the expected behavior — and they do double duty. They are the seed of your test dataset, and they are the alignment mechanism between engineering and product: when a PM writes "the agent should escalate, not apologize, when the user asks for a human twice," that sentence is a test case waiting to be encoded. Teams that skip this step write tests that assert what the agent currently does rather than what it should do, which makes every test pass and none of them meaningful.

Keep the golden set versioned and reviewed like code, in tooling the whole team can access — success criteria scattered across spreadsheets and Slack threads decay in weeks. Confident AI's dataset management treats goldens as versioned, collaboratively edited artifacts, which is what keeps the definition of "good" from drifting apart between the people who define it and the people who encode it.

Testing AI agent tool calling

Tool calling is tested at three levels — selection, arguments, and trajectory — and the levels fail independently: an agent can pick the right tool with wrong arguments, or make individually correct calls in a wasteful or broken order. A complete suite asserts all three.

Test tool selection

For each golden scenario, assert which tool the agent should have invoked. A support agent asked for a refund should call the refund tool, not the booking tool, and not answer from memory without calling anything. The assertion runs against the tool spans in the execution trace: given this input, the trace should contain a call to this tool. Include negative cases — inputs where the correct behavior is no tool call — because over-eager tool use is as real a failure as tool neglect, and it is invisible if every test expects a call.

Validate tool call arguments

Selection being right says nothing about the arguments. The classic failures are hallucinated IDs (an order number the user never gave), format errors (dates, currencies, enums), and missing required parameters silently defaulted. Two layers catch them: schema validation on every call (types, required fields, format constraints — deterministic and free), and grounding checks that the argument values trace to the conversation — the order ID in the call should appear in what the user actually said, not be invented to satisfy the schema.

Test the full trajectory

Trajectory tests assert properties of the whole sequence: the agent reached the goal, took a reasonable path, and did not detour into irrelevant calls or repeat itself. For a multi-step task, define the expected path (or the set of acceptable paths) at the level that matters — "lookup before refund, exactly one refund call, confirmation after" — and assert against the ordered tool spans in the trace.

Confident AI agent trace graph visualizing tool calls and step-by-step execution within an agent run.
Confident AI agent trace graph

Trajectory review is also where reading traces by hand earns its keep: before encoding a trajectory assertion, read a handful of real execution traces for the scenario. The detours agents actually take are rarely the ones you would guess, and the best trajectory tests are transcribed from observed failures rather than imagined ones.

Regression testing AI agents

Agent regression testing runs every change — prompt edit, model swap, tool schema change, orchestration tweak — against the golden dataset and blocks the change if behavior regresses. The mechanics (baselines, verdict flips, threshold tiers, PR gates) are the standard discipline covered in LLM regression testing; what is agent-specific is where the cases come from and what they assert.

The highest-value regression cases come from production failures, through a fixed loop: capture the execution trace of the failure, classify the failure mode, sanitize the data, define what the agent should have done, and add the case to the golden set before the fix ships. From then on, that failure is tested on every change, forever. This loop is what makes an agent test suite converge on reality — the suite grows exactly where the agent actually breaks.

Confident AI test cases view showing failed CI/CD cases, eval insights, filters, annotations, and options to save failures as a new dataset.
Confident AI eval insights and failed test cases

The assertions in agent regression cases span all three tool-calling levels plus outcome: did the fixed case still select correctly, argue correctly, follow the trajectory, and complete the task? A prompt change that fixes tone can silently break tool selection three scenarios away — which is the argument for running a broad representative subset on every change and the complete suite nightly or before release, rather than testing only the cases the author thought were related. Platforms that auto-curate production traces into datasets remove the manual plumbing from this loop; without that, the loop survives on discipline alone, which is to say it usually doesn't.

Testing edge cases and preventing loops

Loops are the signature agent pathology: the agent calls the same tool repeatedly with minor variations, re-asks for information it already has, or cycles between two states without progressing. Test for them deliberately, because they emerge from exactly the inputs your happy-path cases don't cover — ambiguous requests, contradictory instructions, and tasks that are almost but not quite achievable with the available tools.

The test design has three parts. First, hard guards asserted as behavior: max-iteration limits and repeated-call detection should exist in the agent, and the suite should include cases proving they trigger — an input engineered to induce cycling should end with a graceful stop, not a timeout. Second, ambiguous-input cases: requests that could route two ways, missing key details, or mixing two tasks. The correct behavior is usually to ask a clarifying question; the failure is to guess and act. Third, conversation-level metrics on multi-turn cases: loop and drift behaviors that span turns — the agent losing track of the goal, re-answering an earlier question, drifting off the user's intent — are caught by conversation completeness, knowledge retention, and role adherence metrics, not by any single-turn assertion. The multi-turn testing methodology is covered in evaluating multi-turn chatbots.

Simulating tool call failures

Production tools fail — timeouts, empty results, error payloads, malformed responses — and the agent's behavior under tool failure is a first-class quality surface. The failure mode you are testing against: the agent that treats a failed call as a success and reports a confident, fabricated outcome to the user. An agent that tells a customer their refund went through when the refund API timed out is a worse failure than any wrong answer.

Failure simulation works by mocking tool responses in the test environment: for each critical tool, build cases where it times out, returns empty, returns an error, and returns garbage. The assertions target the recovery behavior — the agent retried within limits, fell back to an alternative where one exists, or plainly communicated the failure to the user — and, hard-line, that no success was claimed. Run these in the same suite and CI workflow as the standard cases rather than as a separate "chaos" exercise someone runs quarterly; tool-failure handling regresses under prompt changes exactly the way everything else does.

This is also the cheapest place to buy production resilience before production. Every tool your agent depends on will eventually fail in front of a user; the only question is whether the agent's response to that moment was ever tested.

Integrating agent tests into CI/CD

The tiering that keeps agent testing fast enough to survive: deterministic checks on every PR (schema validation, tool-selection assertions on the golden subset, guard tests — minutes), judge-based evaluation nightly (full metric suite over the whole dataset, including simulated multi-turn scenarios), and the complete regression suite as the release gate, with pass-rate thresholds and non-negotiable cases that block at any failure.

The tiers exist because judge-based metrics over hundreds of scenarios are too slow for a PR check, and a slow gate is a bypassed gate. The PR tier catches the blatant breaks immediately; the nightly tier catches the subtle ones within a day; the release tier guarantees nothing ships without the full verdict. Wire the results to where the team already looks — the PR itself, with per-case flips and judge reasoning attached — and store every run so trends are visible across changes. Confident AI's CI reports and regression tracking turn these runs into shared, reviewable artifacts rather than logs only the pipeline author can parse; whatever tooling you use, that reviewability is the requirement.

What to look for in agent testing tooling

The capability checklist for evaluating any agent testing framework or platform in 2026:

Capability

Why it matters for agent testing

Span-level trace assertions

Tool selection, arguments, and trajectories live in spans; output-only tools cannot test them

Tool mocking / failure injection

Failure-handling tests require controlled tool responses in the harness

Multi-turn scenario simulation

Conversational agents must be tested on fresh simulated dialogues, not replayed transcripts

Validated metrics, deterministic and judge-based

Both tiers are needed: fast checks for CI, judged quality for nuance

Golden dataset versioning with team access

Success criteria are a shared, evolving artifact — not a spreadsheet

Production-trace-to-test-case conversion

The regression loop lives or dies on this being automatic

CI/CD integration with pass/fail gating

The suite must block merges natively

Results readable by non-engineers

Ship decisions involve PMs and QA; evidence must be legible to them

For how the named tools in this space stack up against these dimensions, see the comparisons of CI/CD tools for testing AI agents before production and QA tools for AI agents.

Reading test results as a product manager

A PM does not need to read code to make a ship decision from agent test results — four numbers carry it. Pass rate by suite: the overall percentage, broken out by scenario category, with any category meaningfully below its baseline treated as a hold signal even if the aggregate looks fine. Regression delta: which cases flipped from pass to fail versus the last release — this list, not the aggregate, is the actual risk register for the change. Non-negotiable status: the safety, policy, and worst-historical-incident cases, which gate at 100% and end the conversation if any fail. Judge reasoning on the failures: each failed case carries a plain-language explanation of what went wrong, which is readable evidence, not engineering telemetry.

The discipline point runs both ways. Engineering owes the PM results in this form — legible, categorized, compared to baseline. And the PM owes the process a real read of the flipped cases before shipping, because "the pass rate is still 94%" has approved more bad releases than any other sentence in AI product management. Confident AI's dashboards present exactly this view — pass rates, deltas, and per-case reasoning — without requiring anyone to pull the repo.

What to do Monday morning

  • Write ten golden examples for your agent's core task: input scenario, expected tool calls, expected outcome, and the failure boundaries that must never occur.
  • Add the deterministic layer to CI today: schema validation on every tool call, and tool-selection assertions on the ten goldens.
  • Stand up failure simulation for your single most critical tool — timeout, empty, error — and assert the agent never claims success through a failure.
  • Pipe your last five production failures into the golden set as regression cases before fixing the next one.
  • Set the release gate: full suite, non-negotiables at 100%, pass-rate threshold at your current baseline — then tighten as the suite grows.

Frequently Asked Questions

How do I write test cases for an AI agent with tool calling?

Assert at three levels against the execution trace: tool selection (given this input, the trace contains a call to the right tool — including negative cases where no call is correct), argument validity (schema checks plus grounding checks that argument values trace to the conversation, not hallucination), and trajectory (the ordered sequence of calls reaches the goal without detours or repeats). Each golden scenario should carry assertions at all three levels.

How do I test AI agents in development before shipping to production?

Define success criteria and failure boundaries as golden examples first, then build the suite in layers: deterministic checks (schemas, tool selection) running on every PR, judge-based quality metrics nightly, failure-simulation cases for every critical tool, loop and ambiguity cases, and multi-turn scenario simulation for conversational agents. Gate releases on the full suite with non-negotiable cases at 100%.

What is the best way to regression test an AI agent?

Convert every confirmed production failure into a golden case — captured trace, classified failure mode, defined expected behavior — before its fix ships. Run all non-negotiable cases plus a representative subset on every change, and run the complete golden set nightly or before release with per-case verdict comparison against baseline. The flipped cases, not the aggregate pass rate, are the regression.

How do I test that my agent handles edge cases and does not loop?

Three layers: hard guards (max iterations, repeated-call detection) with test cases proving they trigger gracefully; ambiguous-input cases where the correct behavior is a clarifying question rather than a guess; and conversation-level metrics — completeness, knowledge retention, role adherence — on simulated multi-turn scenarios, because loop and drift behaviors span turns and are invisible to single-turn assertions.

How do I simulate tool call failures to test my agent's error handling?

Mock each critical tool to return timeouts, empty results, error payloads, and malformed responses, then assert the recovery behavior: bounded retries, fallbacks where they exist, honest communication of the failure to the user — and never a claimed success over a failed call. Keep these cases in the main CI suite, not a separate exercise, because failure handling regresses under prompt changes like everything else.

As a product manager, how do I review agent test results and decide if we are ready to ship?

Read four things: pass rate by scenario category (any category below its baseline is a hold signal regardless of the aggregate), the list of cases that flipped from pass to fail since the last release, the status of non-negotiable safety and policy cases (100% or no ship), and the judge reasoning on failures, which explains each miss in plain language. The flipped-case list is the risk register — read it before approving, every time.