Back to blog
9 min readBy VIBPS

How to test an AI agent harness before shipping it

Test the software around the model: write observable invariants, script tool and provider replies, inject failures, and reserve live checks for behavior mocks cannot prove.

AI agentsTestingDeveloper guide

An agent can produce a convincing answer while the software around it mishandles a tool call, retries an action twice or forgets what happened after a crash. Those failures belong to the harness: the code that sends requests to a model, interprets replies, runs tools, applies permissions, stores state and shows a person what happened. Testing that layer means checking the transitions and side effects, not only whether the final paragraph sounds right.

A November 2026 paper, Anatomy of an Agent Harness: Decisions, Invariants and Corner Cases, offers a useful starting point. Its author organizes harness decisions into testable invariants and failure cases. The paper is a design study and one builder’s self-assessment, not an independent benchmark or a ranking. The practical method below uses its questions as prompts, then separates what a deterministic test can establish from what requires a real provider, sandbox or user interface.

Draw the boundary before writing tests

List the parts your application owns. A typical harness has a turn loop, one or more provider adapters, tool dispatch, permission checks, conversation or task state, recovery logic and a user-facing status display. The model and remote services are outside that boundary. A small command-line agent may not have a window, background host or approval screen; skip those rows instead of copying a checklist for a larger product.

For each boundary, write a statement that can be observed. For example: every tool call the harness starts eventually has exactly one recorded outcome; a retry cannot repeat a payment; after Stop is accepted, no new tool begins; a resumed task uses the same saved task ID; and an approval does not authorize a different command. An invariant should describe your application’s promise, not imply that every agent needs the same design choice.

Use a short inventory with four columns: event, expected state change, visible result and protected side effect. That last column matters. If a retry should not send a second message, assert the number of messages in the test account or fake outbox; matching the final assistant text alone cannot establish that.

Start with the turn and tool-call contract

Make a scripted model or provider return a fixed sequence. Send a request that asks for a tool, give the harness a known tool result, and then return a final answer. Assert the request contained the expected conversation and tool definitions, the tool ran once with validated arguments, its result was attached to the right call, and the next model turn received that result. Also assert that the script consumed every expected step. An extra request or an unused response should fail the test rather than pass silently.

Then test awkward but ordinary protocol cases: two tool calls finishing out of order, a repeated or blank call ID, an empty tool result, a result too large to display, a partial streamed response, and a reply that ends without a normal completion marker. Decide what your product should record and show in each case. A call that never started should not look successful, and one call should not acquire another call’s result just because it finished first.

Inject failure paths on purpose

A success-only mock leaves the most important branches untouched. Script a timeout, a dropped connection, a rate limit with a reset time, an overload response, a malformed payload and a provider refusal. Use a fake clock for backoff and deadlines so tests finish quickly and do not sleep for real minutes. For every retry, specify whether the request is safe to replay and check the cap on attempts and elapsed time.

Include side effects in the scenario. Imagine the provider times out after a tool has created a record but before the harness receives its reply. On retry, does an idempotency key prevent a duplicate? If a person presses Stop while an approval prompt is open, does the prompt close and does the pending command stay unrun? If a worker crashes between saving progress and sending a message, can it resume without either losing the task or sending twice? These are application-specific contracts; model answers cannot settle them.

Test permission and untrusted-input boundaries

Treat model replies, tool output, fetched pages, project files and extension configuration as data, not as permission. Test an allowed action, a denied action, a missing approval, a changed action after approval and an action that tries to use a different resource than the one checked. Keep these tests in an isolated project with fake accounts and data. A UI that hides a button is not evidence that the server or execution layer enforces the boundary.

For a tool runner, check that the command the policy evaluates is the command the shell executes. For a web-enabled agent, plant an instruction in a test page and verify that the harness does not interpret page text as a user approval. For a multi-tenant app, use two test identities and assert that one cannot read or alter the other’s records through a direct tool call. Do not run these probes against a real user’s content.

Separate deterministic checks from integration evidence

Use a scripted provider for the behavior your own turn loop and tool routing should control. It makes retries, ordering and rare errors repeatable. It does not test the provider’s wire format, authentication, live latency, model judgment or the real sandbox’s isolation. Test those at their actual boundary with a controlled transport or isolated integration environment, and keep credentials and private conversation bodies out of logs and saved fixtures.

A good test ladder has three levels. Unit and scripted tests cover every listed transition and failure row. Integration tests exercise the real adapter, storage and sandbox where the boundary matters. A small number of observed end-to-end runs check that the assembled product still works with the intended model and interface. Label the evidence precisely: ‘scripted retry path passed’ is stronger and more honest than ‘the agent is safe’ or ‘all providers work.’

OpenAI’s Agents SDK, for example, documents deterministic scripted model tests for workflows and recommends using the real provider adapter with a controlled network transport when testing provider serialization. That is one SDK’s boundary design, not a requirement to adopt its library. The general lesson is to replace only the part outside the test’s question, so the test still exercises the orchestration you mean to verify.

Protect regressions while changing the harness

Before a risky refactor, record a small set of observable cases: normalized requests, tool events, state changes, user-visible messages and exit status. Re-run the same cases after the change. A recording can preserve a bug as easily as a behavior, so pair it with explicit assertions and include scenarios the previous design handled poorly. When several provider formats are supported, run the relevant cases through each adapter instead of assuming the busiest one represents them all.

Keep one ordinary task in the test set beside the adversarial and fault cases. A permission fix can block legitimate work; a retry guard can stop a second request that should have succeeded. Check both the unsafe path and the normal path the same change might break. When you switch model families, revisit workarounds such as forced retries or prompt nudges and measure whether they still help before removing or retaining them.

Turn failures into a reviewable test list

A compact harness test plan can start with these prompts:

  • Turn lifecycle: does every run end once, with a reason and a truthful final status?
  • Tool protocol: are calls matched to results by ID, validated and completed exactly once?
  • Failures: are timeout, retry, rate-limit and cancellation paths bounded and visible?
  • State: can a crash or duplicate delivery resume without losing or repeating a side effect?
  • Permissions: does approval apply only to the exact action and data that were reviewed?
  • Display: do streaming, errors and tool outcomes remain understandable and in order?
  • Evidence: which checks are scripted, which use real adapters, and which were observed in the product?

The arXiv paper behind this guide illustrates why evidence labels matter: its 30 decision cards include 83 invariant clauses, but the author reports a single-harness self-assessment and explicitly limits what its scripted tests establish. Treat its checklist as a source of questions, then adapt and verify each promise against your own architecture. It does not certify other harnesses or prove that one set of choices is best.

When you ship an app that includes an agent, make its failure behavior part of the product experience: a user should know when work is waiting, stopped, retried or finished. A public app page can explain what the tool does and how people can try it, but it cannot substitute for these checks. VIBPS is the social network for software, where makers can introduce an app and give people a way to find and follow what they build next.

Source: Joshi, Anatomy of an Agent Harness: Decisions, Invariants and Corner Cases (arXiv:2611.19960, submitted Nov. 15, 2026)

Source: OpenAI Agents SDK for Python: Testing

How to design an always-on AI agent across runs

How to test an AI-built app before inviting users

How to protect your app when using an AI coding agent

Introduce your app on VIBPS

Built around one question: what happens when software becomes easy for almost anyone to create?

Explore apps