Short answer: Durable execution records a workflow’s progress as it runs, so after a crash, deploy or timeout it resumes from the last completed step instead of starting over or running a step twice. AI agents need durable execution when a task outlives a single request: it runs for minutes or months, waits for a person, or takes actions that cost money. Temporal is the most established open-source engine for durable execution. It does not give you the agent layer (tool permissions, model calls, usage tracking, versioned agent definitions), which is the job of an agent runtime. We use both: Wippy dispatches its durable workflows to a Temporal cluster.
Most agent demos run inside one HTTP request. A user asks, the agent thinks, calls a few tools and answers within a minute. Nothing has to survive a restart, so nothing does.
Real work is longer. An agent that onboards a supplier, reviews a contract, reconciles a month of payouts or chases an approval runs for hours or weeks. Somewhere in the middle, a server restarts, a deploy goes out, a model API times out or the approver goes on vacation. If the agent’s progress lives only in memory, it is gone, and the side effects it already caused (an email sent, a refund issued) may happen again when someone reruns it.
We have built on Temporal since 2021. Spiral Scout authored the Temporal PHP SDK, is a Temporal partner, and designs agent systems on top of it for clients as part of our AI consulting and development work. This post explains what durable execution does for agents, the patterns that make it work, when you don’t need it, and what still has to be built above it.
Key Takeaways
- Durable execution saves the result of each step, so a crashed agent resumes where it stopped instead of repeating a refund or an email.
- Put every model call and side effect in an activity, make external writes idempotent, and keep personal data out of workflow history.
- Human approvals become signals with durable timers, so a workflow can wait hours or months without holding a server.
- Temporal keeps the work alive. An agent runtime such as Wippy decides which tools an agent may call and records what each call costs.
What is durable execution for AI agents?
Durable execution is a way of running code so that its progress is saved step by step. The engine records the result of each step in a history. If the process dies, a new worker picks up the workflow, replays it against the recorded history, skips the steps that already finished (using their saved results) and continues from where it stopped.
Three properties follow from that design. Completed steps don’t run twice, because a recorded tool call returns its saved result on replay instead of calling the tool again. Waiting is cheap: a workflow can sleep for 24 hours or wait weeks for a signal without holding a thread or a server. Failure handling is declared up front, with retries, timeouts and backoff set as policies on each step rather than written as loops scattered through the code.
The trade-off is discipline. Workflow code must be deterministic, because replay has to take the same path every time. Anything non-deterministic, including every call to a language model, the current time and random IDs, goes into a recorded step, which Temporal calls an activity. Temporal’s documentation on deterministic constraints lists the rules.
Why do long-running AI agents fail on ordinary infrastructure?
Anton “JD” Titov, our co-founder and CTO, puts it bluntly in his guide to AI in Temporal: expect model calls to fail, expect output constraints to be ignored, and know that retries are the least of the problems. Agents add failure modes that ordinary services don’t have.
Start with the model calls themselves, which fail in more ways. Timeouts and rate limits are the easy cases. The harder case is a call that succeeds but returns malformed or wrong output, which needs validation and a retry with feedback.
Agents also wait on people. An approval can take a day or a month, and holding that state in memory or in an ad hoc database table is where most homegrown agent systems leak. Deploys happen mid-run as well: a workflow that started under last week’s code may finish under this week’s, and without versioning, replay breaks.
Partial completion is dangerous. If an agent issued a refund and then crashed before recording it, a naive rerun issues it again. Size is a separate hazard, because payloads are large: documents, transcripts and long contexts don’t belong in a workflow’s history, which is replayed on every recovery.
Each of these failures happens in the execution layer, outside the model. Together they are why pilots that work in a demo fail in production.
Six durable execution patterns for AI agents
These are the patterns we apply on every agent system that runs on Temporal. They come from client builds and from our own runtime.
1. Put every model call in an activity, and validate inside it
The workflow decides what happens next. The activity calls the model, checks the output against a schema, and throws a retryable error if the output is invalid. That keeps the workflow deterministic. It also turns “the model returned garbage” from a crash into one more retryable failure with a policy.
2. Make every tool that writes idempotent
Durable execution prevents a recorded step from running twice. It cannot help when a tool’s external effect finished but its result was never recorded, for example when a crash lands between the two. Wippy’s own documentation is blunt about this: recovery does not make external writes exactly once. Pass an idempotency key with every write, so a repeated call is recognized and ignored by the system on the other end.
3. Model human approval as a signal plus a durable timer
The workflow submits the request, then waits for a decision signal. A durable timer handles escalation if nobody answers in 24 hours. Nothing is held in memory while it waits, and a deploy in the meantime changes nothing. Where to put those gates is a design question we covered in human-in-the-loop AI workflows.
4. Keep sensitive data and large blobs out of workflow history
Store documents and personal data in your own encrypted storage and pass references. For Staq’s autonomous banking app, we designed a reference layer that keeps personally identifiable information outside both Temporal and the LLM context, using opaque IDs. It shrinks history, speeds up replay and narrows what a breach could expose.
5. Version workflows, because agent work outlives deploys
A run that waits three weeks for approval will cross several releases. Use Temporal’s versioning so in-flight runs keep their original path while new runs get the new one. Our post on what Replay 2026 changes for agents on Temporal covers the newer primitives that help here.
6. Write compensation for multi-step actions
If step five fails after steps one to four moved money or changed records, the workflow should undo or offset what it did, in order. This saga pattern is ordinary code in a durable workflow, because the workflow knows exactly which steps completed.
When don’t AI agents need Temporal?
Temporal is infrastructure you have to run (or pay for as Temporal Cloud), and determinism is a discipline your team has to learn. In three cases you can skip it.
The clearest case is an agent that answers within one request. A support reply or a document summary that finishes in seconds can simply be retried from the start. A read-only agent is similar: if rerunning it causes no side effects, losing a run costs only time.
For batch work with a few steps, a database-backed pipeline is enough. Persisting each step’s result to your database gets most of the benefit. Wippy’s dataflow framework works this way: it persists state to a database, commits each agent tool result as it finishes, and on recovery reruns only the calls without a committed result.
Reach for Temporal when the work spans hours or more, waits on people, coordinates several services, or moves money. That is the line we use with clients.
Temporal vs an agent runtime: what each layer does
The question we hear most is “Do I need Temporal or an agent framework?” They solve different problems, and production systems usually need both.
| Concern | Durable execution (Temporal) | Agent runtime (for example, Wippy) |
|---|---|---|
| Saving progress and resuming after failure | Yes: event history and replay | Uses Temporal for durable workflows |
| Retries, timeouts, timers, signals | Yes, as policies per step | Exposes them to agent code |
| Which tools an agent may call | No | Yes: an agent can only call tools in its definition, and every call is checked against policy |
| Model calls, prompts and memory | No (you write activities) | Yes: LLM, agents, sessions, embeddings, RAG |
| Token usage per call | No | Yes: recorded per call, tagged by user and context |
| Versioned agent definitions with rollback | Workflow code versioning only | Yes: a versioned registry with rollback |
| Tracing of model and tool calls | Workflow-level visibility | OpenTelemetry traces of model and tool calls |
| App layer: UI, users, real-time updates | No | Yes: web hosting, WebSocket and SSE |
In Wippy, a workflow written in Lua runs on Temporal: each recorded call becomes a Temporal activity, and production durability depends on a running Temporal worker. The runtime adds the agent concerns above it. We explained the broader framework versus runtime split in the missing layer between your AI agent and production.
What we’ve learned building on Temporal
Start by designing the workflow boundaries, before anyone writes a prompt. For an enterprise data services company building a visual workflow editor on Temporal, the value of our review was decomposition and naming conventions that hold as complexity grows. The client’s team owns the system, and it has been running in production for about a year.
A second lesson is that agents should propose and workflows should decide. On Staq, the goal was agent-generated financial workflows that are dynamic but deterministic on replay, with human approval that can graduate to automation.
Put rules first and agents second. In Alaska Rubber Group’s quoting system, Temporal workflows enforce each stage and rules, while agents help with configuration. People step in only when needed.
Finally, treat history size as a budget. Teams that put whole documents or long prompts into workflow history find out during their first big replay.
Common mistakes with long-running agents
Calling the model from workflow code is the first trap, because it works in testing and breaks replay later. Retrying everything is another. Some errors, such as a rejected payment, should stop the run and route it to a person, so mark them non-retryable.
One giant workflow is a mistake too. Split long agent work into child workflows with clear inputs and outputs, so each piece can be versioned and tested.
The last mistake is keeping no per-agent cost record. A long-running agent that loops can burn tokens for days, so record usage per call and alert on it.
Get the guide to AI in Temporal
“A Practical and Tactical Approach to AI in Temporal” is a walkthrough by Anton “JD” Titov of how AI workflows evolved from simple RAG to autonomous agents on Temporal, with code for LLM activities, action workflows and failure handling. It’s free on our Agentic AI with Temporal page.