Skip to content
be-human.ai
← Back to the journal

Testing & reliability

Idempotent AI Agent Actions: Stop Duplicate Bookings and Invoices

Learn how idempotency keys stop a retried AI agent action from creating a duplicate booking, invoice or record, with a step-by-step plan.

Be Human typographic cover with the title: Idempotent AI Agent Actions: Stop Duplicate Bookings and Invoices
Conceptual illustration created with AI · Be Human

An idempotent agent action is a write that produces the same business result no matter how many times the same request reaches the system. To stop a retried action from creating a duplicate booking, invoice or record, the agent sends a stable idempotency key with each business intent, and the system that receives the write stores that key next to the result and returns the stored result for any repeat. Retries then become safe lookups instead of second writes.

Key takeaways

  • Retries are normal. Timeouts, dropped connections and unclear responses will happen, so the agent must be designed to resend safely.
  • The idempotency key belongs to the business intent, not to a single attempt. The same booking request keeps one key from the first send to the last retry.
  • The check must happen in the system that holds the record, because only that system can say whether a write already exists.
  • Log the key, the outcome and the reviewer for every write, so a duplicate can be found and reversed quickly.
  • Give uncertain outcomes a human review path instead of letting the agent guess whether the first attempt worked.

Why retries create duplicates in the first place

Agents call tools over networks, and networks are unreliable. An agent sends a request to create a booking, the booking system saves it, and the response is lost on the way back. From the agent's side, the outcome is unknown. A careful agent will retry, and a naive one may create a second booking. Both behaviors are reasonable from inside the agent's loop, which is why duplicates are a design problem rather than a model problem.

The same pattern appears with invoices, purchase orders, customer records, support tickets and refunds. Any tool that creates something new is exposed. Tools that only read data, or that set a field to a fixed value, are much less risky, because repeating them changes nothing that matters to the business.

Retries also come from sources other than the network. A worker process may restart in the middle of a task. A person may re-run a workflow from a dashboard. A queue may redeliver a message it was not sure had been acknowledged. An idempotency design should assume that any write can arrive twice, from any of these sources.

For the broader question of when an agent should retry at all, read An AI agent retry policy that avoids repeated mistakes. This article focuses on the narrower problem of making the write itself safe to repeat.

How do you choose the idempotency key?

The key should identify what the business wants to happen, not the moment the request was sent. A common mistake is to generate a random identifier on every attempt. That gives each retry a new key, so the receiving system treats every retry as a new request, and the protection disappears.

A workable key is derived from the fields that define the intent. For a booking, that might be the customer identifier, the resource, the start time and the request that produced the booking, combined into one stable value. The agent generates the key once, when it decides to act, stores it in its task state, and reuses it for every retry of that decision.

Keep the key stable across changes to the model, the prompt or the tool version. If the agent is upgraded halfway through a task, the retry should still carry the original key. Otherwise a version change can silently create a duplicate that the old key would have blocked.

Store the key in the task record before the first call. If the agent crashes after sending the write but before saving the key, it cannot find the earlier attempt on restart. The same discipline applies to any long task, as described in Checkpoints for long AI agent tasks: resume without repeating work.

Where should the duplicate check happen?

The agent cannot be the only place where duplicates are prevented. An agent knows only what it remembers, and its memory can be incomplete after a restart or a context reset. The check belongs in the system that owns the record, because that system holds the authoritative list of what has already been written.

Many payment and API platforms already work this way. Stripe, for example, documents an idempotency mechanism in which the client sends a unique key with a request, and the platform returns the result of the first request for any repeat sent with the same key within a defined window. The principle carries over to internal tools. If your booking, billing or customer system accepts a key, use it. If it does not, the write needs a lookup before creation, matched on the same business fields that built the key.

When the target system has no native support, build a thin gateway between the agent and the write. The gateway records each key, a fingerprint of the request and the identifier of the resulting record in its own store. A repeat with the same key returns the stored identifier. A repeat with the same key but different content is rejected and escalated, because that combination usually points to a bug in how the key or the request was built.

The gateway also enforces permissions. It must authenticate the agent and limit which record types the agent can create. The guidance in the OWASP authorization cheat sheet is a practical checklist for that layer, and it should be reviewed whenever the agent's scope changes.

A step-by-step plan for one write action

Use this sequence for any agent action that creates or changes a business record.

  • Define the intent in one sentence that a manager could approve, such as the booking a customer requested for a named slot.
  • Derive the idempotency key from the fields that define that intent, and generate it once.
  • Write the key and the planned action to the task record before calling the tool.
  • Send the write with the key, and never let the key exist only in logs.
  • On success, store the returned identifier against the key and mark the step complete.
  • On a timeout or an error with no clear result, retry with the same key, never a new one.
  • If the same key returns a result that does not match the stored intent, stop and escalate instead of retrying again.
  • When retries are exhausted, hand the decision to a person with the key, the intent and the lookup result, following the approach in Human escalation for AI agents: send the decision, not the mess.

Illustrative scenario: a booking that timed out

The following scenario is illustrative and does not describe a real client. A clinic scheduling agent receives a request to book a follow-up visit for a returning patient on a Tuesday morning. It builds the key from the patient identifier, the appointment type and the requested slot, then calls the scheduling API. The request reaches the system and the slot is saved, but the response times out before the agent receives the confirmation.

Without a key, the agent sees a timeout and tries again, and the second call creates a second appointment in the same slot. Staff notice only when the patient arrives to find two bookings. With the key, the retry carries the same value, the scheduling system finds the existing record and returns its identifier. The agent marks the step complete and sends the confirmation. Nothing was written twice.

The scenario has a second branch worth planning for. If the agent had been upgraded between the first attempt and the retry, the new version might have built the key differently from the stored one. The rule is to reuse the key saved in the task record and never to rebuild it from scratch. A reviewer reading the log would see one key, one booking and one retry marked as a replay.

What should you log, and who reviews it?

Idempotency works only if someone can see it working. For each write, record the key, the intent in plain words, the outcome, whether the result was new or a replay, and the identifier of the record created. These fields let an owner answer the most important question after an incident: did we book this once or twice?

Set a review rule for replays and conflicts. A replay is normal and needs only a count in the regular summary. A conflict, where the same key arrives with different content, should reach the person who owns that process the same day. That person decides whether the agent or the underlying data is wrong. Monitoring logs that capture these fields are described in AI agent observability: what should you actually log?, and the vocabulary for traces and events is summarized in the OpenTelemetry observability primer.

Keep the rule visible to the staff who use the agent. If front desk staff can see a replay flag on a booking, they can explain a second confirmation email without opening a ticket. A plain record of what changed and why also helps, as covered in Superintelligent Agents Need a Change Log Owners Can Read.

How Be Human handles this in managed operations

Be Human treats idempotency as part of the agent's operating context, and sets it up before the agent receives write access. The engagement starts by listing which tools create records, which only read, and which fields define each business intent. The agent's permissions are scoped to the record types it needs. Keys, retry rules and conflict escalations are written into the agent's runbook. In managed operations, replay and conflict counts are reviewed on a recurring schedule, and permissions are checked again whenever a tool, a model or a workflow changes. When an uncertain write needs a person, the escalation carries the key, the intent and the lookup result, so the owner can decide without reconstructing the task.

If you are not sure which of your agent's actions can safely be retried today, take the free Be Human AI diagnostic to find the first task worth handing to an agent.

Frequently asked questions

Does an idempotency key stop every duplicate? No. A key stops duplicates that come from retries of the same intent, but it cannot stop two separate intents that a person or a process submits on purpose. Those cases need business rules, such as a check for an existing booking in the same slot, and a review path for anything that looks like a second request.

Can the agent generate a new key each time it retries? It should not. A new key on each attempt gives the receiving system no way to recognize the retry as the same request, so the protection is lost. The key should be created once for the intent, saved in the task record and reused for every retry.

What if the target system has no idempotency support? Build a gateway that stores each key, a fingerprint of the request and the resulting record identifier. Route agent writes through that gateway so that every repeat is checked before anything is created. Restrict what the agent can create at the same layer, since the gateway is also the natural place for permission checks.

Should every agent action be idempotent? Read actions usually do not need it, because repeating them changes nothing. Start with writes that create commitments or money, such as bookings, invoices, refunds and records that other teams rely on, and extend the pattern to other writes as the agent's scope grows.

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.

Less busywork. More room for you.

Bring us the work you wish you had time for.

Book a call to try a personalized AI agent free for 7 days ↗Or take the free AI diagnostic →