后端与接口
构建、调试或审查 Cloudflare Agents…
适用于使用 agents 包开发、调试或审查 Cloudflare Agents SDK 应用,避免依赖过时的预训练知识。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 38/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 60/100 ×0.15
适用场景
构建、调试或审查 Cloudflare 特定
解决思路
- 对任何 Agents SDK 任务,优先检索最新文档,而不是仅依赖预训练知识。
- 访问 Cloudflare Agents 文档总入口:https://developers.cloudflare.com/agents/。
- 首次创建 agent、项目搭建时,检索 Quick start:https://developers.cloudflare.com/agents/getting-started/quick-start/。
- 安装到已有 Workers app 时,检索 Add to existing project:https://developers.cloudflare.com/agents/getting-started/add-to-existing-project/。
- 配置 `wrangler.jsonc`、bindings、assets、deployment 时,检索 Configuration:https://developers.cloudflare.com/agents/api-reference/configuration/。
- 处理 Agent 生命周期、patterns、pitfalls 时,检索 Agents API:https://developers.cloudflare.com/agents/api-reference/agents-api/。
- 处理 `setState`、`validateStateChange`、persistence 时,检索 Store and sync state:https://developers.cloudflare.com/agents/api-reference/store-and-sync-state/。
- 处理 URL patterns、`routeAgentRequest` 时,检索 Routing:https://developers.cloudflare.com/agents/api-reference/routing/。
- 处理 `@callable`、RPC、streaming、timeouts 时,检索 Callable methods:https://developers.cloudflare.com/agents/api-reference/callable-methods/。
- 处理 `schedule()`、`scheduleEvery()`、cron 时,检索 Schedule tasks:https://developers.cloudflare.com/agents/api-reference/schedule-tasks/。
- 处理 `AgentWorkflow`、durable multi-step tasks 时,检索 Run workflows:https://developers.cloudflare.com/agents/api-reference/run-workflows/。
- 处理 Lifecycle hooks、hibernation 时,检索 WebSockets:https://developers.cloudflare.com/agents/api-reference/websockets/。
- 处理 `AIChatAgent`、streaming、tools、persistence 时,检索 Chat agents:https://developers.cloudflare.com/agents/communication-channels/chat/chat-agents/。
- 处理 `useAgent`、`AgentClient`、state、RPC、HTTP 时,检索 Client SDK:https://developers.cloudflare.com/agents/communication-channels/chat/client-sdk/。
- 处理 Client-side tools、`autoContinueAfterToolResult` 时,检索 Client tools:https://developers.cloudflare.com/agents/harnesses/think/client-tools/。
- 处理 `saveMessages`、`waitUntilStable`、server-initiated turns 时,检索 Autonomous responses:https://developers.cloudflare.com/agents/communication-channels/chat/autonomous-responses/。
- 处理断连后恢复流时,检索 Resumable streaming:https://developers.cloudflare.com/agents/communication-channels/chat/chat-agents/#resumable-streaming。
- 处理 Email routing、secure reply resolver 时,检索 Email:https://developers.cloudflare.com/agents/api-reference/email/。
- 连接 MCP servers 时,检索 MCP client:https://developers.cloudflare.com/agents/model-context-protocol/apis/client-api/。
- 用 `createMcpHandler` 构建 MCP servers 时,检索 MCP server:https://developers.cloudflare.com/agents/model-context-protocol/apis/handler-api/。
- 处理 Streamable HTTP、SSE、RPC transport options 时,检索 MCP transports:https://developers.cloudflare.com/agents/model-context-protocol/protocol/transport/。
- 处理 OAuth、proxy MCP、hardening 时,检索 Securing MCP:https://developers.cloudflare.com/agents/model-context-protocol/guides/securing-mcp-server/。
- 处理 Workflow approvals、elicitation、timeout handling 时,检索 Human-in-the-loop:https://developers.cloudflare.com/agents/concepts/agentic-patterns/human-in-the-loop/。
- 处理 `runFiber()`、`stash()`、surviving DO eviction 时,检索 Durable execution:https://developers.cloudflare.com/agents/api-reference/durable-execution/。
- 处理 Built-in FIFO queue、`queue()` 时,检索 Queue:https://developers.cloudflare.com/agents/api-reference/queue-tasks/。
- 处理 `this.retry()`、backoff/jitter 时,检索 Retries:https://developers.cloudflare.com/agents/api-reference/retries/。
- 处理 Diagnostics-channel events 时,检索 Observability:https://developers.cloudflare.com/agents/api-reference/observability/。
- 处理 Web Push + VAPID from agents 时,检索 Push notifications:https://developers.cloudflare.com/agents/communication-channels/webhooks/push-notifications/。
- 接收外部 webhooks 时,检索 Webhooks:https://developers.cloudflare.com/agents/communication-channels/webhooks/。
- 处理 WebSocket auth、tokens、CORS 时,检索 Cross-domain auth:https://developers.cloudflare.com/agents/runtime/operations/cross-domain-authentication/。
- 处理 `shouldConnectionBeReadonly` 时,检索 Readonly connections:https://developers.cloudflare.com/agents/api-reference/readonly-connections/。
- 处理 Experimental STT/TTS、`withVoice` 时,检索 Voice:https://developers.cloudflare.com/agents/api-reference/voice/。
- 处理 Experimental CDP browser automation 时,检索 Browser tools:https://developers.cloudflare.com/agents/api-reference/browse-the-web/。
- 处理 Experimental higher-level chat agent class 时,检索 Think:https://developers.cloudflare.com/agents/api-reference/think/。
- 升级 `@cloudflare/ai-chat` 时,检索 AI SDK v5 迁移文档:https://github.com/cloudflare/agents/blob/main/docs/agents/migration-to-ai-sdk-v5.md 和 AI SDK v6 迁移文档:https://github.com/cloudflare/agents/blob/main/docs/agents/migration-to-ai-sdk-v6.md。
- 使用 SQLite-backed persistent state,通过 `setState` 自动同步状态到 clients。
- 使用 `@callable()` 方法通过 WebSocket 暴露 callable RPC。
- 使用一次性、recurring(`scheduleEvery`)、cron tasks 实现 scheduling。
- 使用 `AgentWorkflow` 实现 durable multi-step background processing。
- 使用 `runFiber()` / `stash()` 实现能经受 DO eviction 的 durable execution。
- 使用 `queue()` 使用内置 FIFO queue 和 retries。
- 使用 `this.retry()` 实现 exponential backoff 和 jitter。
- 连接 MCP servers,或用 `createMcpHandler` 构建自己的 MCP。
- 使用 secure routing 接收和回复 emails。
- 使用 `AIChatAgent` 实现 streaming chat,包括 resumable streams、message persistence、tools。
- 使用 `saveMessages`、`waitUntilStable` 实现 server-driven messages 和 proactive agent turns。
- 在 client apps 中使用 `useAgent`、`useAgentChat` React hooks。
- 使用 `diagnostics_channel` events 观测 state、RPC、schedule、lifecycle。
- 从 agents 发送 Web Push + VAPID push notifications。
- 接收和验证 external webhooks。
- 实验性:使用 `@cloudflare/voice` 实现 STT/TTS voice。
- 实验性:使用 `agents/browser` 实现 CDP-powered browsing。
- 实验性:使用 `@cloudflare/think` 实现 higher-level chat agent。
- 先运行 `npm ls agents` 验证安装,应显示 agents package。
- 如果未安装,运行 `npm install agents`。
- 对于 chat agents,运行 `npm install agents @cloudflare/ai-chat ai @ai-sdk/react`。
- 在 Wrangler 配置中设置 `compatibility_flags`: `["nodejs_compat"]`。
- 在 Wrangler 配置中为每个 agent class 设置 `durable_objects.bindings`,例如 `[{ "name": "MyAgent", "class_name": "MyAgent" }]`。
- 在 Wrangler 配置中设置 `migrations`,例如 `[{ "tag": "v1", "new_sqlite_classes": ["MyAgent"] }]`。
- 不要在 tsconfig 中启用 `experimentalDecorators`,否则会破坏 `@callable`。
- 永远不要编辑旧 migrations,始终添加新 tags。
- 每个 agent class 都需要自己的 DO binding + migration entry。
- 如果使用 Workers AI,添加 `"ai": { "binding": "AI" }`。
- 从 `agents` 导入 `Agent`、`routeAgentRequest`、`callable`。
- 定义 `State` 类型并在 Agent 子类中设置 `initialState`。
- 实现 `validateStateChange(nextState, source)` 校验状态变更,例如禁止 count 为负。
- 实现 `onStateUpdate(state, source)` 监听状态更新。
- 用 `@callable()` 标记 RPC 方法,例如在 `increment()` 中调用 `this.setState`。
- 导出默认 `fetch`,使用 `routeAgentRequest(req, env) ?? new Response("Not found", { status: 404 })`。
- 理解请求路由到 `/agents/{agent-name}/{instance-name}`。
- 例如 `Counter` 路由到 `/agents/counter/user-123`,`ChatRoom` 路由到 `/agents/chat-room/lobby`。
- Client 使用 `useAgent({ agent: "Counter", name: "user-123" })`。
- 自定义路由:使用 `getAgentByName(env.MyAgent, "instance-id")`,然后调用 `agent.fetch(request)`。
- 读状态:`this.state.count`。
- 写状态:`this.setState({ count: 1 })`。
- SQL 查询:`this.sql`SELECT * FROM users WHERE id = ${id}``。
- Schedule(delay):`await this.schedule(60, "task", payload)`。
- Schedule(cron):`await this.schedule("0 * * * *", "task", payload)`。
- Schedule(interval):`await this.scheduleEvery(30, "poll")`。
- RPC method:`@callable() myMethod() { ... }`。
- Streaming RPC:`@callable({ streaming: true }) stream(res) { ... }`。
- 启动 workflow:`await this.runWorkflow("ProcessingWorkflow", params)`。
- Durable fiber:`await this.runFiber("name", async (ctx) => { ... })`。
- 入队工作:`this.queue("handler", payload)`。
- Retry with backoff:`await this.retry(fn, { maxAttempts: 5 })`。
- 广播给 clients:`this.broadcast(message)`。
- 获取 connections:`this.getConnections(tag?)`。
- 对于 client selection 和当前连接示例,阅读 `references/client-sdk.md`。
- 对于 chat UI 和 tools,还要阅读 `references/streaming-chat.md`。
- 处理 state persistence、scheduling、SQL 时,阅读 `references/state-scheduling.md`。
- 处理 RPC methods、streaming、timeouts 时,阅读 `references/callable.md`。
- 处理 URL patterns、custom routing、`getAgentByName` 时,阅读 `references/routing.md`。
- 处理 Wrangler config、bindings、Vite setup 时,阅读 `references/configuration.md`。
- 处理 AIChatAgent、resumable streams、tools 时,阅读 `references/streaming-chat.md`。
- 处理 `useAgent`、`useAgentChat`、`AgentClient` 时,阅读 `references/client-sdk.md`。
- 处理 trigger patterns、`saveMessages` 时,阅读 `references/server-driven-messages.md`。
- 处理 approval flows、`needsApproval` 时,阅读 `references/human-in-the-loop.md`。
- 处理 Durable Workflows integration 时,阅读 `references/workflows.md`。
- 处理 `runFiber`、`stash`、surviving eviction 时,阅读 `references/durable-execution.md`。
- 处理 built-in queue、retry with backoff 时,阅读 `references/queue-retries.md`。
- 处理 MCP client and server、transports、securing 时,阅读 `references/mcp.md`。
- 处理 email routing and handling 时,阅读 `references/email.md`。
- 处理 webhooks、push notifications 时,阅读 `references/webhooks-push.md`。
- 处理 diagnostics-channel events 时,阅读 `references/observability.md`。
- 实验性 Think:阅读 `references/think.md` 了解 `@cloudflare/think` higher-level chat agent。
- 实验性 Voice:阅读 `references/voice.md` 了解 `@cloudflare/voice` STT/TTS。
- 实验性 Code Mode:阅读 `references/codemode.md` 了解 tool orchestration。
- 实验性 Browse the web:阅读 `references/browse-the-web.md` 了解 CDP browser tools。
适用边界 · 注意事项
- 不适用于非 Cloudflare Workers / Cloudflare Agents SDK 的项目。
- 不适用于无法访问 Cloudflare 文档或无法安装 agents 包的环境。
- 如果只需要通用 LLM agent 框架且不使用 Cloudflare 平台,不适用。