Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions .changeset/soft-docs-ship.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"agents": patch
"@cloudflare/codemode": patch
"@cloudflare/shell": patch
"@cloudflare/think": patch
"@cloudflare/voice": patch
---

Include each package's documentation in its published package.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ out
.nuxt
dist

# Generated package documentation (source lives in /docs)
packages/*/docs

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
Expand Down
2 changes: 1 addition & 1 deletion design/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The goal is to give contributors (and future-us) a quick way to understand _why_
| [think-durable-submissions.md](./think-durable-submissions.md) | Think durable submissions — async programmatic turns, recovery, idempotency |
| [visuals.md](./visuals.md) | UI component library choice, Kumo usage, custom patterns |
| [readonly-connections.md](./readonly-connections.md) | Readonly connection enforcement, storage, tradeoffs, and caveats |
| [workspace.md](./workspace.md) | Workspace — hybrid SQLite+R2 filesystem, bash, symlinks |
| [workspace.md](./shell/index.md) | Workspace — hybrid SQLite+R2 filesystem, bash, symlinks |
| [agent-tools.md](./agent-tools.md) | Agent tools — chat sub-agent orchestration, parent registry, replay |
| [sub-agent-routing.md](./sub-agent-routing.md) | Sub-agent routing as shipped — facets, nested URLs, registry, parent lookup |
| [rfc-sub-agents.md](./rfc-sub-agents.md) | RFC: Sub-agents — child DOs via facets, typed stubs, mixin API |
Expand Down
4 changes: 2 additions & 2 deletions design/think-durable-submissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Related:
- [think.md](./think.md) — overall Think architecture
- [think-sessions.md](./think-sessions.md) — Session-backed message storage
- [docs/think/programmatic-submissions.md](../docs/think/programmatic-submissions.md) — user-facing API guide
- [server-driven-messages.md](../docs/server-driven-messages.md) — lighter-weight server message patterns
- [workflows.md](../docs/workflows.md) — durable multi-step orchestration
- [server-driven-messages.md](../docs/agents/server-driven-messages.md) — lighter-weight server message patterns
- [workflows.md](../docs/agents/workflows.md) — durable multi-step orchestration

## Problem

Expand Down
2 changes: 1 addition & 1 deletion design/think-roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The implementation plan for `@cloudflare/think` — an opinionated chat agent base class built on Session for conversation storage and the Agents SDK for execution.

> This roadmap is retained as a historical implementation record. All phases are complete, and current recovery behavior is documented in [`docs/think/index.md`](../docs/think/index.md) and [`docs/chat-agents.md#stream-recovery`](../docs/chat-agents.md#stream-recovery).
> This roadmap is retained as a historical implementation record. All phases are complete, and current recovery behavior is documented in [`docs/think/index.md`](../docs/think/index.md) and [`docs/agents/chat-agents.md#stream-recovery`](../docs/agents/chat-agents.md#stream-recovery).

This document synthesizes four prior analyses:

Expand Down
4 changes: 2 additions & 2 deletions design/think.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ An opinionated Agent base class for AI assistants. Handles the chat lifecycle
> This is a historical design note. For current user-facing API behavior, see
> [`docs/think/index.md`](../docs/think/index.md),
> [`docs/think/lifecycle-hooks.md`](../docs/think/lifecycle-hooks.md), and
> [`docs/chat-agents.md#stream-recovery`](../docs/chat-agents.md#stream-recovery).
> [`docs/agents/chat-agents.md#stream-recovery`](../docs/agents/chat-agents.md#stream-recovery).

## Problem

Expand Down Expand Up @@ -518,4 +518,4 @@ Think's design — skills, extensions, tree-structured sessions, compaction, and
- [chat-shared-layer.md](./chat-shared-layer.md) — shared streaming, sanitization, and protocol primitives (Think uses `StreamAccumulator`, `sanitizeMessage`, `enforceRowSizeLimit`, `CHAT_MESSAGE_TYPES`, `TurnQueue`, `ResumableStream`, `ContinuationState` from `agents/chat`)
- [rfc-sub-agents.md](./rfc-sub-agents.md) — sub-agents via facets (Think's `subAgent()` is built on this)
- [loopback.md](./loopback.md) — cross-boundary RPC pattern (used by extension host bridge)
- [workspace.md](./workspace.md) — Workspace design (Think's file tools are backed by this)
- [workspace.md](./shell/index.md) — Workspace design (Think's file tools are backed by this)
4 changes: 2 additions & 2 deletions design/voice.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Voice Pipeline — Design (Experimental)

> **Status: experimental.** The voice API is in `@cloudflare/voice` and will break between releases. See `docs/voice.md` for user-facing docs.
> **Status: experimental.** The voice API is in `@cloudflare/voice` and will break between releases. See `docs/voice/index.md` for user-facing docs.

How the voice pipeline works and why it is built this way.

Expand Down Expand Up @@ -35,7 +35,7 @@ What you give up:
- WebRTC-grade network resilience (TCP head-of-line blocking on bad networks)
- Tightly coupled echo cancellation (browser AEC via `getUserMedia` constraints still works)

SFU integration is documented as an advanced option in `docs/voice.md`.
SFU integration is documented as an advanced option in `docs/voice/index.md`.

## Two mixins

Expand Down
11 changes: 6 additions & 5 deletions docs/AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# AGENTS.md — docs/

User-facing documentation for the Agents SDK. These markdown files are manually synced to [developers.cloudflare.com/agents/](https://developers.cloudflare.com/agents/).
User-facing documentation for the Agents SDK monorepo. Each package owns the directory under `docs/` matching its unscoped package name. These markdown files are manually synced to [developers.cloudflare.com/agents/](https://developers.cloudflare.com/agents/) where applicable.

## Diátaxis framework

Expand Down Expand Up @@ -31,14 +31,15 @@ There is no automated sync workflow. Changes here must be manually ported to `cl
- Be concrete: code snippets over prose, real examples over abstract descriptions
- No contractions (Cloudflare style guide requirement — "do not" not "don't")
- Use TypeScript for all code examples
- Link to related docs within this folder using relative paths (`./state.md`)
- Link within a package directory using relative paths (`./state.md`)
- Link across package directories with an absolute repository URL, and name the installed package path in prose when relevant

## Adding a new doc

1. Write the markdown file in this folder
2. Add it to `index.md` in the appropriate section
1. Write the markdown file in the directory owned by its package
2. Add it to that package's `index.md`
3. If it documents a design decision, consider whether a companion entry in `/design` is warranted

## TODO backlog

`index.md` has ~15 entries marked `TODO` — these are known gaps. When filling one, remove the TODO marker and follow the steps above.
`agents/index.md` has entries marked `TODO` — these are known gaps. When filling one, remove the TODO marker and follow the steps above.
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/agent-tools.md → docs/agents/agent-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ For Think children, prefer agent tools when the parent model or workflow
delegates work and you want retained child runs, event replay, abort bridging,
and UI drill-in. Use raw `subAgent(...).chat()` only for lower-level streaming
RPC where your code owns forwarding, cancellation, and replay policy. For the
full comparison, see [Choosing a turn API](./think/index.md#choosing-a-turn-api).
full comparison, see [Choosing a turn API](https://github.com/cloudflare/agents/blob/main/docs/think/index.md#choosing-a-turn-api).

## Use an Agent as an AI SDK tool

Expand Down
4 changes: 2 additions & 2 deletions docs/browse-the-web.md → docs/agents/browse-the-web.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class MyAgent extends Agent<Env> {
}
```

> Using `@cloudflare/think`? The unified execute tool (`createExecuteTool(this)`) already includes `cdp.*` alongside `state.*` and `tools.*` when `env.BROWSER` is bound. See the [Think tools documentation](./think/tools.md).
> Using `@cloudflare/think`? The unified execute tool (`createExecuteTool(this)`) already includes `cdp.*` alongside `state.*` and `tools.*` when `env.BROWSER` is bound. See the [Think tools documentation](https://github.com/cloudflare/agents/blob/main/docs/think/tools.md).

## TanStack AI

Expand Down Expand Up @@ -427,4 +427,4 @@ Use `cdpUrl` only when you intentionally want to connect to some other CDP-compa

## Example

See [`examples/ai-chat/`](../examples/ai-chat/) for a working example that combines browser tools with other AI SDK tools, MCP servers, and tool approval, and [`examples/codemode-connectors/`](../examples/codemode-connectors/) for the connector playground (including in-sandbox approvals).
See [`examples/ai-chat/`](https://github.com/cloudflare/agents/tree/main/examples/ai-chat) for a working example that combines browser tools with other AI SDK tools, MCP servers, and tool approval, and [`examples/codemode-connectors/`](https://github.com/cloudflare/agents/tree/main/examples/codemode-connectors) for the connector playground (including in-sandbox approvals).
File renamed without changes.
12 changes: 6 additions & 6 deletions docs/chat-agents.md → docs/agents/chat-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ The right strategy depends on whether the provider supports assistant prefill an
| OpenAI (Responses API) | Retrieve completed response by ID — zero wasted tokens | Zero |
| Anthropic | Persist partial, send a synthetic user message to continue | Medium |

For a complete multi-provider implementation, see the [`forever-chat` example](../experimental/forever-chat/) and the [`forever.md` design doc](../experimental/forever.md). For how chat recovery fits into the broader long-running agents story, see [Long-Running Agents: Recovering interrupted LLM streams](./long-running-agents.md#recovering-interrupted-llm-streams).
For a complete multi-provider implementation, see the [`forever-chat` example](https://github.com/cloudflare/agents/tree/main/experimental/forever-chat) and the [`forever.md` design doc](https://github.com/cloudflare/agents/tree/main/experimental/forever.md). For how chat recovery fits into the broader long-running agents story, see [Long-Running Agents: Recovering interrupted LLM streams](./long-running-agents.md#recovering-interrupted-llm-streams).

## Client API

Expand Down Expand Up @@ -1669,11 +1669,11 @@ The chat protocol uses typed JSON messages over WebSocket:

## Examples

- [AI Chat Example](../examples/ai-chat/) — Modern example with server tools, client tools, and approval
- [Dynamic Tools](../examples/dynamic-tools/) — SDK/platform pattern with dynamic client-defined tools
- [Resumable Stream Chat](../examples/resumable-stream-chat/) — Automatic stream resumption demo
- [Human in the Loop Guide](../guides/human-in-the-loop/) — Tool approval with `needsApproval` and `onToolCall`
- [Playground](../examples/playground/) — Kitchen-sink demo of all SDK features
- [AI Chat Example](https://github.com/cloudflare/agents/tree/main/examples/ai-chat) — Modern example with server tools, client tools, and approval
- [Dynamic Tools](https://github.com/cloudflare/agents/tree/main/examples/dynamic-tools) — SDK/platform pattern with dynamic client-defined tools
- [Resumable Stream Chat](https://github.com/cloudflare/agents/tree/main/examples/resumable-stream-chat) — Automatic stream resumption demo
- [Human in the Loop Guide](https://github.com/cloudflare/agents/tree/main/guides/human-in-the-loop) — Tool approval with `needsApproval` and `onToolCall`
- [Playground](https://github.com/cloudflare/agents/tree/main/examples/playground) — Kitchen-sink demo of all SDK features

## Related Docs

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ Key points:

### Chat recovery

`AIChatAgent` builds on fibers for LLM streaming recovery. When `chatRecovery` is enabled, each chat turn is wrapped in a fiber automatically. The framework handles the internal recovery path and exposes `onChatRecovery` for provider-specific strategies. See [Long-Running Agents: Recovering interrupted LLM streams](./long-running-agents.md#recovering-interrupted-llm-streams) and the [`forever-chat` example](../experimental/forever-chat/).
`AIChatAgent` builds on fibers for LLM streaming recovery. When `chatRecovery` is enabled, each chat turn is wrapped in a fiber automatically. The framework handles the internal recovery path and exposes `onChatRecovery` for provider-specific strategies. See [Long-Running Agents: Recovering interrupted LLM streams](./long-running-agents.md#recovering-interrupted-llm-streams) and the [`forever-chat` example](https://github.com/cloudflare/agents/tree/main/experimental/forever-chat).

## Concurrent fibers

Expand Down Expand Up @@ -533,5 +533,5 @@ Run an async function while keeping the DO alive. Heartbeat starts before `fn` a
- [Scheduling](./scheduling.md) — `keepAlive` details and the alarm system
- [Workflows](./workflows.md) — durable multi-step execution outside the agent
- [Chat Agents](./chat-agents.md) — `chatRecovery` and `onChatRecovery`
- [`forever-chat` example](../experimental/forever-chat/) — multi-provider LLM recovery demo
- [`forever.md` design doc](../experimental/forever.md) — internal design details, tradeoffs, and architecture
- [`forever-chat` example](https://github.com/cloudflare/agents/tree/main/experimental/forever-chat) — multi-provider LLM recovery demo
- [`forever.md` design doc](https://github.com/cloudflare/agents/tree/main/experimental/forever.md) — internal design details, tradeoffs, and architecture
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 16 additions & 16 deletions docs/human-in-the-loop.md → docs/agents/human-in-the-loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ Human-in-the-loop (HITL) patterns allow agents to pause execution and wait for h

Agents SDK supports multiple human-in-the-loop patterns. Choose based on your use case:

| Use Case | Pattern | Best For | Example |
| ---------------------- | ----------------- | -------------------------------------------------- | ----------------------------------------------------------------- |
| Long-running workflows | Workflow Approval | Multi-step processes, durable approval gates | [examples/workflows/](../examples/workflows/) |
| AIChatAgent tools | `needsApproval` | Chat-based tool calls with `@cloudflare/ai-chat` | [guides/human-in-the-loop/](../guides/human-in-the-loop/) |
| OpenAI Agents SDK | `needsApproval` | Using OpenAI's agent SDK with conditional approval | [openai-sdk/human-in-the-loop/](../openai-sdk/human-in-the-loop/) |
| Client-side tools | `onToolCall` | Tools that need browser APIs or user interaction | Pattern below |
| MCP Servers | Elicitation | MCP tools requesting structured user input | [examples/mcp-elicitation/](../examples/mcp-elicitation/) |
| Use Case | Pattern | Best For | Example |
| ---------------------- | ----------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| Long-running workflows | Workflow Approval | Multi-step processes, durable approval gates | [examples/workflows/](https://github.com/cloudflare/agents/tree/main/examples/workflows) |
| AIChatAgent tools | `needsApproval` | Chat-based tool calls with `@cloudflare/ai-chat` | [guides/human-in-the-loop/](https://github.com/cloudflare/agents/tree/main/guides/human-in-the-loop) |
| OpenAI Agents SDK | `needsApproval` | Using OpenAI's agent SDK with conditional approval | [openai-sdk/human-in-the-loop/](https://github.com/cloudflare/agents/tree/main/openai-sdk/human-in-the-loop) |
| Client-side tools | `onToolCall` | Tools that need browser APIs or user interaction | Pattern below |
| MCP Servers | Elicitation | MCP tools requesting structured user input | [examples/mcp-elicitation/](https://github.com/cloudflare/agents/tree/main/examples/mcp-elicitation) |

### Decision Guide

Expand Down Expand Up @@ -350,7 +350,7 @@ This sends a `tool_result` to the LLM with your custom error text, so it can res

`addToolOutput` with `state: "output-error"` does **not** auto-continue — it gives you full control over what happens next. If you want the LLM to respond to the error, call `sendMessage()` afterward.

See the complete example: [guides/human-in-the-loop/](../guides/human-in-the-loop/)
See the complete example: [guides/human-in-the-loop/](https://github.com/cloudflare/agents/tree/main/guides/human-in-the-loop)

### Surviving restarts while waiting for a human

Expand Down Expand Up @@ -448,7 +448,7 @@ export class WeatherAgent extends Agent<Env, AgentState> {
}
```

See the complete example: [openai-sdk/human-in-the-loop/](../openai-sdk/human-in-the-loop/)
See the complete example: [openai-sdk/human-in-the-loop/](https://github.com/cloudflare/agents/tree/main/openai-sdk/human-in-the-loop)

### MCP Elicitation

Expand Down Expand Up @@ -530,7 +530,7 @@ export class MyMcpAgent extends Agent<Env, State> {
- The **MCP client** (Claude Desktop, etc.) handles UI rendering
- Returns `{ action: "accept" | "decline", content: {...} }`

See the complete example: [examples/mcp-elicitation/](../examples/mcp-elicitation/)
See the complete example: [examples/mcp-elicitation/](https://github.com/cloudflare/agents/tree/main/examples/mcp-elicitation)

## State Patterns for Approvals

Expand Down Expand Up @@ -647,12 +647,12 @@ async submitForApproval(request: ApprovalRequest): Promise<string> {

## Complete Examples

| Pattern | Location | Description |
| ----------------- | ----------------------------------------------------------------- | -------------------------------------------------- |
| Workflow approval | [examples/workflows/](../examples/workflows/) | Multi-step task processing with approval gate |
| AIChatAgent tools | [guides/human-in-the-loop/](../guides/human-in-the-loop/) | Chat tool approval with needsApproval + onToolCall |
| OpenAI Agents SDK | [openai-sdk/human-in-the-loop/](../openai-sdk/human-in-the-loop/) | Conditional tool approval with modal |
| MCP Elicitation | [examples/mcp-elicitation/](../examples/mcp-elicitation/) | MCP server requesting structured user input |
| Pattern | Location | Description |
| ----------------- | ------------------------------------------------------------------------------------------------------------ | -------------------------------------------------- |
| Workflow approval | [examples/workflows/](https://github.com/cloudflare/agents/tree/main/examples/workflows) | Multi-step task processing with approval gate |
| AIChatAgent tools | [guides/human-in-the-loop/](https://github.com/cloudflare/agents/tree/main/guides/human-in-the-loop) | Chat tool approval with needsApproval + onToolCall |
| OpenAI Agents SDK | [openai-sdk/human-in-the-loop/](https://github.com/cloudflare/agents/tree/main/openai-sdk/human-in-the-loop) | Conditional tool approval with modal |
| MCP Elicitation | [examples/mcp-elicitation/](https://github.com/cloudflare/agents/tree/main/examples/mcp-elicitation) | MCP server requesting structured user input |

For detailed API documentation, see:

Expand Down
Loading
Loading