Dashboard
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
51 small wins to finish your pathNext question →

Q32IntermediateConcept

What is idempotency, and why does it matter for agent tools?

30-second answerSay your answer out loud first, then reveal.

Where duplicates come from in agents

  • Code-level retry after a timeout, when the first call actually succeeded.
  • Resuming from a checkpoint taken before the tool result was saved.
  • The model itself calling the same action twice ("let me send it again to be sure").

Techniques

  1. Idempotency keys: generate a unique key per intended action (e.g. run_id + step_id). The downstream API (Stripe-style) or your wrapper stores it and returns the original result if the key is seen again.
  2. Check-then-act: before create_ticket, search for an existing ticket for this run or issue.
  3. Naturally idempotent design: set_status(order, "shipped") instead of increment_counter; upsert instead of insert.
  4. Action ledger: record each side effect with its result in the agent state. On resume, skip completed actions.
  5. Two-phase actions: prepare/draft (safe, repeatable) → commit (once, often approval-gated).
Interview line. "In agent systems, at-least-once execution is the default, so I design every write tool to be safe under retries."

You understood something today that you didn't yesterday.