Idempotent Tool Calls for AI Agents: Stop Duplicate Bookings and Refunds
Idempotent tool calls give each business action a stable key, so a retrying AI agent gets the original result instead of booking or refunding twice.

An idempotent tool call is a request designed so that sending it again produces the same outcome as sending it once. For AI agents, this is done by attaching an idempotency key that is derived from the business action itself, not generated fresh on every attempt. When the agent retries after a timeout or an unclear response, the system recognizes the key and returns the result of the original action instead of creating a second booking, payment, or refund.
Key takeaways
- A retry is normal behavior for an agent, so every write tool must assume it will be called more than once for the same intent.
- The idempotency key should identify the business action (who, what, and for which record), not the attempt number.
- A timeout does not mean failure. The agent must check the status of the original action before it tries again.
- Refunds and payments need read and draft steps first, with a named person approving the final write.
- Idempotency protects against duplicates only if the tool, the logs, and the approval rules are designed together.
Why retries create duplicate bookings and refunds
A person who clicks a button twice usually notices the screen. An agent does not notice in the same way. It sends a request, waits, and receives either a timeout, a network reset, or a response it cannot parse. From the agent's side, the outcome is unknown. The safe default in many agent loops is to try again, and that is exactly where duplicates begin.
The problem is not that the model is careless. The request may have succeeded on the server while the response never arrived. Or the agent may have received a success message, then lost its working memory and re-planned the task from the original instruction. Or a workflow runner may have restarted a step that had already completed. Each of these paths ends with the same action sent twice.
The risk grows as agents act with more autonomy. A read-only agent that retries wastes some time. An agent that can create a booking, post an invoice, or issue a refund can cost money and create customer confusion every time it repeats a write. The more the agent does on its own, the more important it becomes that a repeated instruction cannot produce a repeated effect.
How an idempotency key works
An idempotency key is a unique identifier sent with a write request. The receiving system stores the key along with the result of the first successful request. If a request arrives with a key it has already processed, it returns the stored result rather than running the action again. Stripe documents this pattern for its API, sending the same key with a retried request so the original outcome is returned, and rejecting a reused key when the request parameters differ.
Two details matter for agents. First, the key must be stable across retries of the same intent. A key generated with a random value on each call protects nothing, because every retry looks like a new request. Second, the same key should never be reused for a different action. If the agent changes the amount or the customer, the tool should refuse the request rather than quietly returning the old result.
Idempotency keys belong in the tool layer, not only in the prompt. Asking the model to "be careful not to repeat requests" is not a control. The tool itself must enforce the rule, so that a retry from any cause is handled the same way.
How to design a key from the business action
A good key combines the elements that define the intended effect. For a booking, that is usually the customer or account identifier, the resource being reserved, the start time or slot, and the service type. For a refund, it is the original transaction identifier, the refund reason category, and the amount. The exact fields depend on your systems, but the principle is the same: two requests that mean the same business action should produce the same key, and two requests that mean different actions should not.
Illustrative scenario: a scheduling agent is asked to book a technician visit for a customer at a specific time slot. The booking request times out. The agent does not know whether the slot was taken. If the key was built from the customer, the slot, and the service type, the retry carries the same key. The booking system finds the original record and returns its confirmation. If the agent instead tries to book a different slot after the timeout, the key changes, and the tool should make that a new action that needs a decision.
Plan the key before you build the tool. Write down the fields that define the action, decide how they are normalized (for example, time zone and capitalization), and confirm that your system can search for an existing record by that key. A key that cannot be looked up is only half a control.
A step-by-step plan for making a write tool idempotent
- Name the business action the tool performs, such as "create booking" or "issue refund", and list which records it touches.
- Choose the fields that define the intended effect and build the key from them in a fixed order with fixed formatting.
- Store every write attempt in a log with the key, the request summary, the status (pending, succeeded, failed, or unknown), and the time.
- Before any retry, look up the key. If a succeeded record exists, return it. If the status is pending or unknown, stop and check the external system.
- Reject a request that reuses an existing key with different parameters, and return a clear error that the agent can read.
- Send unknown outcomes to a person or a reconciliation queue, rather than letting the agent guess.
- Test the tool by simulating a timeout after the write succeeds, then confirming that the retry produces one record.
What to do with an unknown result
The hardest case is not a clear failure. It is an unknown result, where the write may or may not have happened. Many duplicate incidents start here, because the agent treats silence as failure and tries again with a new plan. A better design separates three states: the action succeeded, the action failed before any effect, and the action's effect cannot be confirmed.
When the effect cannot be confirmed, the tool should return a status that means "check before retrying" and include the key. The agent can then query the external system for records matching that key or the business identifiers behind it. If the lookup finds nothing, a retry with the same key is generally safe. If the lookup finds a record, the agent should report the existing outcome and stop.
Some teams also keep a short human review path for unknowns, especially for money. A person can confirm whether the refund was issued and mark the key as resolved. This takes little time when the log is clear, and it prevents the agent from becoming the only judge of its own writes.
Refunds and payments need stricter rules than bookings
A duplicate booking is usually a nuisance that can be cancelled. A duplicate refund is a direct financial loss, and it may also trigger customer disputes or reporting work. For this reason, money-moving tools should have stricter boundaries than scheduling tools, even when both are idempotent.
A sound pattern starts with read access. The agent looks up the original transaction, confirms its status, and checks whether a refund already exists. Then it prepares a draft with the amount, the reason, and the key. A named person approves the final write. The agent should never be the only component that can both decide to refund and execute the refund. Our guide on AI agent payment tools and read-only access covers why reading comes before any refund, and safe payment limits explains which limits to set first.
For invoices and bookings, the same logic applies in a lighter form. The idempotency key prevents duplicates from retries, and a duplicate check on business fields catches the cases where a person or another system created the record outside the agent. Our note on idempotent actions that stop duplicate invoices and bookings walks through that second layer.
Checklist before a retrying agent touches a write tool
- The tool requires an idempotency key, and the agent cannot omit it.
- The key is derived from the business action, not from a timestamp or attempt counter.
- A repeated key returns the original result, and a reused key with different parameters is rejected.
- Every write attempt is logged with its status, including unknown outcomes.
- The agent has read access to check existing records before retrying.
- Money-moving writes require a named approver, and the approval is recorded.
- Error messages tell the agent whether a retry is safe, a check is needed, or a person must decide.
- Someone has tested a timeout after success and confirmed that only one record exists.
How Be Human handles idempotency in managed operations
Be Human designs the tool layer for each agent as part of the first engagement, before the agent receives write access. That work includes choosing the business fields that define each action, specifying how keys are built and stored, and defining which statuses the agent must check before retrying. Managed operations then include recurring reviews of the write log, checks for duplicate records that appear outside the agent, and controlled changes when a tool or a vendor API changes. Approval boundaries for money and customer messages are set with the business owner, and each boundary is documented so that operators can see who approves what.
If you want to see where duplicate risk sits in your own workflows, the best starting point is a short list of write actions and the places where a retry could repeat them. This is usually more useful than a long list of tools.
If you are not sure which task deserves this work first, take the free Be Human AI diagnostic to find the first task worth handing to an agent.
Frequently asked questions
What is an idempotent tool call for an AI agent? An idempotent tool call is a write request that can be sent more than once without producing a second effect. The tool attaches a key that identifies the business action, and it returns the original result when the same key arrives again. This lets an agent retry safely after a timeout without creating duplicate records.
How do I choose an idempotency key for a booking or a refund? Build the key from the fields that define the intended effect, such as the customer or account, the resource being booked or the original transaction, the slot or amount, and the service or reason category. Use the same formatting every time so that equal actions produce equal keys. Do not use a random value or an attempt counter, because those make every retry look new.
Why is an unknown result more dangerous than a clear failure? When the outcome is unknown, the write may already have happened on the other system. An agent that treats silence as failure and submits a new plan can repeat the action. The safer design returns a status that requires a check, lets the agent look up existing records by key, and sends unresolved cases to a person.
Do I still need approval steps if the tool is idempotent? Yes, for actions that move money or send messages to customers. Idempotency prevents duplicates caused by retries, but it does not decide whether a refund should be issued at all. Read access, a drafted action, and a named approver keep the decision with a person, and the log records who approved each write.
Your next step
See where an AI agent fits in your company first.
Take the free Be Human AI diagnostic. A few questions about your work show which task to hand to an agent first, what it needs to know and where a person approves.
Be Human editorial guidance. Examples are illustrative unless explicitly attributed. Sources provide background; implementation choices depend on your workflow.


