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 →
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
- 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. - Check-then-act: before
create_ticket, search for an existing ticket for this run or issue. - Naturally idempotent design:
set_status(order, "shipped")instead ofincrement_counter;upsertinstead ofinsert. - Action ledger: record each side effect with its result in the agent state. On resume, skip completed actions.
- 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."
Related
You understood something today that you didn't yesterday.