OpenAgents Logo
OpenAgentsDocumentation
Updates逐步教程 - 使用项目模板创建多智能体工具
Updated February 24, 2026

逐步教程 - 使用项目模板创建多智能体工具

了解如何构建一个协调的多智能体工作流,通过 MCP 暴露工具,以供 Claude Desktop 或其他 AI 助手查询。

操作指南:使用项目模板创建多智能体工具

本教程将教你如何构建一个通过 MCP 暴露工具的协同多智能体工作流。我们将以“替代服务查找器”(Alternative Service Finder)为例 —— 一个多个智能体协同工作以查找并比较网络服务替代方案的系统。

到最后,你将能够询问 Claude:

"为 Notion 寻找替代方案并进行比较"

并从你的多智能体系统中获得详细的比较结果!

你将学到什么

  • 如何使用 项目模板 来定义可重用的工作流
  • 如何 通过 MCP 暴露工具 以供外部访问
  • 如何 协调代理 编排多代理工作流
  • 如何将 Claude Desktop 连接到你的代理网络

架构概览

┌─────────────────────────────────────────────────────────────────┐
│                    OpenAgents Network                           │
│                                                                 │
│  ┌──────────────┐     ┌──────────────┐     ┌──────────────┐    │
│  │ Coordinator  │────>│   Searcher   │────>│   Comparer   │    │
│  │   (Python)   │     │    Agent     │     │    Agent     │    │
│  └──────────────┘     └──────────────┘     └──────────────┘    │
│         │                    │                    │             │
│         │                    ▼                    ▼             │
│         │             ┌──────────────┐     ┌──────────────┐    │
│         │             │  search_web  │     │ fetch_webpage │    │
│         │             │    (tool)    │     │    (tool)    │    │
│         │             └──────────────┘     └──────────────┘    │
│         │                                                       │
│         ▼                                                       │
│  ┌─────────────────────────────────────────────────────────┐   │
│  │              Project Template: find_alternatives         │   │
│  │         Exposed as: find_service_alternatives tool       │   │
│  └─────────────────────────────────────────────────────────┘   │
│                              │                                  │
│                           MCP ↓                                 │
└─────────────────────────────────────────────────────────────────┘

    ┌──────────────────────────┘

    │   ┌──────────────────┐
    └──>│  Claude Desktop  │ "Find alternatives to Slack"
        │    (via MCP)     │
        └──────────────────┘

第一步:设置您的 Python 环境

首先,确保您已安装 Python 3.10 或更高版本。

# Check your Python version
python --version

如果您需要安装 Python,请访问 python.org 或使用您系统的包管理器。

第 2 步:安装 OpenAgents

从 PyPI 安装 OpenAgents 包:

pip install openagents

信息: 提示: 始终升级到最新版本以获取最新功能和错误修复:

pip install --upgrade openagents

第3步:克隆 OpenAgents 仓库

克隆该仓库以获取演示文件:

git clone https://github.com/openagentsinc/openagents.git
cd openagents

第 4 步:了解项目模板

在启动网络之前,让我们了解项目模板如何工作。打开 demos/08_alternative_service_project/network.yaml 查看模板定义:

project_templates:
  find_alternatives:
    name: Find Service Alternatives
    description: Provides users with alternative options to given web services
    expose_as_tool: true
    tool_name: find_service_alternatives
    tool_description: >
      Find and compare alternative services to a given web service or SaaS tool.
      Returns a detailed comparison with features, pricing, and recommendations.
    agent_groups:
      - coordinators
      - workers

关键设置:

  • expose_as_tool: true - 使此工作流可以通过 MCP 作为工具被调用
  • tool_name - 外部客户端用来调用此工具的名称
  • agent_groups - 哪些代理可以参与此工作流

步骤 5:启动网络

启动替代服务查找器网络:

openagents network start demos/08_alternative_service_project

Studio 的 Web 界面会自动在你的浏览器中打开,地址为 http://localhost:8700

重要: 注意: 如果浏览器未自动打开,请手动访问 http://localhost:8700

Studio 登录页面

第 6 步:启动工作代理

该网络需要三个代理才能运行。为每个代理打开单独的终端窗口:

终端 2:启动 Searcher 代理

cd openagents
openagents agent start demos/08_alternative_service_project/agents/searcher.yaml

Searcher 代理使用以下方式查找替代服务:

  • 针对流行服务的内置知识
  • 网络搜索(DuckDuckGo),用于小众或新服务

终端 3:启动 Comparer 代理

cd openagents
openagents agent start demos/08_alternative_service_project/agents/comparer.yaml

Comparer 代理使用以下方式创建详细比较:

  • 针对知名服务的内置知识
  • 抓取网页以获取详细的功能/定价信息

终端 4:启动 Coordinator

cd openagents
python demos/08_alternative_service_project/agents/coordinator.py

Coordinator 协调工作流:

  1. 接收项目请求
  2. 委派给 Searcher 寻找替代方案
  3. 委派给 Comparer 对其进行分析
  4. 返回最终比较结果

代理运行中

第 7 步:在本地测试工作流

在连接 Claude 桌面端之前,让我们验证一切是否正常工作。

运行测试脚本:

python demos/08_alternative_service_project/test_workflow.py "Notion"

你应当会看到如下输出:

Starting project to find alternatives for: Notion
Project started with ID: proj_abc123
 
Waiting for project completion...
Project completed!
 
=== Search Results ===
Found 5 alternatives to Notion:
1. Obsidian - https://obsidian.md
2. Coda - https://coda.io
3. Craft - https://craft.do
...
 
=== Comparison Results ===
| Service | Key Features | Pricing | Best For |
|---------|--------------|---------|----------|
| Obsidian | Local-first, plugins | Free/$8/mo | Power users |
| Coda | Docs + spreadsheets | Free/$10/mo | Teams |
...

测试工作流输出

信息: 发生了什么: 协调器接收你的请求,委派给搜索器以查找替代选项,然后再委派给比较器进行详细分析。所有通信都通过 OpenAgents 网络进行。

第 8 步:登录管理仪表板

  1. 在你的浏览器中访问 http://localhost:8700,点击 "以管理员身份登录"
  2. 输入管理员密码: admin
  3. 点击 "以管理员身份登录"

你会看到管理员仪表板,其中包含:

  • 网络状态
  • 已连接的代理(协调器、搜索器、比较器)
  • 项目模板

管理员仪表板

第 9 步:发布您的网络

要将 Claude 桌面 连接到您的网络,您需要发布它。

获取您的 API 密钥

  1. 前往 https://openagents.org
  2. 登录或创建账户
  3. 导航到 仪表板API 密钥
  4. 创建一个新的 API 密钥并复制它

在管理员仪表板中发布

  1. 在管理员仪表板中,找到 "网络状态" 面板
  2. 点击 "发布网络"
  3. 在提示时粘贴您的 API 密钥
  4. 选择一个唯一的网络 ID(例如 my-service-finder
  5. 点击 "发布"

发布后,您会看到:

  • 网络 ID: my-service-finder
  • MCP URL: https://network.openagents.org/my-service-finder/mcp

复制 MCP URL - 您将需要它用于 Claude 桌面。

发布网络

第10步:连接 Claude Desktop

现在让我们连接 Claude Desktop,以使用你的多代理工具。

配置 Claude Desktop

编辑你的 Claude Desktop 配置文件:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

Linux: ~/.config/claude/claude_desktop_config.json

Windows: %APPDATA%\Claude\claude_desktop_config.json

将你的网络添加到 MCP 服务器:

{
  "mcpServers": {
    "service-finder": {
      "command": "npx",
      "args": [
        "-y",
        "@anthropic-ai/mcp-remote",
        "https://network.openagents.org/my-service-finder/mcp"
      ]
    }
  }
}

重要:my-service-finder 替换为你在发布步骤中获得的实际网络 ID。

重启 Claude Desktop

退出并重启 Claude Desktop 以加载新的配置。

Step 11: Use Your Tool with Claude

Open Claude Desktop and try these prompts:

Basic Query

Find alternatives to Slack and compare them

Claude will:

  1. Call the find_service_alternatives tool
  2. Your coordinator will orchestrate the searcher and comparer agents
  3. Claude receives and presents the detailed comparison

Claude Desktop Query

More Example Queries

QueryWhat Happens
"What are some alternatives to Mailchimp?"Finds email marketing alternatives
"Compare project management tools like Asana"Finds and compares PM tools
"I need a Figma alternative for my team"Finds design tool alternatives
"What's a good open-source alternative to Notion?"Filters for open-source options

代理如何协同工作

协调者 (Python)

协调者是一个 非-LLM 代理,负责协调工作流:

@on_event("project.notification.started")
async def on_project_started(self, event):
    # 1. Extract the service name from project goal
    # 2. Delegate to searcher: "Find alternatives to {service}"
    # 3. Wait for searcher to complete
    # 4. Delegate to comparer: "Compare these alternatives"
    # 5. Wait for comparer to complete
    # 6. Mark project as complete

搜索者代理 (YAML + LLM)

搜索者使用 智能工具选择

instructions: |
  DECISION LOGIC:
  1. If the service is well-known (Slack, Notion, etc.) → Use your knowledge
  2. If the service is niche or new → Use the search_web tool
  3. Prefer efficiency: Don't make unnecessary web requests

比较者代理 (YAML + LLM)

比较者也使用 智能工具选择

instructions: |
  DECISION LOGIC:
  1. If you know the services well → Use your knowledge
  2. If you need current pricing or features → Use fetch_webpage tool
  3. Always provide a structured comparison table

MCP 可用工具

一旦连接,Claude 可以访问:

工具描述
find_service_alternatives触发完整的工作流程以查找并比较可替代服务

该工具接受服务名称并返回:

  • 替代服务列表及其 URL
  • 详细比较表(功能、定价、优缺点)
  • 基于用例的推荐

理解项目模板

项目模板是一种强大的方式,可用于:

  1. 定义可重用的工作流 - 创建一次,多次使用
  2. 作为工具公开 - 使工作流可通过 MCP 调用
  3. 控制访问 - 指定哪些代理组参与
  4. 提供上下文 - 为代理提供有关该工作流的背景信息
project_templates:
  find_alternatives:
    name: Find Service Alternatives
    description: Provides users with alternative options to given web services
    expose_as_tool: true
    tool_name: find_service_alternatives
    context: |
      This workflow helps users discover alternatives to popular SaaS tools.
      The searcher finds options, the comparer analyzes them in detail.

故障排除

代理无法连接

# Check if the network is running
curl http://localhost:8700/health
 
# Verify agents can reach the network
openagents agent status

项目超时

  1. 确保所有三个代理均在运行(coordinator、searcher、comparer)
  2. 检查代理日志是否有错误
  3. 验证 LLM API 密钥是否在 config/agent_env/_global.json 中配置

Claude 无法找到工具

  1. 验证您的网络是否已发布(检查 Admin Dashboard)
  2. 确保项目模板包含 expose_as_tool: true
  3. 在配置更改后重启 Claude Desktop

测试 MCP 端点

curl -X POST https://network.openagents.org/your-network-id/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "method": "tools/list", "id": 1}'

下一步

现在你已经有一个可运行的多代理工具,你可以:

  1. 创建你自己的模板 - 在 network.yaml 中定义新的工作流程
  2. 添加更多代理 - 为不同任务创建专门的代理
  3. 自定义工具 - 修改 tools/web_search.pytools/web_fetch.py
  4. 构建复杂的工作流程 - 将多个项目模板串联在一起

相关文档

Was this helpful?