Content

Retries, Idempotency, and Approval: The Three Things Every AI Agent Workflow Needs

An agent that retries a failed call can double a refund. An agent that waits for approval can lose the window to act. Here is how to get retries, idempotency, and approval working together.

AI AgentsNov 30, 2026

Key takeaways

  • -A retry without an idempotency key can turn one failed action into two real ones
  • -Idempotency keys have to be scoped to the specific action, not the request or the process
  • -Approval and retries fight each other unless the approval binds to the exact call, not just the intent
  • -A policy layer that sits between the agent and the provider can enforce all three without changing agent code
  • -Swytchcode's execution kernel assigns idempotency keys and binds approvals to the specific call by hash

An agent calls a payment API, the connection times out, and the agent retries. The first call actually went through before the timeout. The retry goes through too. Now there are two charges for one request. Nothing about this agent was broken. It did exactly what retry logic is supposed to do. The problem is that nothing told it the first call might have already succeeded.

Retries, idempotency, and human approval are usually built as three separate concerns, each bolted onto an agent workflow by whoever hits the problem first. They do not work as three separate concerns. A retry without an idempotency key doubles actions. An approval step without idempotency awareness blocks legitimate retries or approves a duplicate. Getting agent workflows production-safe means treating these as one mechanism, not three features.

Why retries are not optional for an agent

Networks fail. APIs rate-limit. Providers have brief outages. An agent that gives up on the first failure is not more correct than one that retries, it is just less useful. Retries have to exist. The question is what happens when a retry runs against an action that might have already partially or fully completed.

Why idempotency keys have to be scoped to the action, not the request

A naive idempotency key tied to the HTTP request itself only protects against the exact same request being sent twice. It does not protect against the agent deciding, on its own reasoning, to issue a second logically-equivalent request with slightly different framing. The key has to represent the action the business cares about: "refund this specific charge for this specific customer", not "this specific JSON payload sent at this specific millisecond".

Scoped correctly, a retry of the same action resolves to the same result no matter how many times it fires, no matter how the agent phrased the call, and no matter whether the retry came from a timeout, a crash recovery, or an agent that forgot it already tried.

Why approval and retries fight each other without a shared mechanism

Human approval is supposed to be a gate: nothing consequential happens until a person says yes. Retries are supposed to make failures invisible. Put them together without coordination and you get one of two failure modes.

The approval blocks a legitimate retry. A human approves an action, it fails on a transient network error, and the retry logic has no way to know this specific attempt was already cleared. It either re-requests approval for something already approved, annoying the approver, or it silently retries without approval, which defeats the point of the gate.

The retry bypasses the approval entirely. An agent treats a failed call as a new task rather than a continuation of an approved one, builds a new request, and sends it without re-checking whether this new request needs its own approval. The human approved version 1 of the action; version 2 goes out with no human in the loop at all.

What one unified mechanism needs

An idempotency key generated at the point of approval, not the point of execution. The key has to exist before the first attempt, so every retry of that same approved action carries the same key regardless of how many times it fires.

A policy layer that sits between the agent and the provider. If the agent itself is responsible for deciding when to retry, when to re-request approval, and when to treat something as a new action, those decisions live inside a black box that is hard to audit and easy to get subtly wrong. A layer outside the agent that enforces the rule consistently removes that burden from agent logic entirely.

A binding between the specific approved call and the specific executed call. Approval has to attach to a hash of the actual request, not a description of the intended action, so a retry of that exact request is recognized as already-approved, and any request that differs is correctly treated as new and unapproved.

How this looks with Swytchcode

Swytchcode's execution kernel sits between the agent and every provider it talks to, and assigns the idempotency key at the point a call is approved, not at the point it executes. A retry of that same call, whatever triggers it, carries the same key and resolves to the same result instead of creating a second real action.

Approval binds to the specific call by hash, through the Verifiable Action Card: what a human approves and what actually executes are provably the same request, down to the arguments. If the agent changes anything about the call, the hash changes, and the old approval no longer covers it, so a silent swap-in of a different action cannot ride on an approval that was given for something else.

None of this requires the agent to track its own retry state. The policy lives in the execution layer, which means the same guarantee applies whether the agent is built in-house, assembled from a framework, or running a model the team does not fully control the internals of.

Writing a policy that enforces this

A policy can require explicit human approval for a specific tool, and that requirement survives retries automatically because the approval is tied to the call's hash rather than to a single pass through the agent's loop. A minimal shape looks like this:

Writing a policy that requires approval for a specific action

A policy file can name the exact tool call that needs a human in the loop, independent of how many times the agent attempts it:

rules:
  - match: stripe.refund.create
    require_approval: true
    idempotency: bind_to_approval

With that rule in place, every attempt at this action, however many retries it takes, is checked against the same approval and the same idempotency key, instead of each attempt reopening the question from scratch.

Seeing the gap before it costs anything

Before trusting a live refund flow with real retry behavior, run it against the kernel without executing anything, to see the exact call and the mode it would run in:

swytchcode exec stripe.refund.create --explain --dry-run

That shows the provider, the tool, and the idempotency key that would be assigned, before a single real retry has a chance to double anything.

Does idempotency slow down an agent's retries

No. A correctly scoped idempotency check adds a lookup, not a delay that matters in practice. What it prevents is a duplicate real-world action, which costs far more to undo than the lookup ever costs to perform.

What if the agent genuinely needs to change the action after a failure

Then it is a new action, not a retry, and it should require its own approval. The point of binding the key to the hash of the request is exactly to make that distinction automatic: same request, same key, same approval; different request, different key, new approval required.

Can this work with an approval flow that already exists, like a Slack bot

Yes. The approval interface, Slack, email, a dashboard, is separate from where the idempotency and hash-binding logic lives. The execution kernel can sit behind any approval front end and still guarantee that what gets approved is what executes, retries included.

More content

Ready to make your agent's tool calls reliable?

Give this prompt to your agent and get started.