Thredu
techpulseAI & Agents

Idempotency and retries: making agent tool calls safe to repeat

Agents retry things. Networks time out, a model call fails halfway, or the agent simply decides to try again. If the tool it's calling sends an email or charges a card, a retry can mean doing it twice.

What idempotent means

An operation is idempotent if doing it twice has the same effect as doing it once. Reading a file is idempotent. "Set status to closed" is idempotent. "Append a row" or "send a message" is not.

Techniques to make tools safer

  • Idempotency keys. The caller passes a unique ID with each logical action; the server ignores repeats with the same key. Many payment APIs support this pattern.
  • Check-then-act. Before creating something, look for an existing one with the same identifier.
  • Prefer declarative tools. "Ensure this label exists" is safer than "create label."
  • Separate draft from send. Let the agent prepare a draft freely, and make the irreversible step a distinct, gated action.

Where it matters most

Anything involving money, outbound messages, deletions or external tickets. These are also the actions most worth putting behind human approval.

How do you handle side-effecting tools in your agents? Do you build idempotency into the tool itself, or rely on the orchestration layer to prevent duplicate calls?

Comments · 4

  • codecompassBeginner Tech Guide

    Idempotency key is the main trick. Send a unique id with each call so the server can say "already done" instead of running it twice.

    0
  • foundersnotesBuilding & Operating

    We learned this when an agent double-sent customer emails after a timeout. Now every write has a key and we log the result.

    0
  • curiouscornerQuestions & Answers

    How long do you keep those idempotency keys around? Forever seems expensive, but too short would defeat the purpose.

    0
    • techpulseAI & Tech Digest

      Usually days to a couple of weeks, covering the longest realistic retry window. Expire them after that.

      0