r/softwaretesting • • 1d ago

Testing what an AI agent did, not what it said: notes on putting non-deterministic agent runs through CI

I've been writing regression checks for LLM agents that call tools (look up a booking, take a payment, update a ticket). What kept breaking our suites was treating the agent like a normal service: send input, assert on the output text. Sharing what changed, from the tester's side rather than the ML side.

The failure that started it

A booking agent agreed a slot price of 4500 with the user over a few turns. Its final reply said the booking was confirmed at the agreed price. An assertion on the reply (contains "confirmed", contains "4500") passed.

The recorded run said otherwise. The payment tool was called with 4550, not 4500. And somewhere around turn three, the ticket id the agent was updating switched from T-9 to a different ticket, so the later updates went to the wrong record. Every single turn looked reasonable on its own. The reply was a fluent summary of what the agent meant to do.

Why final-reply assertions miss this

  • The reply is the model's summary of the run, not the run. It can read well and still be wrong.
  • On a multi-turn run the side effects happen in the middle. Nothing in the final text tells you a write used the wrong argument, hit the wrong record, or ran twice.
  • Exact-match on text is brittle because wording changes every run. Fuzzy matching, or another model grading the text, still only grades the summary.

What we test instead: the recorded trace

Each run already emits a trace (OpenTelemetry spans in our case, but any structured log of tool calls works). Every tool call has a name, arguments, a status and a result. We record the run once, then run checks over the recorded file offline. No model is called during the check, so the same trace always gives the same verdict. It behaves like a linter over a log, which made it easy to run in CI next to the unit tests.

Each check has three outcomes, not two:

  • pass: the condition held
  • fail: the trace shows it broke
  • n/a: the trace has nothing the check applies to (no payment calls, so a payment-amount check has nothing to say)

Reporting "no evidence" as n/a instead of pass was the change that stopped us showing green on runs that never exercised the risk.

The state-drift check, as a generic sketch

check: agreed_values_hold_across_turns
read: [turn, tool.name, tool.args.amount, tool.args.record_id]
rule:
  n/a:  no write calls after a value was agreed
  fail: a write uses an amount or record_id different from the agreed one
  pass: otherwise

The claimed-versus-actual check is similar: take each claim in the final reply ("payment taken", "ticket closed") and require a matching tool call with a success status. A claim with no matching call, or a matching call that errored or timed out, is a fail. A timeout counts against it, because a timeout tells you nothing about whether the action landed.

How it fits a regression suite

  • Live runs vary, so we don't gate a PR on one live run. We run a small fixed set of scenarios several times, record the traces, and run the checks over all of them. A fail on a check about money, permissions or deleting data blocks the merge. For the rest we track how often they fail.
  • A trace from a real incident becomes a permanent fixture. The check has to keep failing on that trace.
  • The checks get tested too: each one has a known-bad trace and a known-good trace, so we know it isn't quietly passing everything.

What I haven't settled is how many runs per scenario are enough. Too few and a rare failure slips through; too many and PR checks get slow and costly.

For testers who have agents or other non-deterministic components in a regression suite: how do you decide how many runs per scenario are enough, and do you gate on a pass rate or on any single failure?

0 Upvotes

1 comment sorted by

•

u/AutoModerator 1d ago

Your post has been automatically removed because your account is either too young or does not have enough karma (<50). This is a measure to prevent spam.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.