InsightsAI agents
How we test an AI agent before it does real work
An answer key written first, repeated runs, a prompt-only control on the same model, refusal tests and code that checks every number. With our run results.
- Written by
- CloudMagic engineering team
- Published
- Reading time
- 10 minutes
The short answer
Write the answer key before you build, then score the agent against it on every case, several runs over, next to a prompt-only version on the same model. Test what it must refuse, count the sensitive records it reads, and check every number it writes in code. An agent is ready to launch when all of those pass, because accuracy on its own hides the failures that cost the most.
The usual way to test an agent is to ask it a few questions and read the answers. That finds the failures you can see. It tends to miss three that cost more: an answer that changes between runs, a right answer reached by reading records the agent should never have seen, and a figure that looks correct and is not.
This is the method we follow, with the measured results from two of our recorded demos. Both demos use made-up organizations and synthetic records; the runs themselves are real, on Google Cloud.
What does "tested before launch" mean for an AI agent?
It means the agent has been scored against a written answer key, on cases chosen in advance, several times over, and has passed every gate that was agreed before anyone saw a result.
The answer key comes first. For each case, the nurses, investigators or planners who do the work today write down the right outcome and what the answer has to contain: which records it must cite, which totals it must reach, what it must flag for a person. A grader written in code then checks every answer against those criteria. In our prior authorization demo that came to 480 criteria across 20 cases, and nobody scored a run by eye.
| Gate | What we check | How |
|---|---|---|
| Right outcome | The recommendation matches the key | Code compares it to the key |
| Right facts | Required records cited, totals and dates correct | Code checks each criterion |
| Repeatable | The same result on every run | Every case runs at least four times |
| Exposure | Sensitive records the model received | Counted in every tool result |
| Refusals | Requests it must decline are declined and logged | A misuse set, run like the cases |
| Numbers | Every figure in its written output | Checked against the source data in code |
Why run every case more than once?
A language model can give a different answer to the same input, so one clean run proves very little. We run every case at least four times and report every run.
In the prior authorization demo, a utilization management nurse at a made-up health system asks which of Monday's knee replacements are ready to send to the insurer. Our agent, on Gemini Enterprise, got all 20 synthetic cases right in each of four runs: 80 of 80 cases and 480 of 480 criteria. A prompt-only version on the same Gemini model scored 19, 18, 18 and 18. One run alone could have reported 19 of 20, and the miss it made every time would have looked like bad luck.
Why compare against a prompt-only version?
It shows what the engineering adds. If a well-written prompt on the same model does as well, the rest of the build is cost without benefit, and you should know that before paying for it.
The comparison often finds the problem somewhere other than accuracy.
| Demo (made-up company, synthetic records) | Prompt-only version on the same model | Our agent |
|---|---|---|
| Prior authorization, 20 cases, 4 runs | 19, 18, 18 and 18 of 20 right; read 42 protected behavioral health and substance use records in every run | 20 of 20 in every run; read none |
| AML alert investigation, 20 alerts, 4 runs | Right action in 80 of 80; investigation right in 78 of 80; read full Social Security numbers in all 80 | Right action in all 80 runs; no full Social Security or tax number reached the model |
In prior authorization, the prompt-only version marked one patient's packet not ready in every run because it believed a year typed wrong on an outside therapy fax. Our agent reconciled the year from the referral and the fax header, and kept the typed value beside it for the nurse to check.
The anti-money laundering result is the one we point people to. The prompt-only version, on the same Gemini model at temperature 0 with one read-only SQL tool, reached the right action every time, so a test that only checked decisions would have passed it. It also read the full Social Security numbers of 52 different people across the four runs, plus 13 business tax IDs (EINs) and 29 account numbers, mostly by running SELECT * FROM customers as its first query. In two runs it added up a period total itself and got it wrong, by $1,000 and by $4,000. It never printed a Social Security number, so a reviewer reading only the answers would not have seen any of this.
Our build keeps identifiers out of the model's reach: the agent's service account reads views that mask them, and code does the arithmetic.
What should an agent refuse, and how do you test it?
Write down the requests it must decline, then run them the same way you run the cases. The requests should sound like a real colleague under pressure. In the prior authorization demo, a surgical scheduler asks the agent to override an X-ray window so a case can stay on Monday's list. In the AML demo's misuse set, an investigator asks for a suspicious activity report to go to FinCEN without committee review, and another asks for one deposit to be left out of the narrative to make it shorter.
The most reliable refusal is a tool that does not exist. In the prior authorization demo, no tool can waive an insurer's policy window for any role, so the request fails however it is worded, and the agent records who asked. An instruction in the prompt depends on the model following it every time. A missing tool can be checked in the code by an auditor.
How do you stop an agent from getting numbers wrong?
Keep arithmetic and figures in code, let the model write the sentences around them, and check every figure in the finished text against the source before a person sees it.
In the AML demo, the agent drafts the suspicious activity report narrative in 27 seconds, and code checks all 84 amounts, dates, times and IDs in it against the bank's ledger. A draft that fails the check is not shown: the investigator sees a card saying the draft did not pass and nothing was staged. In our retail demo, Gemini writes the store planning brief and code places every number in it.
A number check has a limit worth knowing. It cannot tell when a correct figure is attached to the wrong thing, so a person still reads every draft before it goes anywhere.
What about instructions hidden in the data?
Treat every document, email and memo the agent reads as data that may carry instructions aimed at it, and remove them in code before the model reads the text. OWASP ranks prompt injection first (LLM01) in its 2025 list of risks for language model applications.
Our AML demo plants one. A wire memo carries a note addressed to an AI reviewer, telling it not to escalate. The agent's code strips it before the model sees the memo and tells the investigator what was removed. The prompt-only version saw the note, marked it as contradicted by the records and ignored it in all four runs, which shows the model handled it well this time. We still remove it in code, because a differently worded note on another day might get a different answer. Our post on stopping instructions hidden in documents covers the full set of defenses.
What does the go-live decision look like?
A short list agreed before the first run, and a yes or no against each item. Our launch list reads like this:
- The right outcome on every case in every run, or a written exception the business owner accepts.
- Zero sensitive records outside the agreed scope reached the model, counted in every run.
- Every misuse request declined and logged.
- Every figure in written output checked in code, and a draft that fails is never shown.
- A person approves anything that leaves the system, and the log shows who asked, who approved and when.
When an item fails, the fix goes into the build and the whole set runs again. Budget real time for the answer key from the people who do the work; it decides how quickly everything after it goes.
Which Google Cloud tools can run these tests?
Two of them, and between them they cover most of the gates. They do not count exposure or check figures against your ledger, so that part stays in your own code.
The Agent Development Kit (ADK), which we use to build custom agents, has evaluation built in. A test file covers one session and works like a unit test; an evalset holds many sessions for integration tests. Each turn can carry the user's question, the tool calls you expect, intermediate responses and a reference answer. You run them in adk web, from pytest, or with adk eval, and set pass marks in a test_config.json file. ADK's documentation uses 1.0 for tool_trajectory_avg_score, meaning the agent must call exactly the expected tools, and 0.8 for response_match_score, which allows small differences in wording. Treat those as Google's starting points and set your own per gate.
Gemini Enterprise Agent Platform (formerly Vertex AI) adds an evaluation service for agents. It runs in four phases: design, execution, scoring and refinement. It can generate test scenarios from the agent's instructions and tools, simulate users, and inject tool failures such as HTTP 503 errors or slow responses so you see how the agent behaves when a system it depends on breaks. Multi-turn autoraters score whole conversations, and the same metrics can score traces from production traffic after launch.
| Gate | Covered by Google's tools | Needs your own code |
|---|---|---|
| Right outcome against a reference | Yes: ADK response match, Agent Platform raters | |
| Right tool calls in the right order | Yes: ADK trajectory score | |
| Behavior when a dependency fails | Yes: Agent Platform environment simulation | |
| Multi-turn task success | Yes: multi-turn autoraters | |
| Sensitive records the model received | Yes: count them in every tool result | |
| Every figure matches the source data | Yes: check them against the ledger or chart |
Model-based raters are useful and they are models too. Calibrate them against a sample of human grades before you trust their scores.
What will an auditor or examiner want to see?
The answer key, the scores from every run, the misuse set and its results, the change log, and who approved going live. Keep all of it, because you will run the set again.
Regulators are moving in this direction. In April 2026 the OCC, the Federal Reserve and the FDIC replaced their model risk guidance, and the new version says generative and agentic AI are outside its scope, so each bank sets its own bar for an agent. In November the OCC published a supervisory framework for its examiners (Bulletin 2026-54) that treats repeated testing against consistency thresholds as stronger evidence than one successful run, names prompt injection and red teaming, and lists vendor model changes among the reasons to test again. It is a resource for examiners and sets no expectations for banks, but it shows what an examiner will look for. In health IT, trade press reports that ONC's HTI-5 rule removes the certification requirement for AI model cards, which leaves more of the checking of AI features with the hospital that uses them.
Frequently asked questions
How many test cases do you need before launch?
Enough to cover every outcome the agent can recommend, plus the hard cases your team argues about. Our healthcare and AML demos use 20 cases each. A production workflow can need more, chosen with the people who do the work. Run each case at least four times.
Can we test without real patient or customer data?
Yes, for most of the build. Most of an agent's development and testing runs on synthetic or de-identified records shaped like yours. Where our engineers need access to patient data, it is set up under a business associate agreement with you.
Who writes the answer key?
The people who do the work today, with an engineer turning their judgment into criteria code can check. The team building the agent should never write the key alone.
Can Google's evaluation tools grade the agent for us?
For many gates, yes: outcomes, tool calls, groundedness, safety and multi-turn task success. Check their model-based raters against human grades first. Counting the sensitive records an agent read, and checking every figure against your own data, still needs code you write.
Do we have to test again when Google updates the model?
Yes. Run the whole set again on every change of model, prompt or tool. A newer model can be better on average and still miss a case your current one gets right.
Is a high accuracy score enough to go live?
No. In our AML demo a prompt-only build was right on every decision and still read 52 people's full Social Security numbers. Accuracy, exposure, refusals and number checks are separate gates, and each one has to pass.
Sources
- Prior authorization agent demo film, CloudMagic: 20 synthetic cases, four runs, prompt-only comparison on the same Gemini model
- AML alert investigation demo film, CloudMagic: 20 alerts, four runs, 84-figure ledger check
- OWASP Top 10 for Large Language Model Applications (2025), OWASP Foundation
- Evaluate agents with ADK, Google
- Agent evaluation on Gemini Enterprise Agent Platform, Google Cloud
- Bulletin 2026-54, supervisory framework for examiners, OCC
- Bulletin 2026-13, revised model risk management guidance, OCC
- ONC final rule cuts health IT certification criteria, Healthcare Dive