Resilient agents with Restate + LangChain
May 14, 2026 · View on GitHub
Use LangChain's create_agent to build your agent, and let Restate handle the persistence and resiliency of the agent's decisions and tool executions.
The example is an agent that can search for the weather in certain city.
Running the example
-
Export your OpenAI or Anthropic API key as an environment variable:
export OPENAI_API_KEY=your_openai_api_key -
Start the Restate Server in a separate shell:
restate-server -
Start the services:
uv run . -
Register the services:
restate -y deployments register localhost:9080 -
Send requests to your agent:
curl localhost:8080/agent/run --json '{"message": "What is the weather in San Francisco?"}'Returns:
The weather in San Francisco is currently 23°C and sunny.
Check the Restate UI (http://localhost:9080) to see the journals of your invocations.
Integrating Restate with LangChain
To make the agent resilient, we attach RestateMiddleware to create_agent:
- Every LLM call is journaled by
awrap_model_callviactx.run_typed("call LLM", ...). - Parallel tool calls are serialized via a turnstile keyed on
tool_call_idso the journal order is deterministic across replays.
Tool side effects are NOT auto-journaled. Wrap them yourself inside the tool body with restate_context().run_typed("name", ...) for the steps you want to be durable. This keeps it explicit which calls are journaled and avoids nested-ctx.run_typed traps.