SDK for building stateful AI agents on Cloudflare Workers and Durable Objects.
SDK for building stateful AI agents on Cloudflare Workers and Durable Objects.
Cloudflare Agents
npm install agents
Agents are persistent, stateful execution environments for agentic workloads, powered by Cloudflare Durable Objects. Each agent has its own state, storage, and lifecycle — with built-in support for real-time communication, scheduling, AI model calls, MCP, workflows, and more.
Agents hibernate when idle and wake on demand. You can run millions of them — one per user, per session, per game room — each costs nothing when inactive.
npm create cloudflare@latest -- --template cloudflare/agents-starter
Or add to an existing project:
npm install agents
Read the docs — getting started, API reference, guides, and more.
A counter agent with persistent state, callable methods, and real-time sync to a React frontend:
// server.ts
import { Agent, routeAgentRequest, callable } from "agents";
export type CounterState = { count: number };
export class CounterAgent extends Agent {
initialState = { count: 0 };
@callable()
increment() {
this.setState({ count: this.state.count + 1 });
return this.state.count;
}
@callable()
decrement() {
this.setState({ count: this.state.count - 1 });
return this.state.count;
}
}
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
return (
(await routeAgentRequest(request, env)) ??
new Response("Not found", { status: 404 })
);
}
};
// client.tsx
import { useAgent } from "agents/react";
import { useState } from "react";
import type { CounterAgent, CounterState } from "./server";
function Counter() {
const [count, setCount] = useState(0);
const agent = useAgent({
agent: "CounterAgent",
onStateUpdate: (state) => setCount(state.count)
});
return (
{count}
agent.stub.increment()}>+
agent.stub.decrement()}>-
);
}
State changes sync to all connected clients automatically. Call methods like they're local functions.
The agent is a Durable Object, so it needs a binding and a SQLite migration in wrangler.jsonc:
{
"name": "counter",
"main": "server.ts",
"compatibility_date": "2026-06-11",
"compatibility_flags": ["nodejs_compat"],
"durable_objects": {
"bindings": [{ "name": "CounterAgent", "class_name": "CounterAgent" }]
},
"migrations": [{ "tag": "v1", "new_sqlite_classes": ["CounterAgent"] }]
}
Features …
Agent framework · Agent frameworks / Agent SDK · Open Source · MIT · TypeScript
Website https://developers.cloudflare.com/agents/ · Repo https://github.com/cloudflare/agents · Docs https://developers.cloudflare.com/agents/
5,988 stars · 845 forks · 211 open issues · pushed 2026-11-11 · verified 2026-11-12
Tags: ai-agents, framework, agent-sdk
What is Cloudflare Agents SDK? Cloudflare Agents SDK is a coding tool listed on Scriptiii AI Tools. SDK for building stateful AI agents on Cloudflare Workers and Durable Objects. Pricing: Free. Free to use. Best for: ai-agents, framework, agent-sdk.
Everything you need to know about Cloudflare Agents SDK
Similar tools in Coding
Open-source vector database that stores objects and vectors with hybrid search and filtering.
Coding·Free