"Retries, timeouts and idempotency: the plumbing that keeps agents alive at 3am"
Your agent demo worked. Production is where it waits out a ten-minute default timeout, double-sends an email after a retry, and hammers a provider that is already down. The distributed-systems basics, timeout budgets, backoff with jitter, idempotency keys, circuit breakers, dead-letter queues, apply doubly to LLM systems.

Your agent worked in the demo. It will die in production, at 3am, and the failure will not be the model being stupid, it will be a hung worker, a double-sent email, or a fleet of retries hammering a provider that is already down. If you lead a team shipping LLM systems, the risks that should keep you up at night are not prompt quality. They are the distributed-systems basics that have bitten every integration since the first flaky HTTP call, and they bite harder here, because the model is a slow, expensive, flaky dependency that can also trigger side effects in the real world.
Start with timeouts, because the defaults are not on your side. The official OpenAI and Anthropic SDKs both time requests out after ten minutes, and both automatically retry transient failures twice. Those defaults suit a batch job and ruin anything interactive: a worker that looks hung may simply be waiting out ten minutes, up to three times over. Set an explicit timeout on every call, sized to its realistic latency, seconds for most, not minutes, and a separate budget for the whole task. An agent making eight calls, each inside its per-call limit, can still take four minutes end to end; the task budget is what protects the user, and each step should check what remains before starting.
When a call fails inside its budget, most failures are transient: a 429 rate limit, a 500, a connection reset. Retry them, but properly, with exponential backoff and jitter, not a tight loop of instant attempts. Backoff gives a struggling provider room to recover; jitter stops a fleet of workers retrying in lockstep and turning one blip into a stampede. AWS published the numbers a decade ago: under contention, full jitter finishes far sooner, with far fewer total calls, than backoff alone (https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/). Cap the attempts, respect Retry-After headers, and retry in one layer only: if your SDK, framework and queue each retry three times, one failure becomes twenty-seven attempts. Non-transient failures, invalid request, auth error, content refusal, are things to handle, not retry.

Here is the distinction between LLM systems that merely fail and ones that fail expensively: retrying the model call is cheap and safe, but retrying the action the model requested is dangerous. Regenerating a draft costs a few pence. Re-executing "send this email" or "create this invoice" touches the world, and the world does not deduplicate for you. Agents blur this line constantly, because a task interleaves model calls and tool calls, and a naive retry-the-whole-task policy replays both.
The fix is idempotency keys on every side-effecting tool call. Before executing, derive a stable key, task ID plus step, or a hash of the operation and its inputs, and record it. When a retry replays the step, the executor sees the key, finds the action already done, and returns the recorded result instead of repeating it. Stripe popularised this pattern for payments: send the same key twice within 24 hours and you get back the stored response of the first attempt, not a second charge. Your agent's tool layer needs the same guarantee. It is not exotic, a unique constraint in Postgres is enough, but it has to sit in the execution path, not in a code review comment.
An anonymised example from an LLM automation I run: it reads incoming customer emails, drafts a reply, and sends it. One night the send succeeded but the confirmation timed out on the way back, so the orchestrator marked the task failed and retried it. Without idempotency, the replay drafts and sends again, and the customer gets two slightly different replies to the same message, a glitch at best, at worst a company that does not have its act together. With an idempotency key on the send, derived from the inbound message ID, the retry hits the key, recognises the email already went out, and completes without a second delivery. The timeout still happened; it just stopped mattering.
Retries assume the provider will recover shortly. Sometimes it will not, a model API can be degraded for an hour, and a hundred workers dutifully backing off is still a hundred workers burning budget against a dead endpoint. A circuit breaker handles this: after enough consecutive failures, stop calling entirely for a cooling-off period, park incoming work, and probe occasionally until the provider is healthy again. The system degrades gracefully, tasks queue up and drain later, instead of turning an upstream incident into your incident.
And when a task genuinely cannot complete, budget exhausted, retries spent, breaker open too long, it must not vanish. Every queue needs a dead-letter queue: failed tasks land there with full context, someone is alerted, and there is a path to inspect and replay them. In an LLM system a silently dropped task is a customer who never got a reply and no record that they were owed one, worse than any loud error, because nobody knows to fix it.
None of this is glamorous, and none of it shows up in a demo. That is the point, demos prove the happy path exists; this plumbing is what holds when the provider is down and nobody is watching. It is the difference between an agent pilot that quietly gets switched off and one that earns the right to run unattended.
Making LLM automations and agents survive production is exactly the work I do. If you have an agent that works in the demo and you need it to work at 3am, get in touch via the contact form.
Senior engineering roles — or production AI consulting?
I'm open to senior AI and software engineering roles and to selective consulting on agents, RAG, and LLM automation in production. If this post resonates — as a hiring manager or as someone shipping similar work — get in touch.
Get in touch