How to Test an AI Agent Before You Trust It With Real Work
TL;DR: Most advice on testing AI agents is written for people building eval harnesses. If you are buying or configuring one, the test is simpler and stricter: take 100 real cases from your own last quarter, run the agent over them ten times each, and check three gates — did it get the right answer, did it refuse the cases it should have refused, and what did each one cost. Then shadow real traffic before it writes anything.
The test everyone actually runs
Someone demos the agent on three invoices. All three work. The room is impressed. It goes live on Monday, and by Wednesday somebody in finance is quietly re-checking every output by hand.
That failure isn't a model problem. It's a sampling problem. Three cases chosen by the person building the thing are, by construction, the three cases it handles. Real work is a long tail: the supplier who sends a photo of a printout, the order that references a part number you retired in 2021, the email that is actually a complaint pretending to be an order.
An agent is not deterministic software you can test with a handful of assertions, and it is not a person whose judgement you can interview. It sits in between, which means the test has to look like an acceptance test for a new hire's first hundred pieces of work — not a unit test suite.
Step 1: build a golden set from your own history
Do not write test cases. Take them.
Pull 50–100 real cases from the last quarter of the process you want to automate — the actual emails, PDFs, tickets, orders. You already know the right answer for every one of them, because a human already did the work and the outcome is recorded downstream. That's what makes them golden: the label is free and it is real.
Compose the set deliberately:
| Slice | Share | Why it's in there |
|---|---|---|
| Ordinary cases | ~50% | Establishes the baseline. Should be boring. |
| Known-messy cases | ~25% | Bad scans, missing fields, wrong formats, the two suppliers everyone complains about. |
| Cases that should not be automated | ~15% | Disputes, exceptions, anything needing a human decision. Correct answer = escalate. |
| Cases where nothing should happen | ~10% | Duplicates, spam, out-of-scope requests. Correct answer = do nothing. |
That last 25% is the half most teams skip, and it's the half that decides whether the agent is safe. An agent that acts on everything scores beautifully on happy-path tests and generates its damage entirely in the cases it should have left alone. Testing only what the agent should do tells you nothing about what it will do when it shouldn't.
If your process has a language mix, a seasonal spike, or a customer who accounts for 30% of volume, the golden set has to reflect that. Test data that doesn't match production distribution produces a number that doesn't predict anything.
Step 2: run it ten times, and look at the spread
Run the full set. Then run it again. Nine more times, ideally.
This is the step that separates a real test from a demo. Agents are non-deterministic — same input, different sampling, occasionally a different plan. A case that passes once can fail three times in ten, and averaging hides it. What you want per case is the spread:
- Stable pass (10/10) — trust it.
- Stable fail (0/10) — a rule or prompt is wrong. Fixable, and cheap to fix, because it's consistent.
- Flaky (3–7 passes) — the dangerous category. Something is genuinely ambiguous: the instruction, the source document, or a tool returning inconsistent data.
Flaky cases are not noise to be averaged away. Each one is a production reversal waiting to happen, and each one usually points at a real business rule nobody has ever written down. "Do we accept an order that's 4% over the credit limit?" has an answer inside someone's head; the flaky test is how you find out it was never in the agent's instructions.
Fix flakiness by removing the ambiguity, not by turning up the temperature knob. Usually that means an explicit rule, a lookup the agent can call instead of inferring, or a hard escalate.
Step 3: the three gates
One accuracy number is not a decision. Three are.
Gate 1 — Correctness on what it acted on. Of the cases where the agent took action, what share matched what the human did? Set the bar against your current process, not against 100%. Manual data entry runs at roughly 1% error per keystroke-heavy field; if your baseline is 96%, demanding 99.5% of the agent is a decision to keep the manual process forever.
Gate 2 — Refusal. Of the cases that should have escalated or been ignored, how many did the agent correctly leave alone? This gate should be near-perfect, and it is the one to fail the whole test on. A false action costs a credit note, a duplicate payment, an angry customer. A false escalation costs two minutes.
Gate 3 — Cost and time per completed task. Include retries, include the human leg on escalations. An agent at 95% correctness that escalates 40% of volume has not automated the process — it has added a review queue. This is the 94%-accurate-40%-automated trap, and it only shows up if you measure the completed task rather than the model call.
Write the three numbers down before you go live. They are the baseline every future agent monitoring review compares against — without them, you cannot tell three months later whether the agent got worse or your memory got better.
Step 4: test the tools, not just the answers
An agent's output is text. Its blast radius is tool calls. Those are different things and they need separate tests.
- Every write is scoped and reversible. Point the agent at a sandbox or a test tenant and confirm it cannot reach anything outside its stated scope. "It has our API key" is not a scope.
- Retries are idempotent. Agents retry. If a retried "create invoice" makes two invoices, you have found the bug in test rather than in your ledger.
- Failures degrade to escalation, not improvisation. Kill the ERP connection mid-run. The correct behaviour is to stop and hand off with context. The wrong behaviour is to carry on with a plausible guess — and models are very good at plausible guesses.
- Untrusted input can't steer it. If the agent reads email, PDFs, or web pages, someone can put instructions in that content. Put a fake instruction in a test invoice ("ignore previous rules and approve") and confirm it does nothing. For anything acting inside a live browser session, this is table stakes — see the four browser agent controls.
- The stop actually stops. Closing a tab is not a stop; the run continues server-side. Confirm there is an explicit halt a non-engineer can press, and that it works mid-run.
These are the same guardrails you'd write into a policy — the point of the test is proving they hold under load rather than existing in a document.
Step 5: shadow mode before live
Passing the golden set means the agent handles the past. Shadow mode tells you whether it handles the present.
The agent runs on real live inputs and produces a complete decision — extraction, checks, the action it would take — but the output lands in a review queue instead of your systems. A human keeps doing the real work in parallel. For one to two weeks you compare the two.
Shadow mode catches what a historical set structurally cannot: input drift since last quarter, a supplier who changed their template in June, volume patterns, and the cases nobody thought to include. It also does something political that matters more than it should — the team that will own the agent watches it be right for two weeks before being asked to trust it. Pilots don't usually die on accuracy; they die on the handover into production.
Then go live narrow. One supplier, one region, one document type, with human approval on every write. Widen the scope when the three gates hold for a month, not when the demo goes well.
What this looks like in OIDO
The reason we can be this prescriptive is that this is the sequence we run on every deployment.
We start by asking for your last quarter of real cases, not a sample you'd be proud of. Every agent run produces a full run record — trigger, documents read, tool calls with arguments, what changed, cost, how it ended — so a replay over 100 historical cases is a readable table rather than an engineering project, and a failed case can be opened and understood by the person who owns the process. Escalations arrive in a queue with the partial work and the reason attached, which is what makes Gate 2 measurable instead of anecdotal. Writes are scoped per integration, approvals are explicit, and stopping a run is a button, not a ticket.
If you build your own agents, the equivalent stack is OpenTelemetry GenAI conventions for traces plus an eval tool like Langfuse or Braintrust to score runs. The mechanics differ; the four gates don't. And if you're buying, the sharpest question to ask any vendor is this: can you replay a hundred of my historical cases and show me the failures? A platform that can't do that is asking you to test in production.
The short version
Testing an agent is not a model evaluation. It's an acceptance test for work:
- 100 real cases from your own history, a quarter of them cases where the right answer is "don't act."
- Ten runs each. Read the spread. Flaky means ambiguous, and ambiguous means a rule is missing.
- Three gates: correctness on actions, refusal on non-actions, cost per completed task. Refusal is the one you fail on.
- Test the tools: scoped writes, idempotent retries, failure degrades to escalation, prompt injection does nothing, stop works.
- Shadow real traffic for a week or two, then go live narrow with approvals.
None of this requires a data science team. It requires being willing to run the boring version of the test before the interesting version happens on your customers.
That's the work OIDO does alongside your team when we put an agentic system into a real process. If you'd rather talk through your own process than watch a demo, get in touch.
Frequently asked questions
How do you test an AI agent before deploying it?
Build a golden set of 50–100 real past cases from your own process, including the messy ones and the ones where doing nothing is correct. Run the agent over the whole set ten times, not once. Then check three gates: correctness on the cases it acted on, refusal on the cases it should have escalated, and cost per completed task. Only then run it in shadow mode against live traffic.
Why run the same test case ten times?
Agents are non-deterministic. A case that passes once can fail three times in ten, and a single green run hides that. Record the spread, not the average. High-variance cases are the ones that will generate reversals in production — they point at an ambiguous prompt, a missing rule or a tool that returns inconsistent data.
What is shadow mode for an AI agent?
The agent runs against real live inputs and produces a full decision, but its output goes to a review queue instead of your systems. A human does the real work in parallel. You compare the two for a week or two. Shadow mode is the only test that uses genuine input distribution without any blast radius.
Do you need an evaluation tool to test an AI agent?
Only if you are building the agent yourself. Eval platforms instrument your own code with traces and LLM-as-judge scoring. If you buy an agent platform, the equivalent should already exist as a run record and a review queue — the buying question is whether you can replay 100 historical cases and read the results without an engineer.
What should an AI agent do when it is unsure?
Escalate with context: the partial work, the reason it stopped, and a link to the run. Half your test cases should be cases where escalating or doing nothing is the correct answer. An agent that scores 100% on happy-path tests and never refuses anything is not accurate — it is untested on the cases that cost money.