New Tool Radar

AI Agents & Automation

How to Check That an Agent Tool Is Idempotent So Retries Are Safe

Verify that calling a tool twice has the same effect as calling it once, so a retry after a timeout never double-charges a customer.

Schematic illustration with three step boxes: list the write tools, call each twice, and check for duplicates.

Idempotent task design survives mid-run crashes: if a tool call times out, the agent does not know whether it ran, and the safe move is to retry it. That is only safe when the tool is idempotent, meaning a second identical call has the same effect as the first. A refund tool that charges twice on a retry is not idempotent, and a retry after a timeout will double-charge the customer.

Before you start

A test environment with your agent’s write tools, and a way to call each tool twice with the same arguments.

List the write tools

Write down every tool that changes something: refunds, sends, deletes, creates, updates. Read-only tools need no idempotency check: calling them twice changes nothing.

For each write tool, note what a duplicate would do: a second refund, a second email, a second order. The worst duplicate sets the priority.

Call each tool twice with the same arguments

In the test environment, call each write tool twice with identical arguments and the same idempotency key, if the tool supports one. Record the effect of the second call: nothing new, a duplicate, or an error.

Test the timeout case too: call the tool, simulate a timeout by dropping the response, then retry the same call and check the result.

Fix the tools that duplicate

For each tool that duplicates, add an idempotency key: the caller sends a unique key with the request, and the tool returns the original result when it sees the key again instead of running twice.

If the tool cannot take a key, make the agent check before it acts: look up whether the refund already exists before issuing it. Re-check the fix by calling twice again.

Practice check: fictional Maple Corner tools, 4 write tools tested

The table below is fictional practice material, worked out by hand from the stated double calls. It is the expected result for the practice tools, not a run of any agent.

Tool Second call effect Idempotency key Verdict
issue_refund Same refund returned Yes Pass – safe to retry
send_email Duplicate sent No Fail – needs a key
create_ticket Duplicate ticket No Fail – needs a key
update_order Same state Yes Pass – safe to retry

Two tools are safe to retry and two are not: send_email and create_ticket both duplicate on a second call. They need idempotency keys before any retry is allowed.

Expected result. UNTESTED: the results in the practice table are worked out by hand, not measured by running any tool. Call each of your own write tools twice with the same arguments in a test environment, and check whether the second call duplicates the first.

Limits

  • A timeout does not prove the operation failed: reconcile the result before another attempt.
  • Read-only tools are idempotent by nature: the check matters for the tools that change things.

Sources

See all