# Agents Build AI-powered agents to perform tasks, persist state, browse the web, and communicate in real-time > Links below point directly to Markdown versions of each page. Any page can also be retrieved as Markdown by sending an `Accept: text/markdown` header to the page's URL without the `index.md` suffix (for example, `curl -H "Accept: text/markdown" https://docs.ahq.lat/agents/`). > > For other Cloudflare products, see the [Cloudflare documentation directory](https://docs.ahq.lat/llms.txt). ## Overview - [Build Agents on Cloudflare](https://docs.ahq.lat/agents/index.md): Create stateful AI agents with persistent memory, real-time WebSocket connections, and scheduled tasks using the Cloudflare Agents SDK. ## Harnesses - [Harnesses](https://docs.ahq.lat/agents/harnesses/index.md): Understand agent harnesses — the loop that controls planning, tool use, and response flow. - [Think](https://docs.ahq.lat/agents/harnesses/think/index.md): Opinionated chat agent framework with built-in tools, persistent memory, lifecycle hooks, streaming, messengers, scheduled tasks, Workflows, and sub-agent RPC. - [Client tools](https://docs.ahq.lat/agents/harnesses/think/client-tools/index.md): Browser-side tools, approval flows, auto-continuation, message concurrency, and multi-tab broadcast for Think agents. - [Configuration](https://docs.ahq.lat/agents/harnesses/think/configuration/index.md): Configuration overrides, dynamic runtime configuration, Session integration, and package exports for the Think chat agent framework. - [Getting started](https://docs.ahq.lat/agents/harnesses/think/getting-started/index.md): Build a Think chat agent with persistent memory, built-in file tools, custom tools, and streaming, step by step. - [Lifecycle hooks](https://docs.ahq.lat/agents/harnesses/think/lifecycle-hooks/index.md): Hooks at each stage of a Think chat turn — beforeTurn, beforeStep, beforeToolCall, afterToolCall, onStepFinish, onChunk, onChatResponse, and onChatError. - [Messengers](https://docs.ahq.lat/agents/harnesses/think/messengers/index.md): Receive and reply to Chat SDK messenger webhooks directly from a Think agent, including Telegram setup, routing, conversation targets, and recovery. - [Programmatic submissions](https://docs.ahq.lat/agents/harnesses/think/programmatic-submissions/index.md): Durably accept a Think turn with submitMessages() for webhooks and RPC callers, with idempotent retry, status inspection, and cancellation. - [Durable recovery](https://docs.ahq.lat/agents/harnesses/think/recovery/index.md): Bounded chat recovery, the stream-stall watchdog, repairing interrupted tool calls, and stability detection for Think agents. - [Scheduled tasks](https://docs.ahq.lat/agents/harnesses/think/scheduled-tasks/index.md): Declare recurring, timezone-aware Think turns and deterministic handlers with getScheduledTasks() and a typed scheduling DSL. - [Sub-agent RPC and programmatic turns](https://docs.ahq.lat/agents/harnesses/think/sub-agents/index.md): Stream Think turns through a child agent with chat(), and trigger turns programmatically with saveMessages(), continueLastTurn(), and abort. - [Tools](https://docs.ahq.lat/agents/harnesses/think/tools/index.md): Built-in workspace tools (including bash), custom tools, approvals, MCP tools, code execution, browser tools, and extensions for Think agents. - [Workflows](https://docs.ahq.lat/agents/harnesses/think/workflows/index.md): Run a durable model-driven reasoning step inside a Cloudflare Workflow with ThinkWorkflow and step.prompt(), including structured output and timeouts. ## Model Context Protocol (MCP) - [Model Context Protocol (MCP)](https://docs.ahq.lat/agents/model-context-protocol/index.md): Build and deploy remote MCP servers on Cloudflare to connect AI agents with external tools and services. - [McpAgent](https://docs.ahq.lat/agents/model-context-protocol/apis/agent-api/index.md): Build stateful MCP servers on Cloudflare by extending the McpAgent class with persistent storage and agent capabilities. - [McpClient](https://docs.ahq.lat/agents/model-context-protocol/apis/client-api/index.md): Connect Agents to external MCP servers to use their tools, resources, and prompts over the Model Context Protocol. - [createMcpHandler](https://docs.ahq.lat/agents/model-context-protocol/apis/handler-api/index.md): Create a stateless MCP server fetch handler for a plain Worker using createMcpHandler and streamable HTTP transport. - [MCP server portals](https://docs.ahq.lat/cloudflare-one/access-controls/ai-controls/mcp-portals/index.md): Centralize multiple MCP servers onto a single endpoint and customize the tools, prompts, and resources available to users. - [Cloudflare's own MCP servers](https://docs.ahq.lat/agents/model-context-protocol/cloudflare/servers-for-cloudflare/index.md): Connect to Cloudflare's managed remote MCP servers to read configurations, manage services, and automate actions across your account. - [Cloudflare Community MCP Server](https://docs.ahq.lat/agents/model-context-protocol/cloudflare/servers-for-cloudflare/community-mcp-server/index.md): Learn how to use the Cloudflare Community MCP server to search topics, read posts, and filter content. - [Connect to an MCP server](https://docs.ahq.lat/agents/model-context-protocol/guides/connect-mcp-client/index.md): Create a Cloudflare Agent that connects to an external MCP server and uses its tools. - [Handle OAuth with MCP servers](https://docs.ahq.lat/agents/model-context-protocol/guides/oauth-mcp-client/index.md): Implement OAuth authentication flows in Cloudflare Agents to connect to protected MCP servers. - [Build a Remote MCP server](https://docs.ahq.lat/agents/model-context-protocol/guides/remote-mcp-server/index.md): Deploy a remote MCP server on Cloudflare with optional authentication using Streamable HTTP transport. - [Securing MCP servers](https://docs.ahq.lat/agents/model-context-protocol/guides/securing-mcp-server/index.md): Secure your MCP servers with OAuth 2.1, token validation, and scope-based access control on Cloudflare. - [Test a Remote MCP Server](https://docs.ahq.lat/agents/model-context-protocol/guides/test-remote-mcp-server/index.md): Test your remote MCP server using the MCP Inspector and compatible MCP clients. - [Authorization](https://docs.ahq.lat/agents/model-context-protocol/protocol/authorization/index.md): Add OAuth 2.1 authorization to your MCP server using Cloudflare Access, third-party providers, or your own identity system. - [Codemode](https://docs.ahq.lat/agents/model-context-protocol/protocol/codemode/index.md): Let LLMs write and execute JavaScript to orchestrate multiple tool calls in a secure sandbox using Codemode. - [MCP governance](https://docs.ahq.lat/agents/model-context-protocol/protocol/governance/index.md): Control which MCP servers your organization uses and enforce access policies with Cloudflare Access. - [Tools](https://docs.ahq.lat/agents/model-context-protocol/protocol/tools/index.md): Define, register, and manage MCP tools that expose server-side functions for AI agents to call. - [Transport](https://docs.ahq.lat/agents/model-context-protocol/protocol/transport/index.md): Configure Streamable HTTP transport for remote MCP servers built with the Agents SDK. ## communication-channels - [Autonomous responses](https://docs.ahq.lat/agents/communication-channels/chat/autonomous-responses/index.md): Send server-initiated messages and trigger LLM responses from Cloudflare Agents without user action. - [Chat agents](https://docs.ahq.lat/agents/communication-channels/chat/chat-agents/index.md): Build AI chat interfaces with AIChatAgent and useAgentChat, including message persistence, streaming, and tool support. - [Client SDK](https://docs.ahq.lat/agents/communication-channels/chat/client-sdk/index.md): Connect to Cloudflare Agents from browsers or server runtimes using useAgent, AgentClient, and agentFetch. - [Email](https://docs.ahq.lat/agents/communication-channels/email/index.md): Connect agents to email so they can send outbound messages, process inbound mail, and handle follow-up replies. - [Slack](https://docs.ahq.lat/agents/communication-channels/slack/index.md): Connect agents to Slack workspaces so they can respond to direct messages, mentions, and threaded conversations. - [Voice](https://docs.ahq.lat/agents/communication-channels/voice/index.md): Build real-time voice agents with speech-to-text, text-to-speech, and conversation persistence over WebSocket. - [Webhooks](https://docs.ahq.lat/agents/communication-channels/webhooks/index.md): Receive and route webhook events from external services to dedicated Cloudflare Agent instances. - [Push notifications](https://docs.ahq.lat/agents/communication-channels/webhooks/push-notifications/index.md): Send browser push notifications from a Cloudflare Agent, even when the user has closed the tab. ## concepts - [Agentic patterns](https://docs.ahq.lat/agents/concepts/agentic-patterns/index.md): Implement common AI agent patterns like prompt chaining, routing, parallelization, and orchestrator-workers on Cloudflare. - [Human-in-the-loop patterns](https://docs.ahq.lat/agents/concepts/agentic-patterns/human-in-the-loop/index.md): Implement human-in-the-loop functionality using Cloudflare Agents for workflow approvals and MCP elicitation - [Long-running agents](https://docs.ahq.lat/agents/concepts/agentic-patterns/long-running-agents/index.md): Build agents that persist for days, weeks, or months — surviving restarts, waking on demand, and managing work that spans far longer than any single request. - [Calling LLMs](https://docs.ahq.lat/agents/concepts/calling-llms/index.md): Call large language models from within a stateful Cloudflare Agent with persistent context and autonomous scheduling. - [Conversation state and memory](https://docs.ahq.lat/agents/concepts/conversation-state-and-memory/index.md): How agents store and recall information, including read-only context, writable short-form memory, searchable knowledge, and on-demand skills. - [Tools](https://docs.ahq.lat/agents/concepts/tools/index.md): Define and use tools in Cloudflare Agents to interact with external APIs, process data, and perform actions. - [What are agents?](https://docs.ahq.lat/agents/concepts/what-are-agents/index.md): Understand what Agents are, how they differ from workflows and co-pilots, and when to use them. - [Using Agents with Workflows](https://docs.ahq.lat/agents/concepts/workflows/index.md): Integrate Cloudflare Workflows with Agents for durable, multi-step background processing with automatic retries. ## examples - [Browser agent](https://docs.ahq.lat/agents/examples/browser-agent/index.md): Build an agent that uses Browser Run tools to inspect pages, capture screenshots, scrape rendered content, and debug frontend issues. - [Chat agent](https://docs.ahq.lat/agents/examples/chat-agent/index.md): Build a streaming AI chat agent with tools using Workers AI — no API keys required. - [Email agent](https://docs.ahq.lat/agents/examples/email-agent/index.md): Build an agent that sends, receives, routes, and replies to email using Cloudflare Email Service and the Agents SDK. - [Slack agent](https://docs.ahq.lat/agents/examples/slack-agent/index.md): Build and deploy an AI-powered Slack bot on Cloudflare Workers using the Agents SDK. - [Voice agent](https://docs.ahq.lat/agents/examples/voice-agent/index.md): Build a real-time voice agent with speech-to-text, LLM processing, and text-to-speech on Cloudflare Workers. ## getting-started - [Add to existing project](https://docs.ahq.lat/agents/getting-started/add-to-existing-project/index.md): Add the Agents SDK to an existing Cloudflare Workers project with state management and real-time connections. - [Quick start](https://docs.ahq.lat/agents/getting-started/quick-start/index.md): Build your first agent in 10 minutes — a counter with persistent state that syncs to a React frontend in real-time. - [Testing your Agents](https://docs.ahq.lat/agents/getting-started/testing-your-agent/index.md): Write and run tests for Cloudflare Agents using Vitest and the Workers test pool. ## platform - [Limits](https://docs.ahq.lat/agents/platform/limits/index.md): Understand the concurrency, storage, and compute time limits that apply to Cloudflare Agents. ## runtime - [Agents API](https://docs.ahq.lat/agents/runtime/agents-api/index.md): Reference for the Agent base class, lifecycle hooks, SQL storage, and error handling in the Agents SDK. - [HTTP and Server-Sent Events](https://docs.ahq.lat/agents/runtime/communication/http-sse/index.md): Handle HTTP requests and stream responses with Server-Sent Events (SSE) from Cloudflare Agents. - [Protocol messages](https://docs.ahq.lat/agents/runtime/communication/protocol-messages/index.md): Control the identity, state, and MCP protocol messages sent to WebSocket clients on Agent connect. - [Readonly connections](https://docs.ahq.lat/agents/runtime/communication/readonly-connections/index.md): Restrict WebSocket clients to view-only access so they receive state updates without modifying Agent state. - [Routing](https://docs.ahq.lat/agents/runtime/communication/routing/index.md): Route HTTP and WebSocket requests to Agents SDK instances using routeAgentRequest() and getAgentByName(). - [WebSockets](https://docs.ahq.lat/agents/runtime/communication/websockets/index.md): Handle real-time WebSocket connections, messages, broadcasts, and lifecycle hooks in the Agents SDK. - [Agent Skills](https://docs.ahq.lat/agents/runtime/execution/agent-skills/index.md): Give an agent a catalog of on-demand instructions, resources, and scripts with agents/skills, activated by the model only when a task matches. - [Agent tools](https://docs.ahq.lat/agents/runtime/execution/agent-tools/index.md): Run Think and AIChatAgent sub-agents as retained, streaming tools from a parent agent. - [Chat SDK](https://docs.ahq.lat/agents/runtime/execution/chat-sdk/index.md): Integrate Chat SDK with Agents, including durable state for subscriptions, locks, queues, and message history. - [Durable execution with fibers](https://docs.ahq.lat/agents/runtime/execution/durable-execution/index.md): Run work that survives Durable Object eviction with runFiber(), startFiber(), keepAlive(), and crash recovery. - [Queue tasks](https://docs.ahq.lat/agents/runtime/execution/queue-tasks/index.md): Add background tasks to a built-in FIFO queue for asynchronous processing within Cloudflare Agents. - [Retries](https://docs.ahq.lat/agents/runtime/execution/retries/index.md): Retry failed operations with exponential backoff and jitter using the built-in retry system in the Agents SDK. - [Run Workflows](https://docs.ahq.lat/agents/runtime/execution/run-workflows/index.md): Integrate Cloudflare Workflows with Agents for durable, multi-step background processing and failure recovery. - [Schedule tasks](https://docs.ahq.lat/agents/runtime/execution/schedule-tasks/index.md): Schedule delayed, date-based, cron, and interval tasks on Agents with persistent SQLite-backed execution. - [Sub-agents](https://docs.ahq.lat/agents/runtime/execution/sub-agents/index.md): Spawn child agents with isolated storage and typed RPC using subAgent(), abortSubAgent(), and deleteSubAgent(). - [Agent class internals](https://docs.ahq.lat/agents/runtime/lifecycle/agent-class/index.md): Explore how the Agent class extends Durable Objects to provide state, WebSockets, scheduling, and RPC. - [Callable methods](https://docs.ahq.lat/agents/runtime/lifecycle/callable-methods/index.md): Expose Agent methods to external clients over WebSocket RPC using the @callable() decorator. - [getCurrentAgent()](https://docs.ahq.lat/agents/runtime/lifecycle/get-current-agent/index.md): Access the current Agent context from external utility functions using getCurrentAgent() in the Agents SDK. - [Sessions](https://docs.ahq.lat/agents/runtime/lifecycle/sessions/index.md): Persistent conversation storage with tree-structured messages, context blocks, compaction, full-text search, and AI-controllable tools. - [Store and sync state](https://docs.ahq.lat/agents/runtime/lifecycle/state/index.md): Persist and sync Agent state across clients in real time using setState, SQL storage, and bidirectional updates. - [Configuration](https://docs.ahq.lat/agents/runtime/operations/configuration/index.md): Configure Wrangler bindings, environment variables, and type generation for a project using the Agents SDK. - [Cross-domain authentication](https://docs.ahq.lat/agents/runtime/operations/cross-domain-authentication/index.md): Authenticate WebSocket connections to Cloudflare Agents across domains using signed tokens. - [Observability](https://docs.ahq.lat/agents/runtime/operations/observability/index.md): Subscribe to structured Agent events for RPC calls, state changes, schedules, workflows, and MCP connections via diagnostics channels. - [Using AI Models](https://docs.ahq.lat/agents/runtime/operations/using-ai-models/index.md): Call AI models from Workers AI, OpenAI, Anthropic, Google Gemini, or any provider within Cloudflare Agents. ## tools - [AI Search](https://docs.ahq.lat/agents/tools/ai-search/index.md): Give agents retrieval capabilities with Cloudflare AI Search. - [Browser](https://docs.ahq.lat/agents/tools/browser/index.md): Give Agents full Chrome DevTools Protocol access to inspect pages, scrape data, and capture screenshots with Browser Run. - [MCP](https://docs.ahq.lat/agents/tools/mcp/index.md): Connect agents to external Model Context Protocol servers and use their tools in model calls. - [Agentic Payments](https://docs.ahq.lat/agents/tools/payments/index.md): Let AI agents pay for services programmatically using payment protocols like MPP and x402 with Cloudflare's Agents SDK. - [MPP (Machine Payments Protocol)](https://docs.ahq.lat/agents/tools/payments/mpp/index.md): Accept and make payments using the Machine Payments Protocol (MPP) on Cloudflare Workers. - [Charge for HTTP content](https://docs.ahq.lat/agents/tools/payments/mpp-charge-for-http-content/index.md): Gate HTTP endpoints with MPP payments using the mpp-proxy template on Cloudflare Workers. - [x402](https://docs.ahq.lat/agents/tools/payments/x402/index.md): Accept and make machine-to-machine payments using the x402 HTTP payment protocol on Cloudflare Workers and the Agents SDK. - [Charge for HTTP content](https://docs.ahq.lat/agents/tools/payments/x402/charge-for-http-content/index.md): Gate HTTP endpoints with x402 payments using a Cloudflare Worker proxy. - [Charge for MCP tools](https://docs.ahq.lat/agents/tools/payments/x402/charge-for-mcp-tools/index.md): Charge per tool call in an MCP server using paidTool. - [Pay from Agents SDK](https://docs.ahq.lat/agents/tools/payments/x402/pay-from-agents-sdk/index.md): Use withX402Client to pay for resources from a Cloudflare Agent. - [Pay from coding tools](https://docs.ahq.lat/agents/tools/payments/x402/pay-with-tool-plugins/index.md): Add x402 payment handling to OpenCode and Claude Code. - [Sandbox](https://docs.ahq.lat/agents/tools/sandbox/index.md): Give agents isolated Linux environments for running code, managing files, and executing commands.