ai-development

Regression testing an AI agent in CI: did this pull request make it worse?

Eran Levy Growth @ WireMock
December 3, 2026
Regression testing an AI agent in CI: did this pull request make it worse?

This post is about regression testing an AI agent in CI: checking each pull request that changes the agent’s prompt, tools or model before it merges. An agent handles the same test case correctly in some runs and not in others, so the question for a pull request is whether it made the agent get a case right less often.

To answer this question, the CI job runs each test case many times against a simulated API in WireMock Cloud. Each job gets its own copy of the API, set back to the same starting data before every run, and a record of every request the agent sent, which is what each run is judged on.

We’ll follow one example through the post, a card-dispute agent. When a customer asks about a charge, the agent looks up the transaction through the card provider’s API and opens a dispute if the charge qualifies. Its tests have three cases:

  1. A valid dispute, where the agent should open one dispute.
  2. A duplicate charge, where it should dispute the second charge only.
  3. A charge from before the dispute window, where it should open no dispute.

The numbers in this post are illustrative, not from a real run.

The approach in brief

A pull request starts a CI job that runs each test case several times against a simulated API in WireMock Cloud; the build fails if a pass rate is clearly lower than on main or if any run does something that must never happen

Our post on API failures showed that one passing run tells you little about an agent. The approach in this post builds on that. For each pull request that changes the agent, the CI job runs this loop:

  1. It creates a simulated card API in WireMock Cloud for this job alone, from an API template or a copy of the team’s own simulated API, if it has already built one.
  2. For each run of each test case, it resets the simulated API, loads the case’s starting transactions, runs the agent, and saves the simulated API’s log of the requests the agent sent.
  3. It scores each run from that log, not from what the agent says it did: whether the agent handled the case correctly, and whether it did anything that must never happen, such as opening two disputes for one charge.
  4. It compares how many runs of each case passed with the case’s pass rate on main, which comes from many earlier runs, and reports the result on the pull request.
  5. It deletes the simulated API.

The build fails if a case passes clearly less often than on main, or if any run did something that must never happen.

The loop measures the agent only if nothing else changes from run to run, which is why each job gets its own simulated API, set back to the same starting data before every run. The next sections go through each part: where the pass rate on main comes from, how many runs it takes to see a drop, the outcomes that must never happen, and the simulated API.

What a case’s pass rate is, and how to measure it on main

Each merge to main adds runs; CI keeps the results of the last 100 runs of each case, which give the pass rate on main

Each test case has a pass rate: the share of runs in which the agent handles that case correctly. A pass rate only describes the version of the agent it was measured on, so any change to the prompt, the tools or the model can raise or lower it. The pass rate on main is the reference point, because it describes the agent the team has already accepted. A pull request is judged by whether it lowers that rate for any case.

Measuring the rate on main takes many runs. A handful of runs can give a figure that’s well off the real rate, and every pull request is judged against this number, so it needs a long record of runs.

The easiest way to build up that record is to keep the results of runs that CI does anyway. If the suite also runs on every merge to main and the job keeps each run’s result between jobs, the last 100 runs per case give a rate you can rely on. If the setup changes, for example new test cases or a change to the simulated card API the agent calls during the tests (we’ll get to that later), the older runs measured something different, so the count starts again from the runs after the change.

For the rest of this post, we’ll assume those runs show the duplicate-charge case passing 80% of the time on main. That figure is only an example. A real case might sit at 95% or at 60%, and the thresholds in the next section are worked out from whatever its rate is.

How many runs it takes to see a drop

More runs per case catch smaller drops in a pass rate but cost more in model calls

Failing the build whenever any run fails doesn’t work for an agent. One that handles a case correctly 80% of the time passes 10 runs in a row only about 1 time in 10, so nearly every pull request would fail.

The simplest comparison is a threshold. Say the duplicate-charge case passes 80% of the time on main, and the pull request fails if the case scores 5 or fewer out of 10. An unchanged agent scores that low about 3 times in 100. The weakness is how often the threshold misses a real drop:

The case’s pass rate after the change10 runs, fail at 5 or fewer50 runs, fail at 34 or fewer
80% (no change)fails about 3 times in 100fails about 3 times in 100
70%fails about 15 times in 100fails about 43 times in 100
50%fails about 6 times in 10almost always fails

With 10 runs, a drop from 80% to 75% passes 92 times in 100, and even a drop to 50% passes 4 times in 10. Fifty runs catch the drop to 50% almost every time and the drop to 70% a bit under half the time. The number of runs sets how small a drop you can see, so it’s worth choosing it from the smallest drop you’d want to block. Each case’s threshold is worked out the same way from its own pass rate on main.

False failures add up across cases. With three cases, each failing an unchanged agent about 3 times in 100, roughly 1 pull request in 10 fails with no real change. When a case fails, it’s reasonable to add runs and judge it on all of them together.

Retrying a failed run until it passes is different from adding runs, and it hides the drops the test is there to find. An agent that gets a case right only half the time passes within three attempts 7 times in 8.

Runs also cost money. At 10 cents of model calls per run, 10 runs for each of the three cases come to about $3 per pull request, and 50 runs each to about $15. One way to split it is 10 runs per case on every push, and 50 per case before merging a change to the model.

Some outcomes must never happen, on any run

After each run, the job reads the simulated API's request log in WireMock Cloud; two disputes for one charge, or a dispute on a charge nobody asked about, fails the build

Some outcomes are never acceptable, even if they occur rarely. For the card-dispute agent, we’d put two outcomes in this group: opening more than one dispute for the same charge, and opening a dispute on a charge the customer never asked about. In these cases, a single occurrence should fail the pull request - so every run is checked for them, including runs where the case passed.

To find these outcomes after each run, the job reads the simulated API’s request log in WireMock Cloud rather than the agent’s reply to the customer, and counts the requests that create a dispute and the transaction in each one.

Two more checks we can apply:

  • With OpenAPI validation set to hard, a malformed dispute request gets an error response and is logged. New simulated APIs default to soft, so the job changes the setting.
  • The list of unmatched requests shows calls the simulated API has no answer for, which means the agent did something the tests don’t cover yet.

Isolating the agent: a fresh simulated API for every job

The job creates a simulated API in WireMock Cloud, then for each run resets it, loads the starting data, runs the agent and reads what the simulated API recorded; at the end it reports on the pull request and deletes the simulated API

A pass rate measures the agent only if every run sees the same API: the same transactions and no disputes left from the run before.

This is where a simulated API in WireMock Cloud comes in. Each step of the loop is a call to WireMock Cloud’s API, made with an API token kept as a CI secret:

  1. The job creates a simulated API from one of the API templates, or copies the team’s own by exporting and importing its stubs, and sets OpenAPI validation to hard.
  2. Before each run, it resets the stored state, clears the request log, and loads the case’s starting transactions with a request to the simulated API (see our post on stateful simulation). The valid-dispute case gets one recent charge, the duplicate case two identical charges, and the third case one charge dated before the window.
  3. It runs the agent, reads the request log and the unmatched requests, and saves them with the run’s result.
  4. When all runs are done, it deletes the simulated API.

A reset covers the whole simulated API, so the runs in one job go one after another. The simulated API also takes away the real card API’s cost and side effects. The model calls cost the same as before.

What a pull request gets back

When a case fails, the reviewer opens the saved request logs of its failed runs to see what the agent sent to the API

For a pull request that rewords the prompt’s instructions on duplicate charges, with 10 runs per case, the job’s report might look something like this:

CasePass rate on main (last 100 runs)This pull requestResult
Valid dispute92%9 of 10Pass
Duplicate charge80%4 of 10Fail
Before the dispute window96%10 of 10Pass
Outcomes that must never happennone in 30 runsPass

An agent still at 80% on the duplicate case would score 4 or fewer out of 10 less than 1 time in 100, so this pull request most likely made that case worse. The saved request logs of the six failed runs show what the agent sent to the card API in each of them, which is where the reviewer starts.

The two things in this design you should agree on beforehand are the list of outcomes that must never happen and the smallest drop each case should catch. Together they decide which pull requests merge.

Next steps

Have More Questions?

Explore the docs or get in touch with our team.