AI agent reliability · interactive lab
Why a retried agent tool call can apply the same action twice
A timeout does not prove that an action failed. Here an agent asks a tool to issue a credit. The tool commits, the response is lost, and the caller retries. Compare a naive runner with one that gives the authorized intention a stable idempotency key.
Naive retry
Stable idempotency key
The pattern
key = "credit:customer-42:incident-7" # one authorized intention, one key
prev = ledger.get(key)
if prev:
if prev.payload != payload: reject() # never mint a new key for a conflicting retry
return prev.receipt # replay: nothing applied again
apply_effect_and_store_receipt(key, payload) # same local transaction
Boundary: a local ledger does not give exactly-once behavior across a remote provider and another database. Remote writes need provider-side idempotency, lookup or reconciliation when the outcome is uncertain. This is a deterministic demonstration with synthetic data, not a measurement of production traffic.
Go deeper
Full write-up: Why Retries Create Duplicate Agent Actions.
Free Python incident lab with source and regression tests (SQLite ledger, python lab.py demo): AI Agent Reliability Engineering lab.
Books by the author
Harness Engineering for AI Coding Agents: build reliable Claude Code, Codex and Python agent workflows with guardrails, tests, CI gates and production controls.
Pydantic AI in Production: building robust LLM agents for enterprise.
By Leandro Calado Ferreira · leandrocaladoferreira.com