MIT License

项目介绍

cloudflare/agents 是一个托管在 GitHub 上的开源项目,主要使用 TypeScript 编写,采用 MIT License 许可证,目前获得 6.0k 个 Star、834 次 Fork。

仓库全名
cloudflare/agents
开源许可证
MIT License
Star 数
6.0k
Fork 数
834
未关闭 Issue
204

README 摘要

Cloudflare 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 —…

完整内容见 GitHub 原始 README 或本页 。

常见问题

agents 用什么语言开发?

主要使用 TypeScript 编写,采用 MIT License 许可证,目前有 6.0k 个 Star。

agents 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 agents 的源码?

可以直接克隆仓库:git clone https://github.com/cloudflare/agents.git;安装与运行步骤见仓库 README。

agents 最近还在维护吗?

仓库最近一次更新为 15 小时前,当前有 204 个未关闭 Issue;Star 数为 6.0k,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

Build and deploy AI Agents on Cloudflare

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
7665
价值分
3821
活跃状态
活跃

语言占比

Astro
CSS
Dockerfile
HTML
JavaScript
Shell
TypeScript

README

Cloudflare Agents

npm version npm downloads

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.

Quick Example

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<Env, CounterState> {
  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<CounterAgent, CounterState>({
    agent: "CounterAgent",
    onStateUpdate: (state) => setCount(state.count)
  });

  return (
    <div>
      <span>{count}</span>
      <button => agent.stub.increment()}>+</button>
      <button => agent.stub.decrement()}>-</button>
    </div>
  );
}

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

Feature Description
Persistent State Syncs to all connected clients, survives restarts
Callable Methods Type-safe RPC via the @callable() decorator
Sub-agents Parent/child DO composition via facets, nested routing, and typed parent lookup
Agent Tools Run chat-capable sub-agents as tools with streaming child timelines
Scheduling One-time, recurring, and cron-based tasks
WebSockets Real-time bidirectional communication with lifecycle hooks
AI Chat Message persistence, resumable streaming, server/client tool execution
MCP Act as MCP servers or connect as MCP clients (HTTP, SSE, RPC, elicitation)
WebMCP Expose page-local tools or bridge remote MCP tools to browser agents
Workflows Durable multi-step tasks with human-in-the-loop approval
Email Send, receive, and reply via Cloudflare Email Service
Voice Continuous STT, streaming TTS, VAD, interruption, SFU utilities
Browser Agents Run agents in the browser tab with agents/browser
Code Mode LLMs generate executable TypeScript instead of individual tool calls
Sandboxed Execution Run generated code inside an isolated Worker with a virtual filesystem
x402 Payments Pay-per-call APIs and tools via the x402 protocol
Observability Built-in tracing, metrics, and structured logs
SQL Direct SQLite queries via Durable Objects
React Hooks useAgent, useAgentChat, useVoiceAgent for frontend integration
Vanilla JS Client AgentClient and VoiceClient for non-React environments

Packages

Package Description
agents Core SDK — Agents, routing, Voice, Channels, scheduling, MCP, workflows, x402, browser agents
@cloudflare/ai-chat Higher-level AI chat — persistent messages, resumable streaming, tool execution
@cloudflare/think Opinionated chat agent base — agentic loop, stream resumption, client tools, workspace tools
@cloudflare/codemode LLMs write executable code that calls your tools, instead of one tool call at a time
@cloudflare/shell Deprecated: use @cloudflare/computer workspaces
@cloudflare/voice Deprecated compatibility wrapper for the agents/voice exports
@cloudflare/worker-bundler Build and bundle Workers at runtime, for use with the Worker Loader binding
hono-agents Hono middleware for adding agents to Hono apps

AI-chat modules used to live in agents/ai-chat-agent, agents/chat, agents/ai-react, and agents/ai-types. Those entry points still re-export, but they’re deprecated — import from @cloudflare/ai-chat directly. New chat-from-scratch projects should look at @cloudflare/think.

Examples

The examples/ directory has 30+ self-contained demos. A non-exhaustive tour:

Examples using the OpenAI Agents SDK live in openai-sdk/. Work-in-progress experiments live in experimental/ (no stability guarantees).

Run any example locally:

cd examples/playground
npm start

Documentation

Repository Structure

Directory Description
packages/agents/ Core SDK
packages/ai-chat/ AI chat layer
packages/think/ Opinionated chat agent base
packages/codemode/ Code Mode
packages/shell/ Deprecated sandboxed execution + filesystem
packages/voice/ Deprecated Voice compatibility wrapper
packages/worker-bundler/ Runtime Workers bundler
packages/hono-agents/ Hono integration
examples/ Self-contained demo apps
experimental/ Work-in-progress experiments (not published)
openai-sdk/ Examples using the OpenAI Agents SDK
guides/ In-depth pattern tutorials
docs/ Markdown docs synced to developers.cloudflare.com
site/ Deployed websites (agents.cloudflare.com, AI playground)
design/ Architecture and design decision records
scripts/ Repo-wide tooling

Development

Node 24+ required. pnpm workspaces with Nx for task orchestration, caching, and affected detection.

pnpm install                 # install all workspaces
pnpm run build               # build all packages (Nx, cached, dependency-ordered)
pnpm run check               # sherif + export checks + oxfmt + oxlint + typecheck
pnpm run test                # vitest + vitest-pool-workers (Workers runtime)
pnpm run test:react          # Playwright-based React hook tests
pnpm exec nx affected -t build # build only what changed
pnpm exec nx affected -t test  # test only what changed

Changes to packages/ need a changeset:

pnpm exec changeset

See AGENTS.md for deeper contributor guidance.

Contributing

We are not accepting external pull requests at this time — the SDK is evolving quickly and we want to keep the surface area manageable. That said, we’d love to hear from you:

License

MIT

评论

暂无评论