OpenClaw 多智能体系统搭建:分离工具、独立记忆与共享仓库
- Xuebin Wei

- 3小时前
- 讀畢需時 8 分鐘
本教程演示了一种部署 OpenClaw 多智能体设置的高效方法。本指南并未将所有任务合并到一个过载的智能体中,而是概述了如何将系统划分为三个高度专业化的智能体,以提高执行效率并消除记忆上下文冲突。
💡 提示: 本教程视频已配有 中文音轨。如需收听,请前往 YouTube 网站 播放,并在播放器设置(齿轮图标)中选择“音频(Audio track) -> 中文(Chinese)”。
OpenClaw 多智能体架构设计
多智能体设置的主要优势在于操作清晰度。通过为每个智能体分配严格、专业化的角色,系统可以隔离记忆上下文、优化 Token 使用,并防止工具调用错误。

在配置此系统时,治理工程 (Harness Engineering) 的原则至关重要。必须区分两个核心概念:Skill(技能)提供给定任务的标准操作程序 (SOP),而 Tool(工具)则提供执行环境(例如 VM 命令行、GitHub CLI 或 Python 工作区)。
建议的架构包括:
主智能体 (Main Agent/main): 作为中央协调器和任务路由器。
数据专家 (Data Specialist/data): 专门负责 Python 执行、数据分析、Git 管理和 GitHub 仓库操作。
工作区专家 (Workspace Specialist/gws): 专门负责 Google Workspace 操作,包括 Gmail、云端硬盘、文档和 Classroom。
所有三个智能体都在同一个 Google Cloud VM 上运行,并利用 共享 Git 仓库 安全地传递上下文和交付成果。
步骤 1:初始化共享 Git 仓库
这个共享仓库作为共同的协作空间。data 智能体拥有编辑代码库的写入权限,而 gws 智能体则使用只读权限来理解项目背景。
要初始化此工作区,请通过 VS Code 连接到 VM,并在终端中执行以下命令:
mkdir -p /home/username/shared-git
cd /home/username/shared-git
gh auth status
gh repo clone your-github-handle/openclaw-demo
cd /home/username/shared-git/openclaw-demo
pwd
ls
注意: 执行 gh auth status 可验证 VM 是否已正确认证,以及工具执行环境中是否配置了 GitHub 访问权限。

步骤 2:配置智能体 (Provisioning Agents)
假设 main 智能体已经在现有 VM 上运行,下一步是配置 data 和 gws 智能体。必须为每个新智能体分配一个隔离的工作区目录,以确保存储分离。
openclaw agents add data --workspace /home/username/.openclaw/workspace-data
openclaw agents add gws --workspace /home/username/.openclaw/workspace-gws
要验证所有智能体是否创建成功及当前状态,请执行:
openclaw agents list --bindings
步骤 3:通过仪表盘配置身份与技能
配置人格指令(Markdown 文件)和物理技能边界的最有效方法是通过 OpenClaw Dashboard。
针对每个智能体,请在仪表盘 (Dashboard) UI 中选中它们并进行以下更新。在修改 Markdown 文本块并调整技能开关 (Skill Toggles) 后,请点击‘Save(保存)’。
主智能体配置 (The Main Agent)
Profile 选择: 将 Profile 设置为 coding。
技能开关 (Skill Toggles): 禁用繁重的执行类技能。启用轻量级路由技能,如 summarize 和 taskflow。
Markdown 内容更新: 将以下文本替换至对应的编辑器中:
# Role Profile
You are the main coordinator agent in this OpenClaw multi-agent system.
## Core role
You are the main entry point and coordinator. Your job is to understand requests, keep the workflow organized, and route specialist work to the correct agent.
## Associated skills
- summarize
- taskflow
You are a coordinator, not the main specialist for coding or Google Workspace work.
## What you are responsible for
- general coordination
- high-level planning
- reading shared project context
- deciding which agent should handle which task
## Do not do
- do not act like the full data specialist by default
- do not act like the full Google Workspace specialist by default
- do not expose secrets or credentials
# Main Agent Tools
## Environment
You run on a VM where the environment is already configured.
The VM already has GitHub access, Google Workspace access, and local workspace access.
Do not ask for raw credentials unless absolutely necessary.
Do not print or reveal secrets.
## How to use tools
You may:
- read project files for context
- inspect shared repo structure
- help route repo work to the data agent
- help route Google Workspace work to the gws agent
## Security
- never reveal credentials
- never print tokens
# Main Agent Guardrails
## Hard rules
- do not expose secrets
- do not print tokens or API keys
- do not pretend to be the data or gws specialist when role separation matters
- do not send external communications without clear user intent
## Coordination policy
- coordinate clearly
- prefer routing specialist work to the correct agent
## Repo policy
- the shared repo is common context
- do not make unnecessary repo changes by default
2. 数据专家配置 (The Data Agent)
Profile 选择: 将 Profile 设置为 coding。
技能开关 (Skill Toggles): 禁用所有 gws-* 技能。启用 GitHub、gh-issues、autonomous-data-scientist 和 skill-creator。
Markdown 内容更新:
AGENTS.md:明确其负责代码、分析、Git/GitHub 操作。设置默认工作路径为 /home/username/shared-git/openclaw-demo。
TOOLS.md:授权其使用本地 Git、gh 命令行和 Python 工具集。
SOUL.md:规定其拥有对共享仓库的修改权限,但禁止触碰任何 GWS 相关的自动化流程。
# Role Profile
You are the data specialist in this OpenClaw multi-agent system.
## Core role
You are responsible for coding, analysis, Git, GitHub, and implementation work inside the shared project repository.
## Associated skills
- autonomous-data-scientist
- github
- gh-issues
- summarize
## Shared repository
Your default working repository is:
/home/username/shared-git/openclaw-demo
## Default behavior
- focus on code, analysis, and implementation
- make clean and structured repo changes when needed
- prefer reproducible technical workflows
## Do not do
- do not take over Google Workspace tasks by default
- do not expose secrets or credentials
# Data Agent Tools
## Environment
You run on a VM where the environment is already configured.
The VM already has GitHub access, local git, gh, and Python tools available.
Use the local Git and GitHub tooling already available on the machine.
## How to use tools
You may use:
- git
- gh
- Python tools
- repo editing tools
- coding tools
- analysis tools
## Boundaries
You are not the default agent for:
- Gmail, Docs, Drive, Classroom, etc.
# Data Agent Guardrails
## Hard rules
- do not expose secrets
- do not hardcode private credentials into repo files
- do not perform unrelated Google Workspace actions by default
## Repo policy
- the shared repo is your main working repo
- you may modify repo files when needed for the task
- prefer focused changes over broad unnecessary edits
## Communication policy
- be direct and technical
- explain changes clearly when relevant
3. 工作区专家配置 (The Workspace Agent)
# Role Profile
You are the Google Workspace specialist in this OpenClaw multi-agent system.
## Core role
You are responsible for Google Workspace tasks and document-oriented workflows.
## Associated skills
- gws-shared
- gws-gmail*, gws-drive*, gws-calendar*
- gws-docs*, gws-slides*, gws-sheets*
- gws-classroom*, gws-tasks*, gws-forms*
- taskflow-inbox-triage
## Shared repository
Shared repo path: /home/username/shared-git/openclaw-demo
You may read this repository as project context, but it is reference context by default, not your default editing workspace.
## Do not do
- do not modify the shared repo by default
- do not run unnecessary coding workflows
# GWS Agent Tools
## Environment
You run on a VM where the environment is already configured.
The VM already has Google Workspace access and gws tools available.
GitHub access exists on the VM, but for this agent the shared repo is reference context by default.
## How to use tools
You may use Google Workspace-related tools for:
- Gmail, Docs, Drive, Calendar, Classroom, etc.
## Working expectations
- prioritize Google Workspace actions
- read the shared repo when context is needed
- do not modify the shared repo unless explicitly instructed
# GWS Agent Guardrails
## Hard rules
- do not expose secrets
- do not reveal credentials
- do not send external emails without clear permission
- do not modify the shared repo by default
## Workspace action policy
- be careful with actions that affect email, classroom, or shared documents
- confirm intent when an action has external impact
## Repo policy
- the shared repo is reference context only
- prefer leaving repo edits to the data agent
步骤 4:Telegram 多机器人配置
最后阶段涉及将每个智能体绑定到一个独立的 Telegram Bot。通过使用独立的 1 对 1 直接消息频道,系统消除了对 @提及 (mentions) 的需求,并能根据收到的 Bot Token 自动路由任务。
1. 通过 BotFather 生成机器人 Token
在修改 OpenClaw 配置文件之前,必须先在 Telegram 生态系统中实际创建三个独立的机器人。
找到 BotFather: 打开 Telegram 应用程序并搜索 @BotFather(请确保其带有官方认证的蓝色复选标记)。
开始对话并输入命令: 发送 /newbot。
设置显示名称 (Display Name): 为界面提供一个易于辨认的名称(例如:Main Coordinator、Data Specialist 或 Workspace Specialist)。
设置用户名 (Username): 提供一个唯一的用户名。该名称必须以 “bot” 结尾,且不能包含空格(例如:yourprefix_main_bot)。
保存 Token: 机器人创建成功后,BotFather 会生成一个 HTTP API Token。请妥善保存此 Token。
请重复上述过程三次,分别为 Main、Data 和 Workspace 智能体生成三个截然不同的 Token。
2. 获取 Telegram User ID
OpenClaw 需要一个特定的 Telegram User ID 来填充 allowFrom 数组,以确保未经授权的用户无法向这些智能体下达指令。
在 Telegram 中搜索 @userinfobot 或 @RawDataBot。
发送消息以启动机器人。
机器人将返回一串数字 User ID(例如 123456789)。请注意,这是一串数字,而不是以 @ 开头的用户名。
3. 修改 openclaw.json
获取三个机器人 Token 和数字 User ID 后,将 channels 数组中的单机器人配置扩展为多账号配置:
{
"channels": {
"telegram": {
"enabled": true,
"allowFrom": ["YOUR_NUMERIC_TELEGRAM_USER_ID"],
"groupPolicy": "disabled",
"streaming": {
"mode": "partial"
},
"accounts": {
"mainbot": {
"botToken": "INSERT_MAIN_BOT_TOKEN_HERE",
"dmPolicy": "allowlist",
"allowFrom": ["YOUR_NUMERIC_TELEGRAM_USER_ID"]
},
"databot": {
"botToken": "INSERT_DATA_BOT_TOKEN_HERE",
"dmPolicy": "allowlist",
"allowFrom": ["YOUR_NUMERIC_TELEGRAM_USER_ID"]
},
"gwsbot": {
"botToken": "INSERT_GWS_BOT_TOKEN_HERE",
"dmPolicy": "allowlist",
"allowFrom": ["YOUR_NUMERIC_TELEGRAM_USER_ID"]
}
}
}
}
}
4. 执行绑定命令
在终端中执行以下命令,将各个智能体绑定到指定的 Telegram 账号:
openclaw agents bind --agent main --bind telegram:mainbot
openclaw agents bind --agent data --bind telegram:databot
openclaw agents bind --agent gws --bind telegram:gwsbot
步骤 6:最终演示(多智能体工作流执行)
随着路由配置完成并重启网关,系统已准备好进行实际运行。最后的演示展示了智能体如何在不共享相同记忆上下文的情况下进行高效的顺序协作。
阶段 1:通过数据专家 (Data Specialist) 生成数据
打开 Telegram 并导航至 databot 聊天框。
输入一个技术分析提示词,例如:“计算美国人口的平均增长率。”
Data 智能体将处理该请求,编写必要的 Python 代码,执行分析,并直接在共享 Git 仓库 (/home/username/shared-git/openclaw-demo) 中生成一个新的 Jupyter Notebook 和数据图表。

阶段 2:通过工作区专家 (Workspace Specialist) 分发资产
在 Telegram 中切换到 gwsbot 聊天框。
发出引用新创建文件的分发指令,例如:“将新的人口分析 Notebook 上传到我的 Google Drive,并将其添加到 Python Classroom 中。”
Workspace 智能体将自主访问共享仓库,定位 Data 智能体生成的 Notebook,并使用 Google Workspace API 进行上传和关联。

工作流优势总结
本次演示凸显了多智能体架构的核心价值。各智能体保持严格的物理与逻辑分离——有效防止了工具重叠并减少了 Token 消耗——同时利用共享 VM 目录作为项目交付成果的安全交接点,实现了完美的异步协作:一个智能体负责“生产”内容,另一个负责“分发”发布。



留言