|
| 1 | +--- |
| 2 | +pcx_content_type: concept |
| 3 | +title: Patterns |
| 4 | +sidebar: |
| 5 | + order: 3 |
| 6 | +head: [] |
| 7 | +--- |
| 8 | + |
| 9 | +import { GitHubCode } from "~/components"; |
| 10 | + |
| 11 | +This page lists and defines common patterns for implementing AI agents, based on [Anthropic's patterns for building effective agents](https://www.anthropic.com/research/building-effective-agents). |
| 12 | + |
| 13 | +Code samples use the [AI SDK](https://sdk.vercel.ai/docs/foundations/agents), running in [Durable Objects](/durable-objects). |
| 14 | + |
| 15 | +## Prompt Chaining |
| 16 | + |
| 17 | +Decomposes tasks into a sequence of steps, where each LLM call processes the output of the previous one. |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +[**Interactive Demo**](https://ai.cloudflare.com/anthropic-agent-patterns) |
| 22 | + |
| 23 | +<GitHubCode |
| 24 | + repo="cloudflare/agents" |
| 25 | + file="guides/anthropic-patterns/src/flows/01 sequential.txt" |
| 26 | + commit="56fb801dc8f980f080b36fcdbd94005099829495" |
| 27 | + lang="ts" |
| 28 | +/> |
| 29 | + |
| 30 | +## Routing |
| 31 | + |
| 32 | +Classifies input and directs it to specialized followup tasks, allowing for separation of concerns. |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +[**Interactive Demo**](https://ai.cloudflare.com/anthropic-agent-patterns) |
| 37 | + |
| 38 | +<GitHubCode |
| 39 | + repo="cloudflare/agents" |
| 40 | + file="guides/anthropic-patterns/src/flows/02 routing.txt" |
| 41 | + commit="56fb801dc8f980f080b36fcdbd94005099829495" |
| 42 | + lang="ts" |
| 43 | +/> |
| 44 | + |
| 45 | +## Parallelization |
| 46 | + |
| 47 | +Enables simultaneous task processing through sectioning or voting mechanisms. |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +[**Interactive Demo**](https://ai.cloudflare.com/anthropic-agent-patterns) |
| 52 | + |
| 53 | +<GitHubCode |
| 54 | + repo="cloudflare/agents" |
| 55 | + file="guides/anthropic-patterns/src/flows/03 parallel.txt" |
| 56 | + commit="56fb801dc8f980f080b36fcdbd94005099829495" |
| 57 | + lang="ts" |
| 58 | +/> |
| 59 | + |
| 60 | +## Orchestrator-Workers |
| 61 | + |
| 62 | +A central LLM dynamically breaks down tasks, delegates to Worker LLMs, and synthesizes results. |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +[**Interactive Demo**](https://ai.cloudflare.com/anthropic-agent-patterns) |
| 67 | + |
| 68 | +<GitHubCode |
| 69 | + repo="cloudflare/agents" |
| 70 | + file="guides/anthropic-patterns/src/flows/04 orchestrator.txt" |
| 71 | + commit="56fb801dc8f980f080b36fcdbd94005099829495" |
| 72 | + lang="ts" |
| 73 | +/> |
| 74 | + |
| 75 | +## Evaluator-Optimizer |
| 76 | + |
| 77 | +One LLM generates responses while another provides evaluation and feedback in a loop. |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +[**Interactive Demo**](https://ai.cloudflare.com/anthropic-agent-patterns) |
| 82 | + |
| 83 | +<GitHubCode |
| 84 | + repo="cloudflare/agents" |
| 85 | + file="guides/anthropic-patterns/src/flows/05 evaluator.txt" |
| 86 | + commit="56fb801dc8f980f080b36fcdbd94005099829495" |
| 87 | + lang="ts" |
| 88 | +/> |
0 commit comments