cloudflare-agents

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cloudflare Agents

Cloudflare Agents

Last Updated: 2025-11-21
最后更新时间: 2025-11-21

Quick Start

快速开始

typescript
export default {
  async fetch(request, env, ctx) {
    const agent = {
      tools: [
        { name: 'getTodo', handler: async ({id}) => ({id, title: 'Task'}) }
      ],
      async run(input) {
        return await processWithLLM(input, this.tools);
      }
    };
    
    return Response.json(await agent.run(await request.text()));
  }
};
typescript
export default {
  async fetch(request, env, ctx) {
    const agent = {
      tools: [
        { name: 'getTodo', handler: async ({id}) => ({id, title: 'Task'}) }
      ],
      async run(input) {
        return await processWithLLM(input, this.tools);
      }
    };
    
    return Response.json(await agent.run(await request.text()));
  }
};

Core Features

核心功能

  • Tool Integration: Register and execute tools
  • LLM Providers: OpenAI, Anthropic, Google Gemini
  • MCP Protocol: Model Context Protocol support
  • Cloudflare Bindings: D1, KV, R2, Durable Objects
  • 工具集成:注册并执行工具
  • 大语言模型提供商:OpenAI、Anthropic、Google Gemini
  • MCP协议:支持Model Context Protocol
  • Cloudflare绑定:D1、KV、R2、Durable Objects

Agent Pattern

Agent模式

typescript
const agent = {
  tools: [...],
  systemPrompt: 'You are a helpful assistant',
  model: 'gpt-4o',
  async run(input) {
    // Process with LLM
  }
};
typescript
const agent = {
  tools: [...],
  systemPrompt: 'You are a helpful assistant',
  model: 'gpt-4o',
  async run(input) {
    // Process with LLM
  }
};

Resources

资源

Core Documentation

核心文档

  • references/patterns-concepts.md
    (317 lines) - What is Cloudflare Agents, patterns & concepts, critical rules, known issues prevention
  • references/configuration-guide.md
    (152 lines) - Complete configuration deep dive
  • references/agent-api.md
    (115 lines) - Complete Agent Class API reference
  • references/patterns-concepts.md
    (317行)- 什么是Cloudflare Agent、模式与概念、关键规则、已知问题预防
  • references/configuration-guide.md
    (152行)- 完整配置深度解析
  • references/agent-api.md
    (115行)- 完整Agent类API参考

Integration Guides

集成指南

  • references/http-sse-guide.md
    (74 lines) - HTTP & Server-Sent Events
  • references/websockets-guide.md
    (110 lines) - WebSocket integration
  • references/state-management.md
    (388 lines) - State management, scheduled tasks, workflows
  • references/mcp-integration.md
    (130 lines) - Model Context Protocol integration
  • references/http-sse-guide.md
    (74行)- HTTP与Server-Sent Events
  • references/websockets-guide.md
    (110行)- WebSocket集成
  • references/state-management.md
    (388行)- 状态管理、定时任务、工作流
  • references/mcp-integration.md
    (130行)- Model Context Protocol集成

Advanced Features

高级功能

  • references/advanced-features.md
    (637 lines) - Browser automation, RAG, AI model integration, calling agents, client APIs
  • references/advanced-features.md
    (637行)- 浏览器自动化、RAG、AI模型集成、Agent调用、客户端API

Error Reference

错误参考

  • references/error-catalog.md
    (10 lines) - Common errors and solutions
  • references/error-catalog.md
    (10行)- 常见错误及解决方案

Templates

模板

  • templates/basic-agent.ts
    - Basic agent setup
  • templates/browser-agent.ts
    - Browser automation
  • templates/calling-agents-worker.ts
    - Calling other agents
  • templates/chat-agent-streaming.ts
    - Streaming chat agent
  • templates/hitl-agent.ts
    - Human-in-the-loop
  • templates/mcp-server-basic.ts
    - MCP server integration
  • templates/rag-agent.ts
    - RAG implementation
  • templates/react-useagent-client.tsx
    - React client integration
  • templates/scheduled-agent.ts
    - Scheduled tasks
  • templates/state-sync-agent.ts
    - State synchronization
  • templates/websocket-agent.ts
    - WebSocket agent
  • templates/workflow-agent.ts
    - Workflows integration
  • templates/wrangler-agents-config.jsonc
    - Wrangler configuration
  • templates/basic-agent.ts
    - 基础Agent搭建
  • templates/browser-agent.ts
    - 浏览器自动化
  • templates/calling-agents-worker.ts
    - 调用其他Agent
  • templates/chat-agent-streaming.ts
    - 流式聊天Agent
  • templates/hitl-agent.ts
    - 人在回路(Human-in-the-loop)
  • templates/mcp-server-basic.ts
    - MCP服务器集成
  • templates/rag-agent.ts
    - RAG实现
  • templates/react-useagent-client.tsx
    - React客户端集成
  • templates/scheduled-agent.ts
    - 定时任务
  • templates/state-sync-agent.ts
    - 状态同步
  • templates/websocket-agent.ts
    - WebSocket Agent
  • templates/workflow-agent.ts
    - 工作流集成
  • templates/wrangler-agents-config.jsonc
    - Wrangler配置