The Research Report
Agent Tool Idempotency: Surviving At-Least-Once Retries
date: 2026-11-08
title: "Agent Tool Idempotency: Surviving At-Least-Once Retries"
author: Brian Taylor
Agent Tool Idempotency: Surviving At-Least-Once Retries
Why retries multiply in agents
An agent tool call can be retried from more places than a normal client sees: the provider SDK, the tool wrapper, the runtime, and the model itself when context is truncated or it is not confident the action landed. Those retries often fire after the underlying write already succeeded, because a timeout cannot distinguish "never arrived" from "arrived, then lost response". At the network layer the two look identical.
Classify before deciding
Treat failures by class, not by status code alone:
- Authorization (401, expired connected account): no retry; get a fresh link.
- Rate limit (429, Google
rateLimitExceeded): retry with backoff and per-user budgets. - Transient (5xx, timeout): retry only if the call is safe to repeat; otherwise check whether it landed first. For writes, this is where idempotency matters.
- Partial write (HTTP 200 with an error in the body, e.g. Slack
ok:false): no blind retry; read and repair. - Permanent (400, missing scope, 404): fix input or scope, then tell the user.
Only two classes are retryable, and one has a condition.
Keys must come from intent
A key generated per attempt changes on every retry, so it never catches the duplicate. Derive it from the operation: the candidate plus the slot, the email thread plus step, or record plus fields. Put enforcement in the tool wrapper, not in the prompt; the model cannot see the network and cannot manage idempotency.
When the downstream API supports keys natively (Google Calendar accepts a client-chosen event ID of 5–1,024 chars and returns 409 Conflict twice; Google notes collision detection is not guaranteed), use that as the guard but also keep your own ledger. For services without native support, build Redis-backed key→result lookup plus a short-lived processing lock (SET NX).
Durable execution is not enough
Engines that journal steps protect only work inside their boundary. A side effect to an external API degrades to at-least-once delivery, so the outbound call still needs its own idempotency key. Layering model, SDK, runtime, and engine retries without boundary idempotency is a self-inflicted outage.
Test the ambiguous case
For every write tool, test three cases before ship:
- Success followed by lost response: retry; effect fires once.
- Error before the server: retry; the real run fires once.
- Concurrent duplicate calls: one wins, the other gets the cached result.
Emit an event when a retry is deduplicated and alert on spikes; that signal can reveal network flakiness or model re-planning loops before users complain.
Relevance to this workspace
Brian's pipelines already retry across mail (Gmail/IMAP) and Google Drive sync; applying a stable, intent-derived key at the outer tool boundary (rather than on the LLM call) is the piece that keeps cron retries from producing duplicate archives or duplicate files. The same key should be carried through Gmail send, Drive upload, and any downstream side effects so each logical action remains exactly-once even as multiple retry loops layer up.
Sources
- https://www.scalekit.com/blog/rate-limiting-ai-agent-tool-calls
- https://tianpan.co/blog/2026/07/05/the-idempotency-key-your-agent-forgot-to-send
- https://developers.google.com/workspace/calendar/api/v3/reference/events/insert