← Build Agents on Cloudflare / agents
Build Agents on Cloudflare
Build and host Agents on Cloudflare, connect chat, voice, email, Slack, and webhooks to a durable agent runtime with Browser, Sandbox, AI Search, MCP, Payments, and other MCP tools.
When you host agents on Cloudflare, each agent session has a durable identity, local SQL storage, real-time connections, scheduled work, and recoverable execution.
Deploy once and Cloudflare runs your agents across its global network, scaling to tens of millions of instances. No infrastructure to manage, no sessions to reconstruct, no state to externalize.
Controls planning, tool use, and response flow.
Durable identity, state, connections, scheduling, and recovery.
Agents on Cloudflare are composed from four parts:
- Communication channels define how users and systems reach your agent, such as chat, voice, email, Slack, webhooks, and other event sources.
- The agent harness defines the loop: how the agent calls models, selects tools, handles tool results, streams responses, and decides whether to continue. Use Project Think for an opinionated harness, or build your own loop directly on the Agents SDK runtime.
- The Agents SDK runtime provides durable infrastructure: the
Agentclass, state, sessions, routing, WebSockets, scheduling, fibers, and observability. - Tools give the agent capabilities: browser automation, sandboxed code execution, AI Search, MCP tools, and payments. Code Mode lets models discover and orchestrate multiple tools by writing code.
Get started
Three commands to a running agent. No API keys required — the starter uses Workers AI by default.
npx create-cloudflare@latest --template cloudflare/agents-starter
cd agents-starter && npm install
npm run devThe starter includes streaming AI chat, server-side and client-side tools, human-in-the-loop approval, and task scheduling — a foundation you can build on or tear apart. You can also swap in OpenAI, Anthropic, Google Gemini, or any other provider.
Example agents
Build a streaming AI chat agent with tools and human-in-the-loop approvals.
Build an agent that responds to Slack messages, mentions, and commands.
Build a real-time voice agent with speech-to-text and text-to-speech.
Build an agent that can inspect pages, capture screenshots, and use browser tools.
Build an agent that sends, receives, routes, and replies to email.
Contents
126 pages mirrored from the Cloudflare documentation for agents.
Pages
- Communication channels
- Concepts
- Examples
- Getting started
- Harnesses
- Model Context Protocol (MCP)
- Platform
- Runtime
- Tools
Communication channels
Concepts
- Agentic patterns
- Human-in-the-loop patterns
- Long-running agents
- Calling LLMs
- Conversation state and memory
- Tools
- What are agents?
- Using Agents with Workflows
Examples
Getting started
Harnesses
- Think
- Actions
- Channels
- Client tools
- Configuration
- Getting started
- Lifecycle hooks
- Messengers
- Programmatic submissions
- Durable recovery
- Scheduled tasks
- Sub-agent RPC and programmatic turns
- Tools
- Workflows
Model Context Protocol (MCP)
- APIs
- McpAgent
- McpClient
- MCP handler APIs
- Cloudflare
- MCP server portals
- Cloudflare's own MCP servers
- Cloudflare Community MCP Server
- Code Mode MCP server patterns
- Guides
- Build a single-tool Code Mode MCP server
- Build a search and execute MCP server
- Build MCP client
- Connect to an MCP server
- Migrate to MCP SDK v2
- Handle OAuth with MCP servers
- Build a Remote MCP server
- Securing MCP servers
- Test a Remote MCP Server
- Protocol
- Authorization
- MCP governance
- Tools
- Transport
Platform
Runtime
- Agents API
- Communication
- Chat SDK
- HTTP and Server-Sent Events
- Protocol messages
- Readonly connections
- Routing
- WebSockets
- Execution
- Agent Skills
- Agents as tools
- Durable execution with fibers
- Queue tasks
- Retries
- Run Workflows
- Schedule tasks
- Sub-agents
- Lifecycle
- Agent class internals
- Callable methods
- getCurrentAgent()
- Sessions
- Store and sync state
- Operations
- Configuration
- Cross-domain authentication
- Observability
- Diagnostics channels
- Tracing
- Using AI Models
Tools
- AI Search
- Browser
- Code Mode
- AI SDK integration
- Code Mode API reference
- Browser integration
- Create a durable Code Mode runtime
- How Code Mode works
- Use MCP tools with Code Mode
- Use an OpenAPI service with Code Mode
- Use Code Mode with TanStack AI
- MCP
- Agentic Payments
- MPP (Machine Payments Protocol)
- Charge for HTTP content
- Accept payments with MPP
- Pay from the Agents SDK
- x402
- Charge for HTTP content
- Charge for MCP tools
- Pay from Agents SDK
- Pay from coding tools
- Sandbox