Skip to content

Commit 3df9e68

Browse files
authored
Typescript patterns (#29)
* First pattern: chaining * add more patterns * update patterns * update patterns * update ts patterns * Add start here and end here tags to TS patterns * Formatting python patterns * Improve llmcall abstractions * Improve llmcall abstractions * Fix routing examples * Racing page * improving unity between ts and py * include local and remote tool * include local and remote tool * Improve TS patterns * Add TS racing example * add new images * fix images and add ts patterns readme * Fix readme * Fix readme * Fix readme * Fix readme * small code fixes * small fixes * Python SDK 0.12.0 * Fix broken link * remove advanced example of interruptible agent * solve mypy issues * solve mypy issues
1 parent 7e49657 commit 3df9e68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2861
-2025
lines changed

README.md

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,56 @@ The goal is to show how you can easily add production-grade _resilience_, _state
1313

1414
The Restate approach works **independent of specific SDKs** but **integrates easily with popular SDKs**, like the [Vercel AI SDK](https://ai-sdk.dev/) or the [OpenAI Agent SDK](https://openai.github.io/openai-agents-python/). You can also use without and Agent SDK _(roll your own loop)_ or for more traditional workflows.
1515

16-
📄 A gentle intro is in [the blog post "Durable Agents - Fault Tolerance across Frameworks and without Handcuffs"](https://restate.dev/blog/durable-ai-loops-fault-tolerance-across-frameworks-and-without-handcuffs/)
1716

18-
### Restate + Vercel AI SDK
17+
## Why Restate?
18+
📄 For a gentle intro, read [the blog post "Durable Agents - Fault Tolerance across Frameworks and without Handcuffs"](https://restate.dev/blog/durable-ai-loops-fault-tolerance-across-frameworks-and-without-handcuffs/)
1919

20-
- **[<img src="https://skillicons.dev/icons?i=ts" width="24" height="24"> Template](vercel-ai/template)**
21-
- [Tour of Agents: Restate + Vercel AI SDK](vercel-ai/tour-of-agents): A step-by-step tutorial showing how to build resilient agents with Restate and the Vercel AI SDK.
22-
- [More examples (including Next.js, multi-agent, etc.)](vercel-ai/examples).
23-
24-
### Restate + OpenAI Agent SDK
25-
26-
- **[<img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> Template](openai-agents/template)**
27-
- [Tour of Agents: Restate + OpenAI Agents SDK](openai-agents/tour-of-agents): A step-by-step tutorial showing how to build resilient agents with Restate and the Vercel AI SDK.
28-
29-
### Roll your own Loop? AI-enriched workflows?
30-
31-
Restate is a flexible general-purpose runtime for what we call _innately resilient application_. It is not limited to agentic workflow use cases and is being used for a variety of other use cases as well, including financial transactions or order processing. These examples show how to build agents directly on Restate's durable execution and state management:
32-
33-
- **[<img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> Python Patterns](python-patterns/README.md)** for hardening custom LLM orchestration logic.
34-
35-
36-
## Use Cases
3720

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

4629

47-
<p style="text-align: center;">
48-
<img src="vercel-ai/examples/doc/img/multi_agent_complete.png" alt="OpenAI Agent SDK invocation UI" width="600px"/><br/>
49-
Restate UI showing an ongoing agent execution
50-
</p>
30+
<img src="/doc/img/patterns/parallel_tools.png" alt="Restate UI - trace of agent with parallel tools" width="900px"/>
31+
<br/>
32+
<caption><em>Restate UI showing an agent execution with parallel tool calls</em></caption>
5133

5234

5335
## Full Example Catalog
5436

55-
1. [**Restate + Vercel AI**](vercel-ai):
56-
- [<img src="https://skillicons.dev/icons?i=ts" width="24" height="24"> Template](vercel-ai/template): A minimal example of how to use Restate with the Vercel AI SDK.
57-
- [<img src="https://skillicons.dev/icons?i=ts" width="24" height="24"> Tour of Agents: Restate + Vercel AI SDK](vercel-ai/tour-of-agents): A step-by-step tutorial showing how to build resilient agents with Restate and the Vercel AI SDK.
58-
- [<img src="https://skillicons.dev/icons?i=ts" width="24" height="24"> Examples](vercel-ai/examples): A more advanced example of how to use Restate with the Vercel AI SDK that can be deployed as a Next.js app on Vercel.
59-
2. [**Restate + OpenAI Agents Python SDK**](openai-agents):
60-
- [<img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> Template](openai-agents/template): A minimal example of how to use Restate with the OpenAI Agents SDK.
61-
- [<img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> Tour of Agents: Restate + OpenAI Agents SDK.](openai-agents/tour-of-agents): A step-by-step tutorial showing how to build resilient agents with Restate and the OpenAI Agents SDK.
62-
2. [**Restate + any AI SDK**](python-patterns): patterns for hardening custom LLM orchestration logic.
63-
- [<img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> Chaining LLM calls](python-patterns/app/chaining.py): Build fault-tolerant processing pipelines where each step transforms the previous step's output.
64-
- [<img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> Tool routing](python-patterns/app/routing_to_tool.py): Automatically route requests to tools based on LLM outputs.
65-
- [<img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> Parallel tool execution](python-patterns/app/parallel_tools.py): Execute multiple tools in parallel with durable results that persist across failures.
66-
- [<img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> Multi-agent routing](python-patterns/app/routing_to_agent.py): Route requests to specialized agents based on LLM outputs.
67-
- [<img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> Remote agent routing](python-patterns/app/routing_to_remote_agent.py): Route requests to remote agents with resilient communication.
68-
- [<img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> Parallel agent processing](python-patterns/app/parallel_agents.py): Run multiple, specialized agents in parallel and aggregate their results.
69-
- [<img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> Orchestrator-worker pattern](python-patterns/app/orchestrator_workers.py): Break down complex tasks into specialized subtasks and execute them in parallel.
70-
- [<img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> Evaluator-optimizer pattern](python-patterns/app/evaluator_optimizer.py): Generate → Evaluate → Improve loop until quality criteria are met.
71-
- [<img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> Human-in-the-loop pattern](python-patterns/app/human_in_the_loop.py): Implement resilient human approval steps that suspend execution until feedback is received.
72-
- [<img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> Chat sessions](python-patterns/app/chat.py): Long-lived, stateful chat sessions that maintain conversation state across multiple requests.
73-
3. [**MCP** <img src="https://skillicons.dev/icons?i=ts" width="24" height="24">](mcp): Using Restate for exposing tools and resilient orchestration of tool calls.
74-
4. [**A2A** <img src="https://skillicons.dev/icons?i=python&theme=light" width="24" height="24"> ](a2a): Implement Google's Agent-to-Agent protocol with Restate as resilient, scalable task orchestrator.
37+
### Agent SDK Integrations
38+
| Integration | Example | Description | Code | Docs |
39+
|-------------|---------|-------------|------|------------------------------------------------------|
40+
| **Vercel AI SDK** | **Template** | A minimal example of how to use Restate with the Vercel AI SDK | [<img src="https://skillicons.dev/icons?i=ts&theme=light" width="20" height="20">](vercel-ai/template) | [📖](https://docs.restate.dev/ai-quickstart) |
41+
| | **Tour of Agents** | A step-by-step tutorial showing how to build resilient agents | [<img src="https://skillicons.dev/icons?i=ts&theme=light" width="20" height="20">](vercel-ai/tour-of-agents) | [📖](https://docs.restate.dev/tour/vercel-ai-agents) |
42+
| | **Examples** | More advanced examples that can be deployed as a Next.js app on Vercel | [<img src="https://skillicons.dev/icons?i=ts&theme=light" width="20" height="20">](vercel-ai/examples) | - |
43+
| **OpenAI Agents SDK** | **Template** | A minimal example of how to use Restate with the OpenAI Agents SDK | [<img src="https://skillicons.dev/icons?i=python&theme=light" width="20" height="20">](openai-agents/template) | [📖](https://docs.restate.dev/ai-quickstart) |
44+
| | **Tour of Agents** | A step-by-step tutorial showing how to build resilient agents | [<img src="https://skillicons.dev/icons?i=python&theme=light" width="20" height="20">](openai-agents/tour-of-agents) | [📖](https://docs.restate.dev/tour/openai-agents) |
45+
46+
### Composable AI Patterns
47+
| Pattern | Description | Code | Docs |
48+
|------------------------|-------------|------|------|
49+
| **Chaining LLM calls** | Build fault-tolerant processing pipelines where each step transforms the previous step's output | [<img src="https://skillicons.dev/icons?i=python&theme=light" width="20" height="20">](python-patterns/app/chaining.py) [<img src="https://skillicons.dev/icons?i=ts&theme=light" width="20" height="20">](typescript-patterns/src/chaining.ts) | [📖](https://docs.restate.dev/ai/patterns/prompt-chaining) |
50+
| **Tool routing** | Automatically route requests to tools based on LLM outputs | [<img src="https://skillicons.dev/icons?i=python&theme=light" width="20" height="20">](python-patterns/app/routing_to_tool.py) [<img src="https://skillicons.dev/icons?i=ts&theme=light" width="20" height="20">](typescript-patterns/src/routing-to-tools.ts) | [📖](https://docs.restate.dev/ai/patterns/tools) |
51+
| **Parallel tool execution** | Execute multiple tools in parallel with durable results that persist across failures | [<img src="https://skillicons.dev/icons?i=python&theme=light" width="20" height="20">](python-patterns/app/parallel_tools.py) [<img src="https://skillicons.dev/icons?i=ts&theme=light" width="20" height="20">](typescript-patterns/src/parallel-tools.ts) | [📖](https://docs.restate.dev/ai/patterns/parallelization) |
52+
| **Multi-agent routing** | Route requests to specialized agents based on LLM outputs | [<img src="https://skillicons.dev/icons?i=python&theme=light" width="20" height="20">](python-patterns/app/routing_to_agent.py) [<img src="https://skillicons.dev/icons?i=ts&theme=light" width="20" height="20">](typescript-patterns/src/routing-to-agent.ts) | [📖](https://docs.restate.dev/ai/patterns/multi-agent) |
53+
| **Remote agent routing** | Deploy/scale agents separately and route requests with resilient communication | [<img src="https://skillicons.dev/icons?i=python&theme=light" width="20" height="20">](python-patterns/app/routing_to_remote_agent.py) [<img src="https://skillicons.dev/icons?i=ts&theme=light" width="20" height="20">](typescript-patterns/src/routing-to-remote-agent.ts) | [📖](https://docs.restate.dev/ai/patterns/multi-agent) |
54+
| **Parallel agent processing** | Run multiple, specialized agents in parallel and aggregate their results | [<img src="https://skillicons.dev/icons?i=python&theme=light" width="20" height="20">](python-patterns/app/parallel_agents.py) [<img src="https://skillicons.dev/icons?i=ts&theme=light" width="20" height="20">](typescript-patterns/src/parallel-agents.ts) | [📖](https://docs.restate.dev/ai/patterns/parallelization) |
55+
| **Racing agents** | Race multiple agents against each other and use the fastest response | [<img src="https://skillicons.dev/icons?i=python&theme=light" width="20" height="20">](python-patterns/app/racing_agents.py) [<img src="https://skillicons.dev/icons?i=ts&theme=light" width="20" height="20">](typescript-patterns/src/racing-agents.ts) | [📖](https://docs.restate.dev/ai/patterns/competitive-racing) |
56+
| **Human-in-the-loop pattern** | Implement resilient human approval steps that suspend execution until feedback is received | [<img src="https://skillicons.dev/icons?i=python&theme=light" width="20" height="20">](python-patterns/app/human_in_the_loop.py) [<img src="https://skillicons.dev/icons?i=ts&theme=light" width="20" height="20">](typescript-patterns/src/human-in-the-loop.ts) | [📖](https://docs.restate.dev/ai/patterns/human-in-the-loop) |
57+
| **Chat sessions** | Long-lived, stateful chat sessions that maintain conversation state across multiple requests | [<img src="https://skillicons.dev/icons?i=python&theme=light" width="20" height="20">](python-patterns/app/chat.py) [<img src="https://skillicons.dev/icons?i=ts&theme=light" width="20" height="20">](typescript-patterns/src/chat.ts) | [📖](https://docs.restate.dev/ai/patterns/sessions-and-chat) |
58+
| **Orchestrator-worker pattern** | Break down complex tasks into specialized subtasks and execute them in parallel | [<img src="https://skillicons.dev/icons?i=python&theme=light" width="20" height="20">](python-patterns/app/orchestrator_workers.py) | - |
59+
| **Evaluator-optimizer pattern** | Generate → Evaluate → Improve loop until quality criteria are met | [<img src="https://skillicons.dev/icons?i=python&theme=light" width="20" height="20">](python-patterns/app/evaluator_optimizer.py) [<img src="https://skillicons.dev/icons?i=ts&theme=light" width="20" height="20">](typescript-patterns/src/evaluator-optimizer.ts) | - |
60+
61+
### Other Examples
62+
| Example | Description | Code |
63+
|------------------------|-------------|------|
64+
| **MCP** | Using Restate for exposing tools and resilient orchestration of tool calls | [<img src="https://skillicons.dev/icons?i=ts&theme=light" width="20" height="20">](mcp) |
65+
| **A2A** | Implement Google's Agent-to-Agent protocol with Restate as resilient, scalable task orchestrator | [<img src="https://skillicons.dev/icons?i=python&theme=light" width="20" height="20">](a2a) |
7566

7667
Restate currently supports 6 languages:
7768

@@ -86,9 +77,7 @@ The examples can be translated to any of the supported languages.
8677
Join our [Discord](https://discord.gg/skW3AZ6uGd)/[Slack](https://join.slack.com/t/restatecommunity/shared_invite/zt-2v9gl005c-WBpr167o5XJZI1l7HWKImA) to get help with translating an examples to your language of choice.
8778

8879
## Learn more
89-
- [Documentation](https://docs.restate.dev/)
90-
- [Quickstart](https://docs.restate.dev/get_started/quickstart)
91-
- Tour of Agents: a tutorial including the most important features: [Vercel AI SDK](https://docs.restate.dev/tour/vercel-ai-agents), [OpenAI Agents SDK](https://docs.restate.dev/tour/openai-agents)
80+
- [Documentation](https://docs.restate.dev/ai)
9281
- [Examples on workflows, microservice orchestration, async tasks, event processing](https://github.com/restatedev/examples)
9382
- [Restate Cloud](https://restate.dev/cloud/)
9483
- [Discord](https://discord.gg/skW3AZ6uGd) / [Slack](https://join.slack.com/t/restatecommunity/shared_invite/zt-2v9gl005c-WBpr167o5XJZI1l7HWKImA)

0 commit comments

Comments
 (0)