Skip to main content
Integrate OpenAI Agents SDK with Restate for fault-tolerant agent execution with automatic retries and durable state.

Learn more about OpenAI Agents SDK

Quickstart

Prerequisites:
  • Python >= v3.12
  • uv
  • OpenAI API key (get one at OpenAI)
1

Install Restate Server & CLI

Restate is a single self-contained binary. No external dependencies needed.
Start the server:
You can find the Restate UI running on port 9070 (http://localhost:9070) after starting the Restate Server.
2

Get the AI Agent template

Get the weather agent template for the OpenAI Agents and Restate:
3

Run the AI Agent service

Export your OpenAI key and run the agent:
The weather agent is now listening on port 9080.
4

Register the agent service

Tell Restate where the service is running (http://localhost:9080), so Restate can discover and register the services and handlers behind this endpoint. You can do this via the UI (http://localhost:9070):
Restate UI Playground
If you run Restate with Docker, register http://host.docker.internal:9080 instead of http://localhost:9080.
When using Restate Cloud, your service must be reachable from your Restate environment. You can use a public endpoint or connect a private service through a supported secure tunnel.
5

Send weather requests to the AI Agent

Invoke the agent via the Restate UI playground: go to http://localhost:9070, click on your service and then on playground.
Restate UI Playground
Or invoke via curl:
Output: The weather in San Francisco is sunny and 23°C.
6

Congratulations, you just ran a Durable AI Agent!

The agent you just invoked uses Durable Execution to make agents resilient to failures. Restate persisted all LLM calls and tool execution steps, so if anything fails, the agent can resume exactly where it left off.We did this by using Restate’s DurableRunner to persist LLM responses, and by using Restate Context actions (e.g. restate_context().run_typed) to make the tool executions resilient:
The Invocations tab of the Restate UI shows us how Restate captured each LLM call and tool step in a journal:
Restate UI Journal Entries
Let the weather tool raise an exception by adding the following line to the get_weather function:
You can see in the Restate UI how each LLM call and tool step gets durably executed. We can see how the weather tool is currently stuck, because the weather API is down.
Restate UI Durable Execution
Fix the problem, by removing the exception again.Once you restart the service, the agent resumes at the weather tool call and successfully completes the request.
Restate UI Durable Execution
Next step: Learn more about Durable Agents and how Restate makes your AI agents resilient to failures.

Resources

Learn More

  • Announcement: Durable Orchestration for AI Agents with Restate and OpenAI SDK
  • Blog: Durable AI Loops: Fault Tolerance across Frameworks and without Handcuffs
  • Blog: AI Agents should be serverless and durable