Evaluation & Testing
AI agent regression testing: a runnable before-and-after example
Run ten failure fixtures against a broken and repaired response adapter. Preserve receipts, test healthy controls, and use explicit pass/fail release gates.
AI agent regression testing checks whether a change to a prompt, model, tool adapter or application breaks behavior that previously worked. For an agent that takes actions, the test must preserve both the response and the evidence about the action. A fluent answer and a successful HTTP request do not establish that the task completed.
This guide includes an original, dependency-free Python workbench executed on November 28, 2026. The deliberately broken adapter passes 3 of 10 synthetic cases; the repaired adapter passes 10 of 10. These are observed results from the downloadable deterministic example, not model accuracy, customer outcomes or a Sentrial-versus-competitor benchmark.
Worked example: an accepted cancellation is not a completed cancellation
A user asks to cancel order order-7. The application submits operation op-4. The service returns a receipt with state=pending, observed at second 18. The response is sent at second 20. The broken adapter treats any returned receipt as success and says “Cancellation confirmed.” The repair checks the action identity, the receipt state and what was known when the response was sent.
request = {"action": "cancel", "target_id": "order-7", "operation_id": "op-4"}
receipt = {**request, "state": "pending", "observed_at": 18}
response_at = 20
# Broken: "Cancellation confirmed."
# Repaired: "Cancellation is pending; it is not confirmed yet."
The correct behavior is not to refuse every request. A completed receipt for the matching operation must still produce a confirmation. A completed receipt for another order must not. A receipt that arrives at second 25 cannot justify a claim made at second 20, even if the action eventually succeeds.
Run the before-and-after regression workbench
Download agent-regression-workbench.py, inspect it, then run it with Python 3.9 or later. It uses only the standard library, makes no network calls and creates no real cancellations.
python3 agent-regression-workbench.py --candidate baseline
# baseline: 3/10 synthetic cases passed
# Exit status 1 is intentional: the release gate fails.
python3 agent-regression-workbench.py --candidate repaired
# repaired: 10/10 synthetic cases passed
# Exit status 0: all ten fixture expectations passed.
python3 agent-regression-workbench.py --candidate repaired --json > repaired.json
The JSON output retains each request, receipt, response time, expected status, actual response and case-level result. Keep this record with the code revision rather than saving only a dashboard average. The policy labels are fixed in the fixtures; they are not inferred from whichever candidate produced the answer.
| Fixture | Expected status | Broken adapter | Repaired adapter |
|---|---|---|---|
| Confirmed cancellation | completed | Pass | Pass |
| Pending receipt | pending | Fail: completed | Pass |
| Rejected receipt | rejected | Fail: completed | Pass |
| Wrong target / operation / action (three cases) | unverified | Fail: completed in all three | Pass in all three |
| Missing receipt | unverified | Pass | Pass |
| Receipt arrives after response | unverified | Fail: completed | Pass |
| Timeout followed by timely completed readback | completed | Pass | Pass |
| Unknown receipt state | unverified | Fail: completed | Pass |
What actually changed in the repair?
The repair requires matching action, target_id and operation_id, rejects evidence observed after the response, and maps only recognized states to response templates. Missing, mismatched or unknown evidence becomes “I cannot verify,” not an invented rejection. The workbench assumes trusted, well-formed fixture records on one clock. Production receipt authentication, conflicting events, clock skew and malformed payload validation need their own tests. The timeout/readback fixture supplies the final observed readback; it does not simulate a network timeout or retry scheduler.
This example tests a deterministic response adapter. It does not call an LLM or extract semantic claims from arbitrary prose. Its text is generated from the checked status, so the status assertion is sufficient for this small example. If a model writes the final response, add an independently reviewed assertion on its actual wording; a correct structured status does not prevent the model from making an unsupported promise.
Connect the example to a real agent test
- Freeze the tool boundary. Replace the cancellation tool with a fixture provider in an isolated environment. Keep the requested operation and target in the agent input. Never replay a write against a customer’s real order.
- Run the candidate. Execute the actual agent with its prompt, model and tool-adapter versions recorded. Save the full final response and all tool observations, including timestamps and retries.
- Assert the action outcome separately. Check the authoritative receipt. Pending remains pending even when the agent honestly describes it.
- Assert communication correctness. Review whether the response claims completed, pending, rejected or unknown work. Preserve the prose and any extracted label; test the extractor on reviewed examples.
- Repeat stochastic runs. Run each case multiple times when the model can vary. Report failures per case and per attempt, not only the best run.
- Hold out new cases. Add separately reviewed examples that were not used while editing the prompt or adapter. Ten fixed fixtures are a functionality check, not evidence of production recall.
A release gate that fails visibly
In a job that already has Python installed, use the command below. Its nonzero exit prevents an unsafe candidate from appearing green. In your application, replace the repaired demo adapter with the real sandboxed candidate and retain the same explicit assertions.
python3 agent-regression-workbench.py --candidate repaired --json > regression-results.json
Require no failures in critical cases, no missing expected cases, and preservation of the confirmed-success control. For a stochastic agent, record the attempted and assessable run counts alongside the failure count. A missing tool result must not silently remove a difficult case from the denominator. Add latency, tool-call and model-cost budgets appropriate to your application; this deterministic example does not measure those budgets.
Capture the incident before changing it
Retain the relevant input, prompt and application versions, tool arguments, returned evidence and final response. Record the action identity and the observation boundary. Minimize or replace sensitive data while preserving the facts the test depends on; note any transformation.
Write the expected behavior from authoritative evidence, not from the current evaluator’s prediction. A reviewer should be able to explain the label without trusting the model judge.
Separate reproducible replay from fresh behavior
Recorded tool fixtures make failures repeatable. A fresh model run checks how the current agent behaves against those fixtures. A live integration test checks whether actual tool and telemetry boundaries still work. Label which kind of run produced each result.
Use sandboxed side effects for write operations. A replay must not silently create another production shipment while trying to reproduce the original failure.
Optional: test the completion-claim policy separately
The runnable evidence lab is a dependency-free Python example of an evidence contract. It checks a structured completion claim against a supplied receipt with matching action, target, operation and timing. It intentionally does not read prose, call a model or certify that a receipt is authentic.
python3 agent-evidence-lab.py
# Expected final line:
# 10 synthetic cases passed; no production accuracy measured.| Case | Expected result | Bug it exposes |
|---|---|---|
| Matching completed receipt | Supported | Rejecting healthy completed work |
| Explicit rejection or pending state | Contradicted | Treating accepted or queued work as completed |
| Wrong order, action or operation | Unverified | Joining by a broad customer or session ID |
| Receipt observed after the claim | Unverified | Using hindsight to justify the original statement |
| Status readback before the claim | Supported | Treating every initial timeout as a failed business action |
Set release gates by severity and evidence
Block a candidate that introduces a known critical failure, even if the average score rises. For subjective judgments, require reviewed evidence rather than treating every score change as decisive. Track cases that became unassessable because a field disappeared; a smaller evaluated denominator can make a broken candidate appear better.
Version the fixture set, environment reset, evaluator and candidate. Run repeated trials when model variability matters, and inspect the spread rather than only the best run. Keep a separate assessment set out of the prompt-editing loop. After release, add newly reviewed failures without rewriting past results, so the historical report still explains what the release actually passed.
Continue feeding reviewed incidents into the development set, while keeping the assessment set and its permissions explicit. The prompt comparison guide covers controlled rollout, and the recovery guide helps prevent a retry from being mistaken for a repair.
Frequently asked questions
Is an LLM judge enough for regression testing?
Use deterministic checks for known IDs, receipt states and timing. Use a calibrated judge or human review when the assertion concerns meaning in free text. Keep the judge version fixed when comparing candidates; changing the judge and the agent together makes attribution difficult.
Does a green replay prove production is fixed?
No. Replay proves behavior against recorded conditions. A fresh model run and a live sandbox integration test cover different boundaries. Production monitoring must still look for new failure modes and missing capture.
To compare how tools store these results, use our LLM observability platform comparison. For the Sentrial integration path, start with the quickstart; the standalone workbench does not require a Sentrial account.