Skip to content

Agents and tool calls · 3 of 6

Retried tool, refunded twice

Step 1 · The pattern

The agent issues a refund through a tool

A support agent decides a customer gets a refund. The step runs through a run engine that executes the tool on a worker, which calls payments. One decision, one refund. (All numbers are illustrative.)

  • a refund step
  • refunded once

In short

Retried tool, refunded twice: how it works and how it breaks

Agents that act, issuing refunds, sending emails, opening tickets, run their tool calls through something that retries: an SDK, a queue, or a durable execution engine that keeps long runs alive across crashes. Temporal's documentation states the trade-off: an activity is observed as completed exactly once, but may be executed multiple times. A worker that issues a refund and crashes before reporting it is retried, so the refund runs again. Reads do not care; refunds, emails and orders do. The model cannot fix this, because the retry happens below it. Give every side-effecting tool call an idempotency key built from the run ID and step ID, stable across retries and unique to that step, and have the service being called enforce it, returning the first result instead of acting again. It is the same pattern as payment idempotency keys.

What this simulation simplifies

  • Crashes happen at a fixed rate after the refund; real crashes can happen at any point.
  • The engine retries once; real engines retry with backoff until a limit.

How this comes up in interviews

"An agent can issue refunds. How do you make sure each refund happens exactly once?"

Then they ask

  1. What retries the tool call?
  2. Where is the key checked?
  3. What goes in the key?

A strong answer covers

  • Retry layers (SDK, queue, durable engine) run steps at least once.
  • A worker can act and crash before reporting; the retry acts again.
  • Idempotency key from run ID + step ID, stable across retries.
  • The payments service enforces it and returns the first result.
  • Classify tools as read-only or side-effecting.

Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.

On one page: the track cheat sheet.

Last reviewed: Official documentation

Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.