Durable AI agents save execution progress to recover from failures and continue after the initial request ends. They can wait for human input and reuse saved results instead of repeating every model call and tool operation.
Copy link to headingWhen do you need a durable AI agent?
Use durable execution when an interruption would erase costly work or leave the next action uncertain. Common cases include:
Long-running tasks that outlive their initial request.
Human approvals that arrive after execution has paused.
Multi-step work whose completed results must survive a failure.
External jobs that require retries or a later response.
Consider a research agent that spends an afternoon gathering sources, analyzing a dataset, and preparing a report. The reviewer approves distribution the next morning after the original request has ended. The agent needs the completed analyses, report version, and pending approval to remain available during the wait.
Copy link to headingRecover after a crash
Process memory holds messages, tool results, and the next planned action while an agent runs. If the process terminates, that information disappears unless your application has saved it elsewhere.
Suppose the research agent has analyzed 12 files when its process crashes. Recovery needs to establish which analyses have finished, where their results are, and what remains to be done.
For short interactions, a conventional agent loop may be sufficient if repeating a failed request has little cost and won’t duplicate an external action.
Copy link to headingLonger timeouts only go so far
Each approach handles a different part of recovery:
Copy link to headingHow does a durable AI agent work?
The runtime records progress as the agent completes operations:
Execute a model call or tool operation.
Save its result.
Suspend when the task needs an external event.
Continue using recorded results when execution resumes.
Tool choices can still change dynamically. Durability determines how completed operations remain available after an interruption.
Copy link to headingRecord model calls and tool results
An agent's logic includes model calls, tool selection, and tool execution. AI SDK provides interfaces for models, tools, structured output, and streaming. Durable execution adds persistence around the operations you need to recover.
In the Workflow SDK, workflow functions coordinate tasks, while step functions make model calls and external API requests. The runtime saves the results of completed steps for replay.
In a project configured for Workflow SDK, this example records the retrieved source text as a step result:
export async function retrieveResearchSource(sourceUrl: string) { "use workflow";
return await fetchSourceText(sourceUrl);}
async function fetchSourceText(sourceUrl: string) { "use step";
const response = await fetch(sourceUrl);
if (!response.ok) { throw new Error(`Source request failed: ${response.status}`); }
return { sourceUrl, text: await response.text(), };}Once the step result is recorded, replay can reuse it without fetching the source again. Keep results compact in production. The research agent guide shows project setup and how to record selected findings.
Keep retrieval and analysis in separate steps when you need to reuse their results independently. If the whole task runs in one step, failure before its result is saved can require repeating substantial work.
Copy link to headingReplay completed work
During recovery, replay reruns workflow logic using recorded step results. Completed model calls can return saved outputs, avoiding another generation that could change the answer and add cost. Operations without a recorded successful result may need another attempt.
Copy link to headingPrevent duplicate actions
Suppose the delivery API accepts the report, but its response never reaches your application. The agent sees a failed request even though the delivery succeeded. Retrying could send the report twice.
When the API supports idempotency keys, reuse the same key for attempts at the same action. Workflow SDK provides a stable stepId across retries that you can use for this purpose.
For services without duplicate prevention, design reconciliation: look up the operation's external status before deciding whether to repeat it. Recording an intention to send cannot, by itself, prove whether delivery happened.
Copy link to headingHandle model-provider failures
Failed model requests don't have to end the task. Vercel AI Gateway centralizes provider access with failover, request logs, and spend controls.
For the research agent, provider failover can help obtain a model result when one provider is unavailable. Workflow persistence records that result so the task can recover and continue with it.
Copy link to headingWait for human approval
Before waiting, the agent records the pending decision. Workflow SDK hooks suspend execution until an external event arrives, such as a reviewer's response. Use sleep() for a timed pause that releases workflow compute until the wait ends.
For the research agent, the application presents the draft for review. The run waits until it receives a decision associated with that review.
Copy link to headingBind approval to a report version
Bind each approval to the report version, recipients, requested action, and run identity. Record the reviewer and decision timestamp with the proposal.
Verify that the reviewer has authority to approve the action. Before executing it, check that the approved proposal still matches the intended operation. Revising the report or changing the recipients may require a fresh review.
An approval to distribute one draft should not silently authorize distributing a later version to different people.
Copy link to headingDefine each review outcome
Decide how the agent should handle approval, rejection, requested changes, and expiration before it reaches the waiting point. Suspension preserves the opportunity to continue; your application determines what happens next.
Late responses also need a rule. An expired approval request should not unintentionally revive a canceled task.
Copy link to headingWhat must survive an interruption?
Durable agents need enough saved information to recover their tasks, including execution records, model context, files, and application data.
Keep their roles distinct so restoring one doesn't create a false impression that everything has recovered.
Associate completed analyses with artifact identifiers and file versions so recovery can locate their results. Assemble the relevant instructions, messages, and findings for each model call from the saved state.
Copy link to headingIsolate generated code
Vercel Sandbox runs the research agent’s generated analysis code in an isolated Linux microVM. Limit its inputs, credentials, and network access to what the task needs. Recovery may create a replacement sandbox, so required files must remain available independently of the running environment.
Copy link to headingKeep files across sandbox runs
Vercel Drives preserve workspace files across sandbox runs. Store datasets, scripts, and charts in the mounted directory, then save the drive's name and artifact paths with the task so a later run can locate them.
Drives preserve files but do not keep processes running. Only one sandbox can write to a drive at a time. Other sandboxes can mount read-only snapshots of its contents; each snapshot excludes changes made after it was mounted.
Copy link to headingA durable agent in action
This illustrative timeline follows the research agent across an overnight approval wait. It does not represent product performance.
Copy link to headingPick up the task the next morning
The continuing entity is the persisted task. Your application correlates the reviewer response with the pending run. Execution continues using recorded findings and the approved report version.
The application can create another sandbox and mount the saved workspace for further analysis. When delivery only needs an API call, it can send the report without starting another sandbox.
Copy link to headingManaging durable agents
Durability provides recoverable execution at the boundaries that your runtime supports. You still design the task's decisions, permissions, and failure behavior.
Copy link to headingEnsure correctness
Durability can preserve an incorrect answer, and retries can duplicate external effects without appropriate protection.
Validate findings against sources and check tool inputs before acting. Apply idempotency or reconciliation where external operations can be repeated. Durability preserves progress; quality checks and action policies determine whether that progress is acceptable.
Copy link to headingDefine when the agent stops
Give the task explicit limits and outcomes:
Define completion criteria and a maximum number of agent iterations.
Limit retries for temporary errors and escalate failures needing intervention.
Establish deadlines for approvals and external jobs.
Budget model usage, compute, and storage.
Provide cancellation and define how to handle operations already in flight.
The research agent should stop when it has delivered the approved report, exhausted its budget, or reached a failure requiring a person.
Copy link to headingMake the agent’s status visible
Expose the run identity, current activity, last completed operation, pending event, and latest error. Reviewers need to know when a report awaits their approval, and operators need to see repeated analysis failures.
Vercel Workflows observability records steps, inputs, outputs, sleeps, and errors. Combine that history with your application’s deadlines and usage records to identify runs that need intervention.
Copy link to headingFrequently asked questions
Copy link to headingIs a durable agent the same as an agent with memory?
No. Agent memory preserves information that the agent can use, such as past messages or preferences. Durable execution preserves task progress and supports continuation after interruptions. An agent can remember a conversation while still being unable to recover an unfinished tool operation.
Copy link to headingDoes a durable agent need to run continuously?
No. Durable agents can suspend while waiting for a person, a timer, or an external event. Their progress persists while active workflow execution stops. Other resources, such as a sandbox left running, have separate lifecycles.
Copy link to headingCan an existing AI SDK agent become durable?
Yes. The AI SDK and Workflow SDK can be combined to run agent logic inside a durable workflow. WorkflowAgent provides an integration for durable agent loops, retryable tools, and approvals. Recovery still depends on choosing appropriate step boundaries and protecting external side effects.
Copy link to headingDoes every durable agent need a sandbox and a drive?
No. An agent that only calls APIs may need durable execution without executing generated code or maintaining workspace files. Add a sandbox when the task requires isolated code execution, and persistent file storage when those files must persist across environments.
Copy link to headingChoose an implementation guide
Start with the guide that matches your agent’s task:
Research: Build a web research agent that records searches and findings, then assembles a cited report.
Code generation and testing: Build a durable AI code agent that tests generated code in isolation and limits attempts to fix failures.
Documentation maintenance: Build a documentation feedback agent that stages proposed fixes as unpublished drafts and notifies editors for review.