Stateful API Simulation as the Benchmark Substrate for Agent Decision Quality
Agent benchmarks need simulations that remember earlier calls.

To use an API for agent evals, run the agent against a stateful simulation that preserves changes across tool calls, enforces resource lifecycles, and resets to known starting conditions between runs. Keep checking that simulation against the real API, while keeping evaluation runs separate from production. Stateful API simulation is a necessary foundation for benchmarks that claim to measure sequential agent decision quality.
Why sequential, world-altering tool calls break every evaluation built on stateless responses
An agent can produce coherent text at every turn and still break a payment flow. It may send a malformed parameter, choose the wrong endpoint, or misread the response from step two before proceeding to step three. Each response can look right when scored on its own. The failure lies between those responses, where one decision changes the conditions under which the next decision must work.
That gap is a measurement error. A response-level score evaluates an output, while an agent benchmark must evaluate tool integration, state-dependent planning, and the cumulative effects of successive calls. These are different objects of measurement. If the environment cannot reflect the consequences of earlier decisions, the benchmark cannot establish whether later decisions were valid.
Most agent benchmarks still score outputs one turn at a time, so their pass/fail signal misses the decisions that make the workflow succeed or fail. A well-formed call is only one part of correctness. The same call may be valid before a resource changes state and invalid afterward, so its quality cannot be judged independently of the history that produced it.
What stateless mocks actually test, and where that boundary runs out
Stateless mocks serve a legitimate and useful purpose. They isolate a function from a network dependency by mapping a request shape to a predefined response. That makes them suitable for unblocking frontend work, checking URLs and headers, or testing how a handler processes a known response shape. None of those tasks requires the mock to remember a previous request.
The boundary becomes visible when a test creates a customer with POST and then retrieves that customer with GET. A stateless mock returns the response configured for the GET route. Consistent fixtures can make the sequence appear correct. But the test has demonstrated only consistency in its configuration.
A mock can also return a configured error, but that does not establish that the error follows from the resource’s current state. IDs do not genuinely chain, lifecycle rules do not govern subsequent calls, and state changes do not trigger webhooks. Spec-derived mocks depend on the accuracy of the OpenAPI document, while handwritten mocks depend on their authors’ assumptions. Neither automatically signals when those assumptions become stale.
The three things an evaluation substrate must do that only state makes possible
Cumulative side-effect tracking connects a decision to its consequences. A resource created in step one must exist when retrieved in step three, and a deletion must remove it from later list results. Likewise, a balance must decrement after a charge. Without that continuity, the benchmark cannot tell whether an action worked or was just described in a way that sounds right. A frozen list response, for example, conceals whether a deletion changed anything.
Enforced state-transition logic sets the rules for which actions are valid after each change. A payment that has been captured cannot be re-captured, a subscription that has been cancelled cannot be invoiced, and a closed issue stays closed until it is explicitly reopened. These constraints make history part of correctness. If a configured response returns success for an invalid transition, the benchmark credits a decision that the real service would reject.
Deterministic reset makes comparisons between runs meaningful. Each agent must start from known conditions, with nothing left over from a previous evaluation. Otherwise, a missing resource or altered balance can change the score without any change in agent quality. Reset therefore serves as both cleanup and part of the measurement contract. It also makes repeated training rollouts possible.
Redocly’s sandbox requirements draw the corresponding distinction from the API-provider side. A mock server verifies HTTP contracts, while a true sandbox validates stateful business logic. Agent decision benchmarks need the latter because their subject is not simply whether a request has the right shape, but whether it is valid in the world that preceding requests have created.
How the RL training case makes the substrate requirement even stricter
Reinforcement learning with verifiable rewards turns the evaluation environment into a source of training signal. The substrate must handle thousands of rollouts and give consistent feedback on which decisions succeed. An error now influences learning as well as reporting. If the verifier accepts behavior that the real API rejects, training rewards the agent for satisfying the wrong environment.
Reproducibility must therefore hold across parallel rollouts as well as successive runs. A simulator can support horizontal scaling across thousands of containers, with isolated state in each instance. At that scale, vendor sandboxes that runs share and test-mode environments have to deal with rate limits, shared state, and account-level quotas. Resetting one shared environment cannot provide the independence required by thousands of concurrent trajectories.
Measurement sensitivity makes this requirement more consequential. There Is No Neutral Harness finds that leaderboard rank-one positions flip across valid harness configurations. That result shows why the environment cannot be treated as a neutral wrapper around the agent. Inconsistent resets or drift can change what training appears to reward.
The same fidelity requirement applies throughout training. A simulator that matched the API at launch may no longer match it three months later after upstream changes. Continuous comparison with current production behavior is therefore necessary to keep the reward signal aligned with the service the agent will eventually use. Otherwise, apparent progress can represent increasing specialization to an inaccurate simulator.
Fault injection as a first-class benchmark dimension, not an edge-case afterthought
Some of the most consequential agent failures begin with a response that raises no exception. A schema-valid payload can contain a semantically incorrect status, leaving the agent to decide whether the content supports its next action. A check of the HTTP status alone misses that test. The substrate must deliberately expose these faults if the benchmark is to measure whether the agent interprets responses.
Latency, packet loss, and connection drops show how a system handles transport disruption. They do not, by themselves, test reasoning about incorrect message content. Wrong status fields, truncated payloads, and malformed tool_call content require faults inside the tool interaction.
A 429 with a Retry-After header tests backoff logic, while a 503 during a multi-step flow tests partial-failure recovery. State gives those failures their context. When the agent decides what to do next, the environment must still show the changes made by earlier successful calls.
A benchmark limited to happy-path responses leaves resilience unmeasured, including whether the agent recognizes contradictory content or responds correctly when only part of a sequence succeeds. Fault injection belongs in the benchmark’s design because these are decision problems.
The fidelity problem: why a simulator that isn't continuously verified against the live API will silently mislead
The strongest objection to stateful simulation is its maintenance cost and potential for false confidence. A simulator can keep state perfectly while getting the lifecycle wrong. That replaces a misleading response fixture with a misleading model of the service. The extra sophistication does not make it trustworthy, and lifecycle mismatches can be harder to diagnose than incorrect response shapes.
Schema and lifecycle fidelity form the first boundary. The simulator must return the same field names, enforce the same state transitions, and fire webhooks on the same events as the real API. Automated checks that keep comparing the simulator with the live service can verify those properties. Checking before every release, as well as at launch, helps catch drift across this wider range of behavior.
Vendor-specific decline behavior, undocumented rate-limit semantics, and proprietary internal rules are not established merely because a simulator follows a schema and maintains state. A schema-driven simulator validates the integration pattern. For those edge cases, teams should use vendor test mode for the final check.
Redocly’s requirements treat the sandbox as a production-grade product, with automated contract testing before every promotion. That approach keeps documentation, sandbox behavior, and production aligned rather than allowing each to become a separate account of the API. The distinction is operationally important.
How do you test an AI agent against realistic API responses without hitting production?
A practical substrate can be assessed through a four-step test that follows the resource lifecycle across runs. The first step is to begin an isolated evaluation from a known seed state containing realistic records. The records must have enough shape and variety to exercise retrieval, filtering, and pagination rather than leave the agent facing an empty environment. Each run needs its own state. Otherwise, realistic data still produces unreliable comparisons when another run can change it.
The second step is to create a resource, retrieve it using the ID returned by the creation call, and verify that the retrieved resource is the one just created. List endpoints must also reflect the new state.
The third step is to change the resource’s state and observe the consequences across the integration contract. A captured payment must stay captured, and a closed issue must stay closed until an explicit reopen call. Invalid transitions must not succeed simply because the endpoint exists. Where asynchronous events belong to the API contract, state changes must also fire webhooks. Without those events, the evaluation covers only the synchronous portion of the workflow.
The fourth step is to reset the environment and repeat from the original seed. Changes from the earlier run must not persist into the next one or appear in another isolated run. Reset must be a first-class operation. This completes the check that the substrate can support comparable evaluations rather than a sequence of tests dependent on their execution history.
These properties make offline and CI-native operation practical. Evaluation runs can use realistic API behavior without live credentials, production side effects, or calls to the real service. The simulator still needs a separate check against the live API before releases. Keeping that verification distinct from individual evaluations allows the benchmark to run in containerized CI and at RL training scale without inheriting live-service quotas.
Why teams building agent evals and RL environments should treat the substrate as infrastructure, not scaffolding
The substrate determines what an agent is rewarded for getting right. If it misrepresents resource lifecycles, omits consequences, or changes starting conditions between runs, optimization targets those defects as well as the intended task. Deployment exposes the difference. A higher score against a flawed environment is not evidence of better decisions against the real API.
For teams building evaluations and RL environments, the lesson is to maintain and version the substrate as production infrastructure. Its fidelity, reset behavior, and fault-injection capabilities define the shared standard against which progress is compared. Benchmarks saturate, reward hacking appears, and graders drift, so environments need continued refreshment to remain training-relevant.
That investment also has to support the scale at which the environment will be used. Thousands of parallel rollouts require horizontal execution with no shared state between instances. Building stateful, verified, resettable, and scalable evaluation infrastructure early gives teams a basis for improving agent quality over time. Without it, changes in the score remain entangled with changes in the measurement itself.
Sources
- Gecko: A Simulation Environment with Stateful Feedback for Refining Agent Tool Calls
- Beyond Perfect APIs: A Comprehensive Evaluation of LLM Agents Under Real-World API Complexity
- APIFlow-Bench: Measuring Whether Agents Survive Long, Dependent API Workflows
- Beyond Executable Models: The Pufibara Agent Harness and the Modelica Agent Workflow Benchmark for Physical System Modeling
- Environment-free Synthetic Data Generation for API-Calling Agents
- Simulate to Generalize: Scaling Stateful Supervision for API-calling Agents using LLM World Models


