Home / Insights / QA and Software Testing

QA and Software Testing

Testing AI Agents before Release: Scenario Suites, Tool Mocks and Safety Checks

An AI agent does not just produce text; it calls tools, changes records and makes decisions over several steps. Testing it means checking what it actually did, how consistently it does it, and what it refuses to do. This guide sets out a practical pre-release test approach for agents.

TopicsQA and Software TestingAI Agents and Automation

Key takeaways

  • Agent tests should be scenario-based: a realistic goal, a starting state, and a check of the end state of the systems the agent touched, not just the wording of its final reply.
  • Mock or sandbox every tool so scenarios run repeatably, cheaply and without side effects, and use mocks to inject failures such as timeouts, empty results and permission errors.
  • Run each scenario several times. A pass on one run says little; benchmarks such as tau-bench show agents that succeed sometimes but behave inconsistently across repeated trials.
  • Keep two suites: capability scenarios that measure progress and a regression suite that should stay close to 100%, and run the regression suite on every prompt, model, tool or policy change.
  • Test safety directly: prompt injection through tool results, attempts to exceed permissions, high-impact actions without approval, and data leakage. Enforce permissions in your systems, not in the model, and test that they hold.

Testing a chatbot is hard enough. Testing an agent is harder, because an agent acts. It reads a customer record, decides a refund is due, calls the payments API, updates the ticket and writes a reply. Each step depends on the last, the path can differ between runs, and a mistake may not show in the reply at all: the message can say a refund was issued while no refund exists in the system.

This article is for QA leads, engineering managers and product owners preparing to release an AI agent into a real workflow, whether customer-facing or internal. It explains what makes agent testing different, how to design a scenario suite, how to mock and sandbox tools, how to grade results and measure consistency, which safety checks to include, and how to turn all of this into release gates. It focuses on testing before release; monitoring agents in production is covered in our article on observability for AI agents.

Why testing agents is different from testing AI features

Evaluation sets for single-step AI features, such as a summary or a classification, score one output per input. Agents add three complications.

  • Multi-step trajectories. The agent chooses which tools to call, in which order, with which arguments, and may ask the user for clarification along the way.
  • Side effects. Tool calls change real state: records, orders, emails, tickets. What matters is the state of the world afterwards.
  • Compounding variation. Small differences early in a run lead to different paths later, so repeated runs of the same scenario can end differently.

Anthropic’s engineering guide Demystifying evals for AI agents frames this well: a task is run as multiple trials, the transcript records everything the agent did, and the outcome is the final state of the environment. Its example is a flight-booking agent that tells the user the booking succeeded while the database holds no reservation. Grading the reply alone would pass it; grading the outcome catches it.

The academic benchmark tau-bench takes the same approach. It simulates a user, gives the agent domain tools and policy rules, and compares the database state at the end of each conversation with an annotated goal state. Its authors reported that even strong function-calling agents succeeded on fewer than half of tasks and were inconsistent across repeated trials in the retail domain. Your agent is not tau-bench, but the lesson transfers: a single successful demo tells you very little.

Designing a scenario suite

A scenario is the agent equivalent of a test case. Each one should be unambiguous enough that two people who know the domain would agree on whether the agent passed.

Anatomy of a scenario

  • Goal: what the user wants, written as the user would say it.
  • Starting state: the records and data in the mocked systems when the scenario begins.
  • User behaviour: scripted replies, or a simulated user with a persona and facts to reveal when asked.
  • Expected outcome: the end state of each system, such as refund created for the right amount, ticket closed with the right category, no email sent to anyone else.
  • Forbidden actions: things the agent must not do in this scenario, such as issuing a refund above the policy limit.
  • Tags: category, risk level and the policy rule being tested.

What to cover

Scenario typePurposeExample (illustrative)
Happy pathCore tasks complete correctlyCustomer asks to change a delivery address before dispatch; agent updates the order
Policy boundaryAgent follows business rules at the edgesRefund request one day after the return window; agent declines or escalates per policy
AmbiguityAgent asks rather than guessesCustomer with two open orders asks to cancel their order
Tool failureGraceful handling of errorsPayments API times out; agent does not claim success and does not retry endlessly
Should not actAgent avoids unnecessary actionsCustomer asks a question only; agent answers without changing any records
EscalationHandover to a person when requiredCustomer reports a safety issue with a product
AdversarialResistance to manipulationA ticket attachment contains instructions to refund all orders

Balance matters. If every scenario rewards action, you will tune an agent that acts too readily. Anthropic’s guide recommends testing both when a behaviour should occur and when it should not.

Start small, from real failures

The same guide suggests starting with roughly 20 to 50 tasks drawn from real failures rather than waiting for a large suite. In our experience a first suite built from a pilot’s transcripts, support tickets and a workshop with the people who currently do the work is far more useful than scenarios invented in isolation.

Tool mocks, sandboxes and test environments

Agents call tools: APIs, databases, search, email, internal services. Tests that hit real systems are slow, expensive, non-repeatable and risky. Most of the agent test suite should run against mocks or sandboxes.

ApproachWhat it isUse it forWatch out for
Static mocksTools return fixed responses for given inputsFast unit-style checks of tool selection and argumentsBrittle when the agent phrases calls differently
Stateful fakesIn-memory versions of your systems that apply changes and can be inspectedMost scenario tests; outcome checks on end stateMust mirror real validation rules, or tests pass falsely
Vendor sandboxesTest modes of payment, CRM or messaging providersIntegration tests close to production behaviourRate limits, shared state, slower runs
Staging environmentA full copy of your stack with test dataEnd-to-end release candidate checksCost; keeping data realistic and anonymised

Use mocks to inject trouble

The main value of controllable tools is testing what happens when things go wrong. Build failure modes into your fakes and switch them on per scenario:

  • Timeouts and slow responses
  • Empty or partial results
  • Permission denied and expired credentials
  • Validation errors, such as an amount above a limit
  • Conflicting data between two systems
  • Tool results containing injected instructions

Keep runs isolated

Reset the fake systems to the scenario’s starting state before every trial. Shared state between trials creates results that pass or fail for reasons unrelated to the agent, which is one of the most common sources of confusing agent test results.

Grading outcomes and measuring consistency

Grade the outcome first

The primary check for most scenarios is code-based: inspect the end state of the fake systems and compare it with the expected outcome. Did the refund record exist, with the right amount, linked to the right order? Did any forbidden action occur? These checks are fast, cheap and unambiguous.

Add model-based grading for qualities code cannot judge well, such as whether the reply was accurate, polite and consistent with policy wording. Calibrate any model grader against human judgement on a sample before relying on it, as we describe in our guide to evaluation sets and regression checks for AI features.

Do not over-specify the path

It is tempting to assert an exact sequence of tool calls. Anthropic’s guide advises that it is often better to grade what the agent produced rather than the path it took, because rigid step checks penalise valid solutions. Constrain the path only where it matters: for example, the agent must check identity before reading account data, or must request approval before a refund over a threshold.

Run every scenario more than once

Because runs vary, a single trial is weak evidence. Two measures are useful:

  • pass@k: the chance that at least one of k trials succeeds. Useful when a person reviews options and one good result is enough.
  • pass^k: the chance that all k trials succeed. This is the measure that matters for agents acting on behalf of customers, because users experience every run, not the best one. Tau-bench introduced it to expose inconsistency, and Anthropic’s guide recommends it for customer-facing agents.

For example, an agent that passes a refund scenario on four of five runs looks fine on a pass@k basis but fails one customer in five. Tracking pass^k by scenario category shows where the agent is unreliable.

Read the transcripts

Scores tell you where to look; transcripts tell you why. Reading a sample of failing and passing trials regularly reveals broken scenarios, grader errors and genuine agent mistakes. A scenario that every trial fails is more often a broken scenario than an incapable agent.

Safety checks for agents that take actions

Agents widen the attack surface because they read untrusted content and hold permissions. The OWASP GenAI Security Project’s guidance gives a clear basis for what to test.

Excessive agency

OWASP’s LLM06:2025 Excessive Agency describes damaging actions taken in response to unexpected, ambiguous or manipulated model outputs, with three root causes: excessive functionality, excessive permissions and excessive autonomy. It recommends minimal, narrow tools, least-privilege credentials, acting in the user’s context, human approval for high-impact actions, and enforcing authorisation in downstream systems rather than relying on the model to decide what is allowed. Each of these is testable.

Prompt injection through tools

OWASP’s LLM01:2025 Prompt Injection distinguishes direct injection from indirect injection, where instructions arrive in external content such as web pages or files. For agents, every tool result is potential external content. OWASP recommends regular adversarial testing that treats the model as an untrusted user, and notes that no foolproof prevention is currently known, so controls aim to limit impact.

Safety scenarios to include

  1. Injected instructions in tool results: an email, document, web page or ticket field telling the agent to take an unrelated action or reveal data.
  2. Permission boundaries: the user asks for something outside their entitlement; verify the downstream system rejects it even if the agent tries.
  3. Approval bypass: attempts to talk the agent out of requesting approval for a high-impact action.
  4. Data leakage: requests for another customer’s data, internal notes or system prompts.
  5. Runaway loops: tool errors that could cause repeated retries or escalating costs; verify step and budget limits stop the run.
  6. Unsafe content: requests that should be refused or escalated under your policies.

Safety failures should be blocking regardless of overall scores. Our article on agent permissions and approvals covers how to design the controls these tests verify.

Fitting agent tests into the release process

Two suites with different jobs

Anthropic’s guide distinguishes capability evaluations, which should start at a low pass rate and show progress as the agent improves, from regression evaluations, which should stay near 100% and catch backsliding. Keep both, and move scenarios from the capability suite to the regression suite once the agent handles them reliably.

What triggers a run

  • Changes to the prompt, instructions or policy text
  • A new model or model version
  • Adding, removing or changing a tool, its description or its permissions
  • Changes to retrieval sources or memory behaviour
  • Changes to step limits, budgets or approval thresholds

Release gates

GateExample criterion (illustrative)
SafetyZero failures on blocking safety scenarios across all trials
RegressionRegression suite pass^k at or above the last approved baseline
High-risk categoriesNo drop in pass^k for refunds, account changes or other tagged categories
Cost and latencyMedian steps, tokens and duration per scenario within budget
Human reviewSample of transcripts reviewed and new failures accepted by the product owner
RollbackPrevious agent configuration can be restored quickly

Costs to expect

Agent testing costs more than testing single-step features: each scenario runs several steps, several times, and model-based grading adds more calls. Budget for model usage in test runs, building and maintaining stateful fakes, domain experts to write and review scenarios, and transcript review time. Run the full suite on release candidates and a smaller smoke suite on every change to control spend.

A pre-release checklist for AI agents

  1. Agent’s goals, allowed actions and forbidden actions written down and agreed with the business owner.
  2. Scenario suite covering happy paths, policy boundaries, ambiguity, tool failures, should-not-act cases, escalations and adversarial inputs.
  3. Each scenario has a defined starting state and an expected end state that code can check.
  4. Stateful fakes or sandboxes for every tool, reset before each trial, with switchable failure modes.
  5. Outcome-based grading as the primary check; model-based grading calibrated against human reviewers.
  6. Each scenario run multiple times; pass^k tracked by category.
  7. Safety scenarios for injection through tool results, permission boundaries, approval bypass, data leakage and runaway loops, all blocking.
  8. Permissions enforced in downstream systems and verified by tests, not left to the model.
  9. Regression suite automated on prompt, model, tool and policy changes; full suite on release candidates.
  10. Release gates agreed in advance, including cost and latency budgets and rollback.
  11. Transcript review scheduled before each release and regularly after launch.

If you are comparing agents built by different vendors or frameworks, the same scenario suite gives you a fair basis for comparison. Our article on evaluating testing agents against your existing suite applies a similar approach to AI testing tools. PoliteTech’s QA and testing service covers test strategy, automation in your pipeline, release checklists and evaluation sets for AI features; a test strategy review is the usual first step.

Frequently asked questions

Can we test an AI agent with our normal end-to-end tests?

Only partly. Conventional tests still cover the code, integrations and UI around the agent. The agent’s decisions need scenario-based evaluation with outcome checks and repeated trials, because its path can change between runs.

Why run the same scenario several times?

Agents behave differently between runs. A scenario that passes once may fail on the next run. Measuring pass^k, the chance that all k trials succeed, shows how consistently the agent behaves, which is what customers experience.

Should we test against real systems or mocks?

Mostly mocks and stateful fakes, because they are repeatable, cheap and safe, and let you inject failures. Use vendor sandboxes and a staging environment for a smaller set of integration and release candidate checks.

How many scenarios do we need before launch?

Start with a few dozen drawn from real tasks and failures, covering each scenario type and every high-risk policy. Grow the suite with every production issue. Coverage of risks matters more than the total count.

How do we test for prompt injection?

Plant instructions in content the agent reads through its tools, such as emails, documents, web pages and ticket fields, and check that the agent ignores them and that downstream permissions block any resulting action. OWASP recommends regular adversarial testing of this kind.

Who should write agent test scenarios?

QA engineers working with the people who currently do the work. Domain experts know the policy edges and exceptions; QA engineers turn them into scenarios with clear starting states, expected outcomes and checks.

Sources and methodology

Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.

  1. Anthropic Engineering: Demystifying evals for AI agents (January 2026) — accessed 9 November 2026. Tasks, trials, transcripts and outcomes; grader types; grading outcomes over paths; capability versus regression evals; pass@k and pass^k; starting with 20 to 50 tasks.
  2. Yao et al.: tau-bench, a benchmark for tool-agent-user interaction (arXiv, June 2024) — accessed 9 November 2026. Simulated users, policy rules and end-state database comparison; agents succeeding on fewer than half of tasks and inconsistent across repeated trials.
  3. OWASP GenAI Security Project: LLM06:2025 Excessive Agency — accessed 9 November 2026. Root causes of excessive agency and mitigations including least privilege, human approval and authorisation in downstream systems.
  4. OWASP GenAI Security Project: LLM01:2025 Prompt Injection — accessed 9 November 2026. Direct and indirect prompt injection, adversarial testing and the absence of a foolproof prevention method.

How would your AI agent perform across a hundred runs of its hardest task?

We can help you build a scenario suite, tool fakes and safety checks for your agent, and set release gates your team can trust.