Skip to content

restatedev/ai-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Documentation Discord Slack Twitter

Examples for AI workflows and Durable Agents

This repo contains a set of runnable examples of AI workflows and agents, using Durable Execution and Orchestration via Restate (Github)

The goal is to show how you can easily add production-grade resilience, state persistence, retries, suspend/resume, human-in-the-loop, and observability to agentic workflows. So you can ship agents that stay alive and consistent without sprinkling retry-code everywhere and without building heavyweight infra yourself.

The Restate approach works independent of specific SDKs but integrates easily with popular SDKs, like the Vercel AI SDK or the OpenAI Agent SDK. You can also use without and Agent SDK (roll your own loop) or for more traditional workflows.

Why Restate?

πŸ“„ For a gentle intro, read the blog post "Durable Agents - Fault Tolerance across Frameworks and without Handcuffs"

Use Case What it solves
Durable Execution Crash-safe LLM/tool calls & idempotent retriesβ€”agents resume at the last successful step.
Detailed Observability Auto-captured trace of every step, retry, and message for easy debugging and auditing.
Human-in-the-loop & long waits Suspend while waiting for user approval or slow jobs; pay for compute, not wall-clock time.
Stateful sessions / memory Virtual Objects keep multi-turn conversations and other state isolated and consistent.
Multi-agent orchestration Reliable RPC, queuing, and scheduling between agents running in separate processes.

Restate UI - trace of agent with parallel tools


Restate UI showing an agent execution with parallel tool calls

Full Example Catalog

Agent SDK Integrations

Integration Example Description Code Docs
Vercel AI SDK Template A minimal example of how to use Restate with the Vercel AI SDK πŸ“–
Tour of Agents A step-by-step tutorial showing how to build resilient agents πŸ“–
Examples More advanced examples that can be deployed as a Next.js app on Vercel -
OpenAI Agents SDK Template A minimal example of how to use Restate with the OpenAI Agents SDK πŸ“–
Tour of Agents A step-by-step tutorial showing how to build resilient agents πŸ“–

Composable AI Patterns

Pattern Description Code Docs
Chaining LLM calls Build fault-tolerant processing pipelines where each step transforms the previous step's output πŸ“–
Tool routing Automatically route requests to tools based on LLM outputs πŸ“–
Parallel tool execution Execute multiple tools in parallel with durable results that persist across failures πŸ“–
Multi-agent routing Route requests to specialized agents based on LLM outputs πŸ“–
Remote agent routing Deploy/scale agents separately and route requests with resilient communication πŸ“–
Parallel agent processing Run multiple, specialized agents in parallel and aggregate their results πŸ“–
Racing agents Race multiple agents against each other and use the fastest response πŸ“–
Human-in-the-loop pattern Implement resilient human approval steps that suspend execution until feedback is received πŸ“–
Chat sessions Long-lived, stateful chat sessions that maintain conversation state across multiple requests πŸ“–
Orchestrator-worker pattern Break down complex tasks into specialized subtasks and execute them in parallel -
Evaluator-optimizer pattern Generate β†’ Evaluate β†’ Improve loop until quality criteria are met -

Other Examples

Example Description Code
MCP Using Restate for exposing tools and resilient orchestration of tool calls
A2A Implement Google's Agent-to-Agent protocol with Restate as resilient, scalable task orchestrator

Restate currently supports 6 languages:

TypeScript Python Java Kotlin Go Rust

The examples can be translated to any of the supported languages. Join our Discord/Slack to get help with translating an examples to your language of choice.

Learn more

Acknowledgements

  • The DIY patterns are largely based on Anthropic's agents cookbook.
  • Some of the A2A examples in this repo are based on the examples included in the Google A2A repo.