Skip to content
Merged

Patterns #19559

Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/assets/images/agents/01-sequential.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/agents/02-routing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/agents/03-parallel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/agents/04-orchestrator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/agents/05-evaluator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions src/content/docs/agents/patterns.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
pcx_content_type: concept
title: Patterns
sidebar:
order: 3
head: []
---

import { GitHubCode } from "~/components";

Common patterns for implementing AI agents, based on [Anthropic's research on agent patterns](https://www.anthropic.com/research/building-effective-agents).

Code samples use the [AI SDK](https://sdk.vercel.ai/docs/foundations/agents), running in Cloudflare's Durable Objects.

## Prompt Chaining

Decomposes tasks into a sequence of steps, where each LLM call processes the output of the previous one.

![Figure 1: Prompt Chaining](~/assets/images/agnets/01-sequential.png "Figure 1: Prompt Chaining")

[**Interactive Demo**](https://patterns.agents.workers.dev)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[**Interactive Demo**](https://patterns.agents.workers.dev)
[**Interactive Demo**](https://anthropic-patterns.agents.workers.dev)


<GitHubCode
repo="cloudflare/agents"
file="examples/anthropic-patterns/src/flows/01-sequential.txt"
commit="3b8959063c17d53e27a3040670d9cbf8a95644e1"
lang="ts"
/>

## Routing

Classifies input and directs it to specialized followup tasks, allowing for separation of concerns.

![Figure 2: Routing](~/assets/images/agnets/02-routing.png "Figure 2: Routing")

[**Interactive Demo**](https://patterns.agents.workers.dev)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[**Interactive Demo**](https://patterns.agents.workers.dev)
[**Interactive Demo**](https://anthropic-patterns.agents.workers.dev)


<GitHubCode
repo="cloudflare/agents"
file="examples/anthropic-patterns/src/flows/02-routing.txt"
commit="3b8959063c17d53e27a3040670d9cbf8a95644e1"
lang="ts"
/>

## Parallelization

Enables simultaneous task processing through sectioning or voting mechanisms.

![Figure 3: Parallelization](~/assets/images/agnets/04-parallel.png "Figure 3: Parallelization")

[**Interactive Demo**](https://patterns.agents.workers.dev)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[**Interactive Demo**](https://patterns.agents.workers.dev)
[**Interactive Demo**](https://anthropic-patterns.agents.workers.dev)


<GitHubCode
repo="cloudflare/agents"
file="examples/anthropic-patterns/src/flows/03-parallel.txt"
commit="3b8959063c17d53e27a3040670d9cbf8a95644e1"
lang="ts"
/>

## Orchestrator-Workers

A central LLM dynamically breaks down tasks, delegates to worker LLMs, and synthesizes results.

![Figure 4: Orchestrator Workers](~/assets/images/agnets/04-orchestrator.png "Figure 4: Orchestrator Workers")

[**Interactive Demo**](https://patterns.agents.workers.dev)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[**Interactive Demo**](https://patterns.agents.workers.dev)
[**Interactive Demo**](https://anthropic-patterns.agents.workers.dev)


<GitHubCode
repo="cloudflare/agents"
file="examples/anthropic-patterns/src/flows/04-orchestrator.txt"
commit="3b8959063c17d53e27a3040670d9cbf8a95644e1"
lang="ts"
/>

## Evaluator-Optimizer

One LLM generates responses while another provides evaluation and feedback in a loop.

![Figure 5: Evaluator-Optimizer](~/assets/images/agnets/05-evaluator.png "Figure 5: Evaluator-Optimizer")

[**Interactive Demo**](https://patterns.agents.workers.dev)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[**Interactive Demo**](https://patterns.agents.workers.dev)
[**Interactive Demo**](https://anthropic-patterns.agents.workers.dev)


<GitHubCode
repo="cloudflare/agents"
file="examples/anthropic-patterns/src/flows/05-evaluator.txt"
commit="3b8959063c17d53e27a3040670d9cbf8a95644e1"
lang="ts"
/>
Loading