The Cloudflare Agents SDK builds agents as Cloudflare Durable Objects. Each agent is a persistent, stateful instance with its own storage and lifecycle, and it hibernates when idle and wakes on demand, so an app can run one agent per user, per session, or per game room without paying for inactive ones. An agent class declares its state and its callable methods, a router directs requests to the right instance, and state changes sync automatically to every connected client.
Around that core, the SDK covers the pieces an agent app tends to need: scheduled and cron tasks, WebSockets, AI chat with message persistence and resumable streaming, durable multi-step workflows with human approval, email, and voice with continuous speech-to-text and streaming text-to-speech. Agents can act as MCP servers or connect to MCP servers as clients, compose sub-agents, and run chat-capable sub-agents as tools. Code Mode has the model write executable TypeScript that calls your tools instead of issuing one tool call at a time, and that code runs in an isolated Worker with a virtual filesystem.
The project ships as several packages: the core agents SDK, a higher-level AI chat layer, Think (an opinionated chat agent base with an agentic loop), Code Mode, a sandboxed shell, a runtime Worker bundler, and Hono middleware. React hooks and a vanilla JavaScript client connect frontends, and more than 30 example apps cover chat, MCP, voice, workflows, payments, and games. Guides cover Anthropic's agent patterns (sequential, routing, parallel, orchestrator, and evaluator) and human-in-the-loop approval.
Features
- Persistent state: survives restarts and syncs to all connected clients
- Callable methods: type-safe RPC through a decorator, called from the client like local functions
- Sub-agents: parent and child Durable Object composition with nested routing
- Scheduling: one-time, recurring, and cron-based tasks
- AI chat: message persistence, resumable streaming, and server or client tool execution
- MCP: act as an MCP server or connect as a client over HTTP, SSE, or RPC, plus WebMCP for browser agents
- Workflows: durable multi-step tasks with human-in-the-loop approval
- Voice and email: continuous STT, streaming TTS, and interruption handling, plus sending and replying to email
- Code Mode: the model writes TypeScript that calls tools, run inside an isolated Worker
- x402 payments: pay-per-call APIs and tools through the x402 protocol
- Observability and SQL: built-in tracing, metrics, and logs, plus direct SQLite queries
- Frontend clients: React hooks and a vanilla JavaScript client