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:
- A valid dispute, where the agent should open one dispute.
- A duplicate charge, where it should dispute the second charge only.
- 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

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:
- 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.
- 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.
- 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.
- 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. - 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 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

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 change | 10 runs, fail at 5 or fewer | 50 runs, fail at 34 or fewer |
|---|---|---|
| 80% (no change) | fails about 3 times in 100 | fails about 3 times in 100 |
| 70% | fails about 15 times in 100 | fails about 43 times in 100 |
| 50% | fails about 6 times in 10 | almost 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

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

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:
- 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.
- 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.
- It runs the agent, reads the request log and the unmatched requests, and saves them with the run’s result.
- 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

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:
| Case | Pass rate on main (last 100 runs) | This pull request | Result |
|---|---|---|---|
| Valid dispute | 92% | 9 of 10 | Pass |
| Duplicate charge | 80% | 4 of 10 | Fail |
| Before the dispute window | 96% | 10 of 10 | Pass |
| Outcomes that must never happen | none in 30 runs | Pass |
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
- How to test AI agents covers the wider testing setup this CI check fits into, including why to check what the agent did against the request log.
- Beyond happy paths shows how to test an agent against API timeouts, rate limits and errors, which are good cases to add to the suite.
- Stateful API simulation for AI agents explains how to make the simulated API keep what the agent creates, which the checks in this post rely on.
- WireMock’s API templates are a starting point for the simulated APIs your agent calls.
- To see how this would work with your own agent and APIs, request a demo of WireMock Cloud.