A windswept bonsai on a floating island

Get to know Cadenya

We’re developers who love to build. We set out to create a yes-code platform that makes building agents feel like the best parts of building software.

Idempotency and retries for AI agent tool calls (2026)

Idempotency

By Cadenya

Temporal, DBOS, Inngest, Trigger.dev, and Restate all retry a failed activity or step, and each one runs your code at least once, so a retried tool call can repeat its side effect. The fix is the same everywhere: send the API that does the work an idempotency key that stays the same across retries, such as a Stripe-style Idempotency-Key header.

Pick Temporal for activity retries with no attempt limit by default, DBOS for steps checkpointed in your database, Inngest or Trigger.dev for a dedup key on the trigger, and Restate for an Idempotency-Key header on every handler. If you’d rather not write the agent loop at all, Cadenya is a hosted agent loop with approvals, conversation state, resume, and model swap. It hands a failed tool call back to the agent, and an External ID stops a duplicate objective. A coding agent can set it up with no account, in a temporary workspace you claim later. What it offers is at the end.

Every price and limit below comes from each vendor’s own pages, checked on November 11, 2026.

Temporal, DBOS, Inngest, Trigger.dev and Restate retries side by side

Here’s what each option retries and which key it gives you:

What retriesDefault retry policyHow the docs word the guaranteeBuilt-in dedup keyHow to stop retrying
TemporalAn ActivityUnlimited attempts, 1 second doubling to 100 seconds”Observed as completed exactly once”, but “may be executed multiple times”The Workflow ID for runs. For an Activity, the Run ID plus the Activity IDApplicationError with non_retryable
DBOSA step, once you set retries_allowed=True3 attempts, 1 second doublingSteps “at least once”, transactions “exactly once”The workflow IDA should_retry predicate
InngestEach step.run(), with its own counter4 retries after the first attempt, with jitterA step “cannot undo a duplicate write”Event id or an idempotency expression, for 24 hoursNonRetriableError
Trigger.devThe task’s run(), from the topmaxAttempts in trigger.config or on the taskA key stops a task being “triggered twice”, not its code “running twice”idempotencyKey on the trigger, with a 30-day default TTLAbortTaskRunError
RestateA ctx.run block or the whole invocation70 attempts, 50 ms doubling to 60 seconds, then pauseAn invocation “runs exactly once regardless of failures”Idempotency-Key header, for 24 hoursTerminalError
CadenyaA failed tool call returns to the agent as tool_errorThe agent reads the error text and picks the next step”Use an External ID to prevent duplicate Objectives”External ID on the objective, webhook-id on webhooksThe agent “decides how to proceed”

The SDK versions behind these docs, from the registries on November 11, 2026:

PackageRegistryLatest versionReleased
temporalioPyPI1.36.02026-11-11
@temporalio/workflownpm1.25.02026-10-27
dbosPyPI3.5.02026-11-10
@dbos-inc/dbos-sdknpm5.5.02026-11-10
inngestnpm4.26.22026-10-29
@trigger.dev/sdknpm4.8.42026-11-10
@restatedev/restate-sdknpm1.18.32026-11-04

Temporal activity idempotency: at least once execution and the retry policy

Temporal retries Activities by default and Workflows not at all. The default Retry Policy starts at 1 second, doubles up to 100 seconds, and its maximum attempts value “is evaluated as unlimited.”

The Activity Definition page says one with retries is “observed as completed exactly once.” The next sentence matters more for a tool call: “the Activity may be executed multiple times and may even partially complete more than once.” The docs name the case. The Activity finishes, then “the Worker crashes just before it notifies the Temporal Service,” so it runs again.

Idempotency keys “are enforced by the service you are calling from your Activity, not by the Activity itself.” For the key, Temporal suggests “a combination of the Workflow Run ID and the Activity ID,” which stays the same across retry attempts.

Give each side effect its own Activity, because when one step of three fails, “the entire Activity” runs again. And set a Start-To-Close Timeout, since the server “relies on the Start-To-Close Timeout to force Activity retries” after a Worker crash. Temporal for AI agents covers the rest of the setup.

DBOS step retries and workflow IDs as idempotency keys

DBOS states both halves plainly. Steps “are tried at least once but are never re-executed after they complete,” and transactions “commit exactly once.”

Step retries are off by default. The decorator defaults are retries_allowed=False, interval_seconds=1.0, max_attempts=3, and backoff_rate=2.0. This example from the DBOS Python docs retries an HTTP call up to 10 times, but skips one error type:

@DBOS.step(
    retries_allowed=True,
    max_attempts=10,
    should_retry=lambda e: not isinstance(e, FatalError),
)

An async step also takes timeout_seconds. With retries on, “each attempt gets its own timeout,” so timeout_seconds=30, max_attempts=3 “allows up to three 30-second attempts, not 30 seconds total.”

The run-level key is the workflow ID. “An assigned workflow ID acts as an idempotency key: if a workflow is called multiple times with the same ID, it executes only once.”

with SetWorkflowID("very-unique-id"):
    example_workflow()

DBOS for AI agents walks through the full agent setup.

Inngest step retries and Trigger.dev idempotency keys

Inngest gives each step.run() its own retry counter, with “four retries after the initial attempt” by default and backoff with jitter. The docs name the gap a key fills: “A named step preserves a completed result; it cannot undo a duplicate write that occurred before Inngest received the step result.”

Inngest has two dedup keys. A stable event id stops functions starting again for “a duplicate event received within 24 hours.” A function’s idempotency expression, such as event.data.cartId, “prevents another execution with the same value for 24 hours.”

Trigger.dev retries the whole run, so “run() executes again from the top.” Its docs draw the line: “An idempotency key stops a task from being triggered twice. It does not stop the code inside that task from running twice.” Keys are stored “for 30 days” by default, and idempotencyKeyTTL changes that.

For the provider call, Trigger.dev uses the run ID, because “retries are attempts of the same run, so the ID does not change between them.” Its own example passes it straight to Stripe:

import { idempotencyKeys, task } from "@trigger.dev/sdk";
import Stripe from "stripe";
import { sendRefundEmail } from "./send-refund-email";

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

export const refundOrder = task({
  id: "refund-order",
  retry: { maxAttempts: 3 },
  run: async (payload: { orderId: string; paymentIntentId: string; amount: number }, { ctx }) => {
    // The run ID is stable across retries, so Stripe returns the original refund instead of creating a second one
    await stripe.refunds.create(
      { payment_intent: payload.paymentIntentId, amount: payload.amount },
      { idempotencyKey: `refund-${ctx.run.id}` }
    );

    // The Trigger.dev key is run-scoped by default, so a retry does not create a second email run
    const idempotencyKey = await idempotencyKeys.create("refund-email");
    await sendRefundEmail.trigger({ orderId: payload.orderId }, { idempotencyKey });
  },
});

AbortTaskRunError fails the attempt and turns retrying off. Trigger.dev for AI agents covers waits and queues.

Restate retries, ctx.run and the Idempotency-Key header

An invocation “runs exactly once regardless of failures,” and after a crash Restate “replays the journal, skipping completed steps.” A ctx.run block that throws is still retried, so the side effect inside it can run again.

The server default retry policy starts at 50ms, doubles up to 60s, and stops at max-attempts = 70 with on-max-attempts = "pause". You can set a tighter policy per block, as the TypeScript docs show:

const myRunRetryPolicy = {
  initialRetryInterval: { milliseconds: 500 },
  retryIntervalFactor: 2,
  maxRetryInterval: { seconds: 1 },
  maxRetryAttempts: 5,
  maxRetryDuration: { seconds: 1 },
};
await ctx.run("write", () => writeToOtherSystem(), myRunRetryPolicy);

For keys, ctx.rand.uuidv4() is seeded by the invocation ID, so it returns the “same result on retries.” The HTTP ingress takes an Idempotency-Key header, and a repeat “within 24 hours” gets the same response without running again.

In an agent, retries stack. The Vercel AI SDK retries a model call maxRetries times (2 by default), then Restate retries the invocation, so “the two limits multiply.” For tool errors, the AI SDK by default turns the error into “a message to the LLM, and the agent decides how to proceed.” Restate vs Temporal compares the two engines.

Stripe-style Idempotency-Key headers for tool side effects

A retry engine can’t stop an API from acting twice. As Trigger.dev puts it, “Only the provider can deduplicate its own API call.” So derive a key that stays the same across attempts, and send it to the API that does the side effect.

Stripe’s API “supports idempotency for safely retrying requests without accidentally performing the same operation twice.” Keys are “up to 255 characters long,” and for API v1, Stripe can remove a key once it’s at least 24 hours old. A reused key with different parameters returns an error.

Resend works the same way for email. It “checks whether an email with the same idempotency key has already been sent in the last 24 hours,” and takes the key in the same Idempotency-Key header.

Each engine gives you a stable value for that header:

  1. Temporal: the Workflow Run ID plus the Activity ID.
  2. Trigger.dev: ctx.run.id, or a business ID such as refund-${payload.orderId} to dedupe across separate runs.
  3. Restate: ctx.rand.uuidv4().
  4. Vercel Workflow: getStepMetadata().stepId, which “does not change between attempts.”

The run-level key stops a duplicate trigger. Only the API’s own key stops a duplicate charge. A tool that moves money needs both. Vercel Workflow for AI agents shows the stepId pattern in a full workflow.

Webhook deduplication and at-least-once delivery

Webhooks reverse the problem: the sender retries, and your handler dedupes. Slack’s Events API expects “an HTTP 2xx within three seconds.” If it doesn’t get one, it retries three times, “backing off exponentially,” and marks each retry with an x-slack-retry-num header. Each event carries an event_id.

The pattern for any at-least-once sender:

  1. Read the delivery’s unique ID from the header or body.
  2. Insert it into a table with a unique constraint before you trigger any side effect.
  3. If the insert conflicts, return 200 and stop.

Cadenya’s webhooks follow the Standard Webhooks spec, and its docs give the same advice: treat webhook-id as an idempotency key, “store it with a unique constraint before you trigger side effects,” and return 200 without repeating the work.

What does Cadenya offer that durable execution engines don’t?

The engines above retry your code, and your code still has to be the agent and carry every key. Cadenya runs the agent loop for you, with approvals before side effects, duplicate protection, and a durable record of every tool call. Here’s what that covers:

  1. Nothing else to run. Cadenya hosts the agent loop, so you operate no workers, brokers, or journal databases.
  2. The agent loop, already written. Cadenya calls the model, runs the tools, and hands each result back to the model.
  3. A failed tool call goes back to the agent. An endpoint error, an MCP rejection, or a timeout becomes a tool_error event, and the objective keeps going: “The agent sees the error text and decides how to proceed.”
  4. A person approves before the side effect runs. With requiresApproval: true, the objective emits toolApprovalRequested, and toolCalled arrives only after approval. A denial carries a memo that steers the agent.
  5. One objective per record. Set an External ID on each objective. “Use an External ID to prevent duplicate Objectives for a workflow or record in your application.”
  6. Webhooks with the idempotency key built in. The webhook-id header is “Unique per delivery. Key your idempotency on it.” Cadenya records each delivery attempt with its status and attempt count.
  7. A durable event log of every tool call. “Every Objective carries a durable event log of its agent loop,” and every tool call gets a toolcall_ ID. List the stored events, or stream new ones over server-sent events and resume from the last event ID.
  8. SDKs at 1.9.0. TypeScript (Node 18 or later), Python (3.9 or later), Ruby, and Go SDKs ship under Apache-2.0, plus a CLI and a plain HTTP API.
  9. A price per model call. Free for 1,000 loops a month, $49 a month for 50,000, then $0.0015 a loop. A loop is one LLM request.

Webhooks shows the idempotent handler step by step, and the free plan needs no card.

No account yet? A coding agent can create a temporary workspace with cadenya workspaces create --temporary, run its first objectives there, and hand you a link to claim it, as auth.md explains. To create an account, sign up at app.cadenya.com/signup, then copy your API key from the API keys page at app.cadenya.com/account/apiKeys.

Grow wherever AI goes next.

Start shipping agents that are equipped to evolve.

A pine bonsai overlooking a mountain lake