Agents SDK

What is it?

The Agents SDK is Cloudflare's framework for building stateful AI agents that run on Workers. While Workers AI provides the "brain" (running AI models), the Agents SDK provides the "body" — state management, tool calling, real-time communication (WebSockets), scheduled tasks, and persistent memory. It's how you build AI agents that can remember context, take actions, and interact with users in real-time.

What problem does it solve?

Building AI agents is more than just calling an LLM. A real agent needs:

  • State management: Agents need to remember conversation history, user preferences, and task context across interactions.
  • Tool calling: Agents need to take actions — search the web, query databases, send emails, call APIs. These tools need to be defined, managed, and secured.
  • Real-time communication: Chat interfaces need WebSocket connections for streaming responses and real-time updates.
  • Durability: If an agent is in the middle of a multi-step task and the server restarts, it shouldn't lose its progress.
  • Scheduling: Agents might need to perform tasks on a schedule (check for updates every hour, send daily summaries).

Without the Agents SDK, developers would need to stitch together multiple separate systems (database, WebSocket server, job scheduler, state machine) — a significant engineering effort.

How does it work?

The Agents SDK is built on top of Durable Objects (for state and coordination) and Workers (for compute). Here's what it provides:

  1. Agent class: Extend the Agent base class to create your agent. It automatically handles state persistence, WebSocket connections, and lifecycle management.
  2. State management: The agent has a built-in state object (backed by SQLite) that persists automatically. No database setup required.
  3. Tool definitions: Define tools (functions the agent can call) using a structured format that LLMs understand. Support human-in-the-loop approval for sensitive actions.
  4. WebSocket support: Built-in WebSocket handling for real-time chat interfaces.
  5. React hooks: useAgentChat() — a React hook that connects a frontend chat UI to your agent with one line of code.
  6. Scheduling: Built-in support for cron-like scheduled tasks.

Example use cases:

  • A customer support agent that can look up orders, process refunds, and escalate to humans
  • A coding assistant that can read files, run tests, and commit code
  • A research agent that searches the web, summarizes findings, and creates reports

Why it matters strategically

The Agents SDK is central to Cloudflare's Act 4 vision. Cloudflare is betting that AI agents will be the next major computing paradigm — and they want to be the infrastructure that agents run on. The SDK makes it significantly easier to build agents on Cloudflare than on any other platform, creating developer adoption and platform lock-in. It's also a pull-through product: agents built with the SDK naturally use Workers AI, Durable Objects, D1, R2, and Workflows.

Learn more