Agents

Persistent, stateful AI agents on Cloudflare Durable Objects with real-time sync

Framework
npm
v0.21.0
5,458stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
88/100Excellent
Development Activity100
Maintenance100
Community72
Maturity40
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
84/100Excellent
Architecture88
Code Quality85
Innovation85
Learning Curve78

Agents is Cloudflare’s SDK for building persistent, stateful execution environments for agentic workloads, built directly on top of Durable Objects. Instead of treating an agent as a stateless function call, each agent instance is a long-lived object with its own private storage, SQLite database, and lifecycle — it hibernates when idle and wakes on demand, so you can run millions of independent agents (one per user, per session, per game room) while paying nothing for inactive ones.

The framework provides the Agent base class along with request routing, WebSocket connection handling, scheduling (one-time, recurring, and cron), and a @callable() decorator for exposing type-safe RPC methods that a React frontend can call as if they were local functions, with state changes synced automatically to every connected client. Beyond the core primitives it bundles first-party building blocks for AI chat (message persistence, resumable streaming), MCP client/server support, durable multi-step workflows with human-in-the-loop approval, sandboxed code execution, and voice pipelines, making it a full toolkit for shipping agentic products on Cloudflare’s edge platform.

What You Get

  • An Agent base class with persistent state, setState(), and automatic real-time sync of state changes to every connected client
  • Type-safe RPC via the @callable() decorator, so client code can call server agent methods as if they were local functions
  • Built-in WebSocket handling with lifecycle hooks, plus request routing (routeAgentRequest) for wiring agents into a Worker
  • One-time, recurring, and cron-based task scheduling that survives Worker restarts
  • First-party MCP support — agents can act as MCP servers or connect as MCP clients over HTTP, SSE, or RPC
  • Durable multi-step workflows with human-in-the-loop approval, plus companion packages for AI chat, sandboxed code execution, and voice pipelines

Common Use Cases

  • Per-user or per-session AI chat assistants that need durable conversation state and resumable streaming
  • Multiplayer or collaborative apps (games, shared documents) where each room/session is its own stateful agent
  • Long-running agentic workflows that call tools, wait on human approval, and must survive process restarts
  • MCP servers and clients that need persistent connection state and OAuth-backed authentication

Under The Hood

Architecture - The core (packages/agents/src/index.ts) wraps Cloudflare’s partyserver Server class to build the Agent base class: incoming requests are routed via routeAgentRequest/routePartykitRequest to a named Durable Object instance, state mutations flow through setState() and are broadcast to connected Connection/WebSocket clients, and @callable()-decorated methods are exposed as RPC targets via cloudflare:workersRpcTarget. Scheduling (schedule.ts), MCP client/server support (src/mcp/), sub-agent routing (sub-routing.ts), and workflow tracking (workflow-types.ts) are layered on top of this same Durable Object primitive, with companion packages (@cloudflare/ai-chat, @cloudflare/think, @cloudflare/codemode, @cloudflare/shell, @cloudflare/voice) building higher-level features on the same base class.

Tech Stack - Pure TypeScript (98.8% of the repo) built with esbuild/Rolldown, targeting the Cloudflare Workers runtime. Core dependencies include partyserver/partysocket for WebSocket routing, @modelcontextprotocol/sdk for MCP, cron-schedule for scheduling, nanoid for IDs, and zod for schema validation; React integration is an optional peer dependency (@ai-sdk/react, react) consumed via agents/react.

Code Quality - The packages/agents package alone ships 118 *.test.ts files covering core routing, MCP, scheduling, retries, and chat, run via Vitest (including @vitest/browser-playwright for browser-context tests). Naming is consistent (Agent, AgentClient, useAgent) and the retries module (retries.ts) explicitly models Cloudflare-specific transient failure classes (isDurableObjectCodeUpdateReset, isPlatformTransientError), indicating deliberate handling of Durable Object edge cases rather than generic try/catch.

API Design - Getting started is a single npm install agents plus extending the Agent class and adding a Durable Object binding in wrangler.jsonc; the @callable() decorator and useAgent hook let client code call server methods as plain function calls, which is a notably low-boilerplate developer experience for a stateful, real-time system. The large surface area (30+ example apps, many sub-packages) trades off some discoverability for breadth.

Used by 5 apps in this directory

TypeScript
100%
Apache 2.0

agentic-inbox

AI Agents · Productivity

6,880

A self-hosted email client with an AI agent that reads your inbox, drafts replies automatically, and exposes full email operations over MCP — running entirely on Cloudflare Workers.

View details
32
Repo Health
74
Technical
77
Dependency
Built with
TypeScript100%
Updated 3 months ago
TypeScript
93%
Apache 2.0

flue

AI Agents · Developer Tools

7,953

Build autonomous AI agents and powerful workflows with a programmable TypeScript harness that gives any model sessions, tools, sandboxes, and durable execution.

View details
67
Repo Health
82
Technical
75
Dependency
Built with
TypeScript93%
Updated 1 weeks ago
TypeScript
98%
Other

Novu

Developer Tools

39,615

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
65
Dependency
Built with
TypeScript98%
Updated today
TypeScript
96%
MIT

open-seo

Marketing · Developer Tools

12,596

Pay-as-you-go open source SEO platform with MCP integration — keyword research, rank tracking, backlinks, site audits, and AI brand visibility in one self-hosted tool.

View details
83
Repo Health
79
Technical
78
Dependency
Built with
TypeScript96%
Updated today
TypeScript
77%
MIT

supermemory

AI Development · Productivity · Note Taking

28,954

The state-of-the-art memory and context engine for AI agents — ranked #1 on all three major AI memory benchmarks.

View details
88
Repo Health
82
Technical
69
Dependency
Built with
TypeScript77%
MDX17%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search