SuperAPI AI 工具集

cloudflare-agents

智能体与模型

查看项目

更新于 10-15 15:11

技能介绍

Cloudflare Agents

本技能面向在 Cloudflare Workers 上构建 AI 智能体的开发场景,覆盖智能体核心概念、配置方式、API 参考与集成指南,并附带多类可直接参考的模板。文档最后更新时间为 2025-11-21。

用途

用于在 Cloudflare Workers 平台上构建 AI 智能体,结合 MCP 集成、工具使用与 LLM 提供商完成智能体应用的开发。

主要能力

  • 工具集成(Tool Integration):注册并执行工具。
  • LLM 提供商:支持 OpenAI、Anthropic、Google Gemini。
  • MCP 协议:支持 Model Context Protocol。
  • Cloudflare 绑定:D1、KV、R2、Durable Objects。

使用方式

快速开始示例(JavaScript):

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()));
  }
};

Agent 模式示例(TypeScript):

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

资料结构

核心文档

  • references/patterns-concepts.md(317 行)— Cloudflare Agents 是什么、模式与概念、关键规则、已知问题预防
  • references/configuration-guide.md(152 行)— 完整配置深入讲解
  • references/agent-api.md(115 行)— 完整 Agent 类 API 参考

集成指南

  • 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 集成

高级功能

  • references/advanced-features.md(637 行)— 浏览器自动化、RAG、AI 模型集成、调用智能体、客户端 API

错误参考

  • references/error-catalog.md(10 行)— 常见错误与解决方案

模板

  • templates/basic-agent.ts — 基础智能体搭建
  • templates/browser-agent.ts — 浏览器自动化
  • templates/calling-agents-worker.ts — 调用其他智能体
  • templates/chat-agent-streaming.ts — 流式聊天智能体
  • 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 智能体
  • templates/workflow-agent.ts — 工作流集成
  • templates/wrangler-agents-config.jsonc — Wrangler 配置

适用场景与限制

适用于在 Cloudflare Workers 上开发具备工具调用、多 LLM 提供商与 MCP 支持的智能体应用,并需要参考实现模板的场景。安装命令、具体配置参数细节、收费与价格信息未在当前资料中提供。