[ Web Proxy ]
URL:
Viewing: https://docs.restate.dev/ai/patterns/durable-agents [Back]  [Original]

Durable Agents - Restate
Skip to main content
Search...
Navigation
Getting Started
Durable Agents
Getting Started

Durable Agents

Build AI agents that survive crashes and recover automatically. Every LLM call, tool execution, and routing decision is durably persisted.

OpenAIOpen in ChatGPT
A Restate AI application has two main components:
  • Restate Server: Sits in front of your agents and takes care of orchestration and resiliency
  • Agent Services: Your agent logic using the Restate SDK for durability
Application Structure [Application Structure] Your agent is a regular function, a handler, that makes LLM calls, executes tools, and coordinates work. Restate wraps this handler in durable execution: every step is recorded in a journal, so if the process crashes, the agent picks up exactly where it left off. You can use the Restate SDK alone or in combination with an Agent SDK.

Creating a durable agent

Follow the Agent Quickstart to run a durable agent end-to-end. A Restate agent has three building blocks:
  1. The handler: An HTTP handler containing your agent logic, exposed in a Restate service
  2. LLM calls: Persisted so responses are not re-fetched on recovery
  3. Tool executions: Wrapped in durable steps so side effects are not duplicated
To implement a durable agent, you use the Restate SDK in combination with the Vercel AI.Heres a weather agent that looks up the weather for a city:
agent.ts
The agent logic lives in a handler of a Restate service (here the run handler).The main difference compared to a standard Vercel AI agent is the use of the Restate Context at key points:
  1. Restate service handler: The agent runs inside a Restate service handler, giving it a durable execution context. Restate exposes the handler as an HTTP endpoint you can call via curl, the Restate UI, or any HTTP client.
  2. Persisting LLM responses: Wrap the model with durableCalls(ctx) middleware so every LLM response is saved in the Restate Server and replayed during recovery. The middleware is provided via @restatedev/vercel-ai-middleware.
  3. Resilient tool execution: Tools use ctx.run() to make steps durable. The result is persisted and retried until it succeeds.

Observing your agent

The Restate UI (http://localhost:9070) shows the step-by-step execution trace of your agent, with detailed traces of every LLM call, tool execution, and state change: Learn more.

How durable execution works

When your agent runs, Restate records each steps result in a journal. If the process crashes mid-execution:
  1. Restate detects the failure and restarts the handler
  2. Completed steps are replayed from the journal (no re-execution)
  3. Execution resumes from the first incomplete step
This means:
  • LLM calls are not repeated (saving cost and time)
  • Tool side effects are not duplicated (no double bookings, no duplicate emails)
  • Multi-step workflows recover their full progress automatically
Durable AI Agent Execution [Durable AI Agent Execution]
Try it yourself: follow the Agent Quickstart to run a durable agent and see how it recovers from a failure.
AI Examples
Durable Sessions

Web Proxy Viewer  |  New URL  |  Original Page