Faultgate 0.5.0, Faultgate-Zero 0.2, Trace-to-Fixture 0.1 and Fault-Contract 0.1 are on PyPISee products →
Guides

How to Test AI Agents Before They Reach Production

One green run proves little. Test AI agents across repeated runs, check tool calls with fixed rules, and gate every release in CI.

How to Test AI Agents Before They Reach Production

AI agent testing is the practice of running the same tasks many times, checking every tool call against fixed rules, and blocking a release when the results move outside their normal noise. You measure a distribution, not a single run.

Picture a refund agent that passes its demo once and ships. If it succeeds 80% of the time per run, it completes five refunds in a row only about 32.8% of the time (FAULTLINE). The demo was a sample, and production collects the rest of the draws.

This guide is the method we use at FAULTLINE. Measure across runs, check tool calls with rules, gate on a noise band, turn every production failure into a fixture, and test the tools themselves. Each section gives the mechanism and the evidence behind it.

01 / Why one passing run proves almost nothing

An agent's result is a sample from a distribution, and a single pass is one draw from it. FAULTLINE ran the same model on the same thirty inputs five times, and the pass rate moved from 0.60 to 0.87 (Regression or noise?). Nothing changed except the run. That is a twenty-seven point swing in a number people quote as a single figure.

The compounding is worse than it looks. At an 80% success rate per run, five consecutive successes happen about 32.8% of the time (Why a single successful run tells you almost nothing). You can compute it as 0.8 to the fifth power. Run by run, 0.8 to the power k gives 80%, 64%, 51.2%, 41.0% and 32.8% for one to five runs in a row. A demo that passes is often the best of several draws, and the failures sit in the runs nobody recorded.

Pinning temperature does not remove the problem. Thinking Machines sampled 1,000 completions at temperature 0 and got 80 unique completions, with the most common one appearing 78 times (Defeating Nondeterminism in LLM Inference). Their explanation is that server load changes batch size, and batch size changes the arithmetic of the forward pass (same post). Two runs of the same prompt can take different paths through the model.

Why does this happen? The model, the tools, and the environment all carry state between runs. A cache warms. A retriever returns a different top document. A rate limit changes a timeout.

None of those changes is visible in a diff, and all of them can flip a borderline task. When a task sits near the model's capability edge, a small change in context tips it. That is why the same suite can look healthy on Monday and broken on Wednesday without a code change.

Animated bars showing pass rate decay across five runs from 80% down to 32.8%.
Pass rate across repeated runs, where values are computed as 0.8^k.

The fix is a schedule that runs the same task more than once and reports the distribution.

02 / Measure reliability with pass^k

pass^k is the share of tasks an agent completes on every one of k tries (tau-bench). It is the number that predicts whether the agent works for a customer on a random Tuesday, because it counts only tasks that never failed across the trials.

pass@k asks a different question: did any of the k tries succeed? At k=1 the two metrics are identical. By k=10, pass@k approaches 100% while pass^k falls to 0% (Anthropic). pass^k measures the probability that all k trials succeed, and it falls as k rises (Anthropic).

pass@k rewards retries. pass^k punishes inconsistency.

The tempting fix is a retry. A retry raises pass@k because it gives the agent another draw. It does not raise pass^k, because the metric asks whether every try succeeded. If the business needs the action to happen once, correctly, a retry hides the failure instead of fixing it.

Tau-bench's own results show the gap. gpt-4o succeeded on under 50% of tasks and was quite inconsistent, with pass^8 under 25% in retail (arXiv). Under 50% per task is already a warning. Under 25% for eight in a row is a different product.

The metric is simple to compute from a matrix of trials:

PYTHON
def pass_hat_k(trials: list[list[bool]]) -> float:
    """trials holds one list of k booleans per task."""
    return sum(all(run) for run in trials) / len(trials)

FAULTLINE ran 150 held-out hard scenarios at k=3, across 1,350 total runs, graded by a deterministic dual-condition oracle, a fixed grader that decides pass or fail from exact checks, with no model judges (research). Naive Bernoulli compounding, pass@1 to the power k, matched the empirical joint reliability within 2.5 percentage points at k=3 (research). That result matters for cost. A small k on a hard suite will tell you whether the agent is stable or lucky, so you do not need a long run per task to get a usable estimate.

One caveat belongs here. The compounding shortcut assumes trials are independent, and real agents share state across a task. FAULTLINE tests k=3 on a multi-hop workload and uses a beta-binomial model, which treats each task's success rate as drawn from a shared distribution, to extrapolate beyond that (research). Treat the shortcut as a planning estimate. If your tasks share memory, a cache, or a long conversation, measure pass^k directly at the k you care about.

03 / Check tool calls with fixed rules, not a model judge

For an agent that takes actions, the important question is what it did. A trace is the recorded sequence of model and tool calls from one run. A deterministic rule reads it and checks the call.

Did the refund tool fire? With the right order id? Before or after the identity check?

An LLM judge reads text and scores it, and its verdict carries position, verbosity and self-enhancement bias (LLM-as-a-judge). Put the better answer second and the score can move.

A useful check has three parts. It names the tool. It names the arguments that must or must not appear. And it names the order constraint that matters, such as identity verification before a refund.

Write those as assertions over the trace, not as prose instructions to a judge. Then a failure points to a line of code and a specific call.

FAULTLINE measured the gap on one check. The search_loop rule scored a Cohen kappa of 0.98 on 200 runs and 1.00 on the test split, while the same question put to two model judges, Laya and GLM-5.3, scored 0.09 and minus 0.03 (Regression or noise?). Cohen kappa is a chance-corrected agreement score, where 1.0 is perfect agreement and 0 is what you get by guessing.

A score near zero means the judge was not tracking the thing it claimed to check.

Judges also drift. A prompt change, a model upgrade, or a different provider can move scores without any change to the agent. A rule either passes or fails the same trace the same way, which is what a release gate needs.

Cost follows the same split. In the P11 drill, an API judge on thirty scenarios cost $1.84, while faultgate evaluated the identical thirty scenarios in 0.0 seconds with zero model spend (blog). Deterministic checks are also reproducible, which matters when two engineers disagree about a failed build.

Where the checks live depends on when you want them. faultgate-zero runs inside pytest with no tracing setup, collector, account, network, or LLM judge (faultgate-zero). fault-contract checks the data that was already sent and received, with nothing calling a tool, a backend, or the network (fault-contract). Both keep the check close to the code.

Cohen kappa scores comparing search_loop rule at 0.98 against Laya at 0.09 and GLM-5.3 at minus 0.03.
Cohen kappa on the search_loop check: fixed rule versus two model judges.

04 / Gate releases on noise bands, not fixed thresholds

A fixed threshold is a guess about variance. Set a pass mark and a normal bad day blocks good code, while a normal good day lets bad code through. The threshold does not know the spread.

faultgate builds the spread from your own baseline. Supply at least three baseline trace files to measure run-to-run variance and generate a tolerance band (blog). Two files work, but the tool warns that they measure noise poorly. With a band in place, a candidate is graded against the range the agent actually produced, not a number someone picked in a meeting.

The band comes from your own repeated runs. That makes it easy to explain to a reviewer and hard to move without new data.

Build it in the environment you ship to, because a laptop run and a production region can produce different spreads. Rebuild the baseline after a model upgrade, and keep the old band in the repo so you can see how far it moved.

The gate returns PASS, FAIL, or INCONCLUSIVE (faultgate). INCONCLUSIVE is the honest third answer. It means the data cannot separate the candidate from the baseline, which is different from a regression and different from a pass.

Policy sits above statistics. With a band supplied, a run whose clean rate sits inside the measured band still fails if the policy check fired on any trace (faultgate). A policy violation is a hard block. The averages do not get a vote.

The engine runs offline on Python 3.11 or newer with one dependency, pydantic (blog). That matters for CI, the automated check that runs on every commit, because there is no network call, no vendor account, and no rate limit between a commit and its verdict.

Operationally, three verdicts change how a team argues. A FAIL opens a bug with a trace. An INCONCLUSIVE opens a data question: add baseline runs or narrow the task. A PASS closes the release. None of the three asks an engineer to defend a vibe.

Threshold band showing FAIL below the baseline band and PASS or INCONCLUSIVE inside.
The baseline band comes from 3+ runs. A policy violation fails the release at any clean rate. (schematic, not to scale)

05 / Turn production failures into regression tests

Every production failure should become a test that runs on every release. The cheapest start is small. Anthropic recommends starting with 20-50 simple tasks drawn from real failures (Anthropic). LangSmith frames the same move as adding real traces to a dataset so a failure you saw once becomes a test you run every time (LangSmith). Both point at one loop: observe, record, replay.

The loop also improves the suite over time. Each incident adds a task. Each task adds a fixture. Each fixture runs on every release. After a few months the suite is a record of every way the agent has failed in production, which is more useful than a generic benchmark.

trace-to-fixture automates the middle of that loop. It scrubs private data with deterministic HMAC pseudonyms, keeps one example of each distinct behaviour, and outputs executable pytest fixtures (trace-to-fixture). HMAC is a keyed hash, so the same customer id maps to the same pseudonym across runs while the original value stays out of the fixture.

The tool is explicit about its limits. It masks the private data its detectors can find, plus entries in a deny file, and it is not an anonymisation or compliance product. It can miss things such as internal customer ids (trace-to-fixture).

Read that before you point it at production traces. Scrubbing reduces exposure. It does not certify anything.

A fixture needs three properties to stay useful. It must run offline, so CI does not depend on a vendor. It must be deterministic, so the same input gives the same verdict. And it must fail loudly, with the trace attached, so the next engineer sees the call and not just a red mark.

Keep the scrub step in the loop so private data never enters the repository. Keep the fixtures in your own repository. A test suite that lives inside a hosted product leaves when the product does.

Sequence diagram showing trace recording, HMAC scrub, pytest fixture, and CI gate.
Turning production failure traces into deterministic CI fixtures.

06 / Test the tools, not only the agent

An agent can be correct and still cause harm when a tool lies to it. A tool poisoning attack embeds malicious instructions in MCP tool descriptions, the text that tells an agent what a Model Context Protocol server can do. Users cannot see that text, and AI models read it (Invariant Labs). The agent follows the description, calls the tool, and the damage happens through a normal-looking action.

The scale is large. MCPTox was built on 45 live MCP servers and 353 authentic tools, with 1,348 malicious test cases across 10 risk categories (MCPTox). Across 20 prominent LLM agents, o1-mini reached a 72.8% attack success rate (MCPTox). The attack lives in the tool description, so a better agent prompt does not remove it.

FAULTLINE's P08 study produced a client-side provenance contract, which checks a tool call against the record of where that tool definition came from, and it cut pooled attack success on MCPTox from 30.32% to 7.41% across six models (mcp-guard). mcp-guard ships that idea as a proxy. Audit mode logs findings by default. Enforce mode blocks unknown tools, extra arguments, and changed tool definitions, and quarantines high-confidence poisoned descriptions (mcp-guard).

A proxy is the right place for the check. The agent should not have to know which tools are safe. The boundary should reject a call before it reaches the server, and log the decision either way.

The lesson for a test plan is to treat tool definitions as code. Diff them, pin them, and fail the build when one changes without review.

Tool definitions also drift in small ways. A description gains a sentence. An argument gains an optional field. A server returns a new tool name.

Most changes are harmless. Some are the exact place an attacker hides an instruction. Review a tool-definition diff the way you review a code diff: show the change, name the owner, and require a reason.

Pipeline animation showing agent tool call blocked by mcp-guard proxy before reaching MCP server.
Tool call blocked by mcp-guard when tool definition changes (schematic, not to scale).

07 / What to change on Monday

Leaders need three things from this. First, the decision: no agent release without a gate in CI. Second, the owner: the platform or ML engineering lead, the person who already owns the build. Third, the metric: pass^k at k=3 on a 20-50 task suite built from real failures, plus zero policy violations (Anthropic, research, faultgate).

Put the suite and the fixtures in your own repository. OpenAI's hosted Evals platform becomes read-only for existing users on October 31, 2026, and is scheduled to shut down on November 30, 2026 (OpenAI docs). Any evaluation that exists only in a vendor's database has an expiry date. Yours does not.

Run the gate on every pull request. Start with the checks that map to money and data: refund or payment calls, writes to customer records, and outbound messages. Add a task from each incident. Within a quarter the suite reflects your product instead of a public benchmark.

A practical rollout starts in report-only mode. Record traces, pick tasks from real failures, and run the gate beside the existing process. Once the verdicts match what engineers already believe, make policy violations block. Then make the whole gate blocking and publish the pass^k number in the release notes.

Getting started is cheap. faultgate and mcp-guard are MIT and free (services), and the docs cover install and CI wiring. faultgate-zero, trace-to-fixture and fault-contract cover the pytest, fixture and contract steps. If you want an outside check, FAULTLINE runs fixed-price audits.

The point is a release decision that depends on a measurement which repeats. A gate that returns three verdicts gives a team something to argue with. A demo gives them a story.

Questions#

What is the difference between pass@k and pass^k?

pass@k asks whether at least one of k trials succeeds. pass^k asks whether every one of k trials succeeds, so it measures consistency instead of a lucky draw. Tau-bench introduced pass^k to evaluate reliability over multiple trials. At k=1 the two are identical. By k=10, pass@k approaches 100% while pass^k falls to 0%. Use pass^k when the agent must work every time.

How many times should you run an AI agent test?

There is no published universal minimum, and anyone who names one is guessing. FAULTLINE found that simple compounding matched empirical reliability within 2.5 percentage points at k=3. Tau-bench reported pass^8 results in retail. Anthropic suggests starting with 20-50 tasks drawn from real failures. Start at k=3 on a small suite, then raise k for the checks that move money.

Can an LLM judge test an AI agent?

For open-ended writing, maybe. For tool calls, it is weak. LLM judges carry position, verbosity and self-enhancement bias. On FAULTLINE's search_loop check, a fixed rule scored a Cohen kappa of 0.98 while two model judges scored 0.09 and minus 0.03. Use deterministic rules for actions and keep a judge for tone or style.

Why does an AI agent give different answers at temperature 0?

Temperature 0 removes sampling randomness. It does not remove hardware and scheduling randomness. Thinking Machines sampled 1,000 completions at temperature 0 and got 80 unique answers. The main cause is that server load changes batch size, and batch size changes the floating-point arithmetic. That is why you test across repeated runs.

How do you test an AI agent in CI?

Record real traces, build a baseline from at least three runs to measure noise, then compare each candidate against that band. faultgate returns PASS, FAIL or INCONCLUSIVE and makes any policy violation a hard block. faultgate-zero runs the same failure checks inside pytest with no network or judge, so the gate can run on every commit.