Be idempotent and predictable where it matters
Sé idempotente y predecible donde importa
The same call should produce the same result, and retries must be safe, so agents can recover without causing duplicate side effects.
Why
Agents retry. Unlike humans who notice a double-charge and call support, agents will silently retry a failed write and create a duplicate record or trigger a duplicate transaction. Speakeasy's Predictability principle asks that agents behave consistently every time, whether an action is asked once or a hundred times. On the server side, Stripe's idempotency keys make retries safe: the client sends a unique key per intent, Stripe's v1 API saves the status code and body of the first request for that key, and later requests with the same key get the same result, even a 500. MCP lets a tool declare the same property with idempotentHint: repeated calls with the same arguments have no additional effect. This is especially critical in fintech and e-commerce where non-idempotent retries directly cause financial harm.
A key alone does not tell the agent what happened. UndoBench (arxiv 2610.05622) dropped the acknowledgment of a write and compared ways of recovering: naive retry produced duplicate external effects in 53.33 percent of trials. Where the write had committed and only the acknowledgment was lost, verification and server-side idempotency substantially improved safety. Where the fault hit a workflow partway through its writes, per-call idempotency collapsed on the workflows tested. Pair the key with a read, so the agent can check whether a write committed before it decides to retry.
Do
Use idempotency keys on writes, and give every write a read the agent can use to check whether it committed before it retries.
Don't
Create a new resource on every identical retry.
Artifact
Send an Idempotency-Key on writes so the same key returns the same result (safe retries). See the refund example in AX-SYS-13.
Citations
- [01]Speakeasy: Designing Agent Experience(opens in a new tab)
Predictability: users need to trust that agents will behave consistently every time; an action should succeed whether it is asked once or a hundred times
- [02]Stripe: Idempotent Requests(opens in a new tab)
For API v1, Stripe saves the status code and body of the first request made with a given idempotency key after endpoint execution begins, and retries with the same key return the saved response, including 500 errors; keys can be removed automatically after they are at least 24 hours old
- [03]MCP Specification 2025-11-25: Schema (ToolAnnotations)(opens in a new tab)
idempotentHint: if true, calling the tool repeatedly with the same arguments will have no additional effect on its environment
- [04]Sah et al.: UndoBench: Separating Task Competence from Recovery Capability in Tool-Using AI Agents (arxiv 2610.05622, v1, 2026-10-04)(opens in a new tab)
On 12 held-out TEST workflows across two open-weight models, two frameworks, and three recovery paradigms (5,760 executions / 2,880 paired trials) in the frozen lost-acknowledgment study, nominal competence reached 83.54% while conditional recovery success rate (CRSR) fell to 46.72%, with naive retry producing duplicate external effects in 53.33% of trials.
- [05]Sah et al.: UndoBench (arxiv 2610.05622, v1, 2026-10-04)(opens in a new tab)
Evaluations across complementary execution boundaries show that recovery is phase-dependent: before mutation, methods perform similarly without duplicate effects among capable trials; during partial mutation, naive retry, per-call idempotency, and zero-privilege journaling collapse on the evaluated composite workflows; after commit but before acknowledgment, verification and server-side idempotency substantially improve safety.