OpenClaw 多 Agent 配置完整教程:一台服务器运行 10 个智能体(2026 版)
本文导读:详细讲解 OpenClaw 多 Agent 架构配置全流程,从工作区创建、配置文件修改到飞书集成,附完整命令和避坑指南,助你零成本搭建企业级 AI 基础设施。
一、场景背景
1.1 业务痛点
某中小企业,员工 50 人,年营收 3000 万,面临以下 AI 落地挑战:
1. 部门需求差异大 - 财务部需要报表分析、销售部需要客户跟进、人事部需要简历筛选
2. 采购成本高 - 如果每个部门单独采购 AI 服务,年费用 20 万+
3. 数据孤岛 - 各部门使用不同 AI 工具,数据无法互通
4. 部署复杂 - 传统方案需要多台服务器,运维成本高
5. 权限混乱 - 员工访问权限难以精细化控制
6. 响应慢 - 通用 AI 助手不懂业务,回答质量低
1.2 核心需求
| 需求 | 说明 | 优先级 |
|---|---|---|
| 多部门独立 Agent | 每个部门专属 AI 助手,懂业务术语 | P0 |
| 低成本部署 | 1 台服务器承载所有 Agent | P0 |
| 数据隔离 | 各部门记忆和技能独立 | P0 |
| 统一入口 | 飞书/企业微信单点接入 | P1 |
| 权限管控 | 员工只能访问本部门 Agent | P1 |
| 快速上线 | 1 小时内完成部署 | P2 |
二、系统架构
2.1 多 Agent 架构原理
OpenClaw 采用工作区隔离设计,每个 Agent 拥有独立的:
/root/.openclaw/
├── workspace-sales/ # 销售 Agent 工作区
│ ├── IDENTITY.md # 身份定义
│ ├── SOUL.md # 性格设定
│ ├── USER.md # 用户信息
│ └── memory/ # 独立记忆
├── workspace-writer/ # 文案 Agent 工作区
│ └── ...
├── workspace-finance/ # 财务 Agent 工作区
│ └── ...
└── agents/
├── main/ # 主 Agent
├── writer/ # 文案 Agent 配置
└── finance/ # 财务 Agent 配置
核心优势:
- ✅ 资源复用 - 共享同一套运行时,内存占用降低 70%
- ✅ 独立记忆 - 每个 Agent 有自己的长期记忆和技能库
- ✅ 灵活扩展 - 随时添加新 Agent,无需重启服务
- ✅ 成本优化 - 1 台服务器 = 10 个专属 AI 助手
2.2 架构图
┌─────────────────────────────────────────────────┐
│ OpenClaw Gateway (单实例) │
│ ┌───────────┐ ┌───────────┐ ┌───────────┐ │
│ │ Sales │ │ Writer │ │ Finance │ │
│ │ Agent │ │ Agent │ │ Agent │ │
│ └───────────┘ └───────────┘ └───────────┘ │
│ │ │ │ │
│ └──────────────┴──────────────┘ │
│ │ │
│ ┌───────┴───────┐ │
│ │ 路由 bindings │ │
│ └───────┬───────┘ │
└────────────────────┼────────────────────────────┘
│
┌────────────┼────────────┐
│ │ │
▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐
│ 飞书销售│ │ 飞书文案│ │ 飞书财务│
│ 群 │ │ 群 │ │ 群 │
└─────────┘ └─────────┘ └─────────┘
三、环境准备
3.1 服务器配置
推荐配置(中型规模,运行 10 个 Agent):| 配置项 | 要求 | 说明 |
|---|---|---|
| CPU | 16 核+ | 每个 Agent 约占用 1-2 核 |
| 内存 | 32GB+ | 每个 Agent 约占用 500MB-1GB |
| 硬盘 | 500GB SSD | 记忆文件频繁读写 |
| 网络 | 200Mbps+ | 支持多用户并发 |
| IP 资源 | 1 个公网 IP | 统一出口 |
3.2 安装基础组件
步骤 1:安装 Node.js# Ubuntu/Debian
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
# 验证安装
node -v # 应显示 v20.x
npm -v # 应显示 10.x
步骤 2:安装 OpenClaw
# 全局安装 OpenClaw
sudo npm install -g openclaw
# 验证安装
openclaw --version
步骤 3:初始化配置
# 运行初始化向导
openclaw init
# 按提示配置:
# 1. 选择模型提供商(阿里云、智谱等)
# 2. 输入 API Key
# 3. 选择通信通道(飞书、钉钉等)
# 4. 配置工作区路径
四、配置多 Agent
4.1 创建第一个 Agent(以 writer 为例)
步骤 1:执行创建命令# 在终端执行
openclaw agents add writer
# 系统提示:
# ? 是否创建工作区?(Y/n) → 直接回车确认
# ? 是否配置模型?(y/N) → 输入 N(使用默认配置)
# ? 是否配置通道?(y/N) → 输入 N(后续手动配置)
步骤 2:验证创建结果
# 查看工作区目录
ls -la /root/.openclaw/workspace-writer/
# 输出应包含:
# IDENTITY.md SOUL.md USER.md memory/ skills/
步骤 3:配置 Agent 身份 编辑 `/root/.openclaw/workspace-writer/IDENTITY.md`:
# IDENTITY.md - 文案 Agent 身份
- **名称**:文案小助手
- **职责**:负责公司产品文案、SEO 文章、社媒内容创作
- **风格**:专业、生动、有吸引力
- **技能**:SEO 优化、文案创作、内容策划
4.2 创建多个 Agent
批量创建脚本:#!/bin/bash
# 定义 Agent 列表
agents=("sales" "finance" "hr" "support" "marketing" "product" "data" "legal" "admin")
# 批量创建
for agent in "${agents[@]}"; do
echo "创建 Agent: $agent"
openclaw agents add "$agent" << EOF
Y
N
N
EOF
echo "✅ $agent 创建完成"
done
echo "所有 Agent 创建完成!"
执行脚本:
chmod +x create_agents.sh
./create_agents.sh
4.3 修改 openclaw.json 配置
创建完多个 Agent 后,必须修改 `openclaw.json` 的 4 个地方:
位置 1:agents.list 添加新 Agent{
"agents": {
"list": [
{
"id": "main",
"name": "main",
"workspace": "/root/.openclaw/workspace",
"agentDir": "/root/.openclaw/agents/main/agent"
},
{
"id": "writer",
"name": "writer",
"workspace": "/root/.openclaw/workspace-writer",
"agentDir": "/root/.openclaw/agents/writer/agent"
},
{
"id": "sales",
"name": "sales",
"workspace": "/root/.openclaw/workspace-sales",
"agentDir": "/root/.openclaw/agents/sales/agent"
},
{
"id": "finance",
"name": "finance",
"workspace": "/root/.openclaw/workspace-finance",
"agentDir": "/root/.openclaw/agents/finance/agent"
}
]
}
}
位置 2:tools 启用 Agent 间通信
{
"tools": {
"agentToAgent": {
"enabled": true,
"allow": ["main", "writer", "sales", "finance"]
}
}
}
位置 3:bindings 配置路由规则
{
"bindings": [
{
"agentId": "main",
"match": {
"channel": "feishu",
"accountId": "main"
}
},
{
"agentId": "writer",
"match": {
"channel": "feishu",
"accountId": "writer"
}
},
{
"agentId": "sales",
"match": {
"channel": "feishu",
"accountId": "sales"
}
}
]
}
位置 4:feishu.accounts 添加飞书应用
{
"feishu": {
"accounts": {
"main": {
"appId": "cli_a1b2c3d4e5f6",
"appSecret": "xxxxx"
},
"writer": {
"appId": "cli_xxx",
"appSecret": "xxx"
},
"sales": {
"appId": "cli_yyy",
"appSecret": "yyy"
}
}
}
}
五、部署与验证
5.1 重启 Gateway
# 重启服务使配置生效
openclaw gateway restart
# 验证状态
openclaw gateway status
预期输出:
✅ Gateway 运行中
✅ 已加载 Agent: main, writer, sales, finance
✅ 监听端口:18789
✅ 工作区:/root/.openclaw/workspace
5.2 配置飞书机器人
步骤 1:创建飞书应用1. 访问 飞书开放平台
2. 点击"创建企业自建应用"
3. 填写应用名称(如"文案助手")
4. 复制 App ID 和 App Secret
步骤 2:配置机器人能力飞书应用后台 → 版本管理 → 可见范围 → 添加目标同事
5.3 授权流程
同事第一次与 Agent 对话时:
1. 收到授权码提示
2. 管理员在终端执行:
openclaw pairing approve feishu XXXXX
3. 授权完成,同事可正常使用
六、性能优化
6.1 内存管理
每个 Agent 内存占用:| Agent 数量 | 内存占用 | 推荐配置 |
|---|---|---|
| 1-3 个 | 1-2GB | 8GB 内存 |
| 4-6 个 | 3-5GB | 16GB 内存 |
| 7-10 个 | 6-10GB | 32GB 内存 |
# 限制每个 Agent 的最大内存
export NODE_OPTIONS="--max-old-space-size=1024"
# 使用 PM2 管理进程
npm install -g pm2
pm2 start openclaw-gateway
6.2 并发处理
Nginx 反向代理配置:server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:18789;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
6.3 日志管理
配置日志轮转:# 创建日志配置文件
cat > /etc/logrotate.d/openclaw << EOF
/var/log/openclaw/*.log {
daily
rotate 7
compress
delaycompress
notifempty
create 0640 www-data www-data
}
EOF
七、最佳实践
7.1 部门 Agent 规划
| 部门 | Agent 名称 | 核心技能 | 预期效果 |
|---|---|---|---|
| 销售部 | sales | 客户跟进、报价生成 | 转化率提升 30% |
| 文案部 | writer | 文章撰写、SEO 优化 | 产出效率提升 5 倍 |
| 财务部 | finance | 报表分析、预算审核 | 错误率降低 80% |
| 人事部 | hr | 简历筛选、面试安排 | 筛选时间缩短 70% |
| 客服部 | support | 问题解答、工单处理 | 响应时间 |
7.2 扩展建议
1. 逐步扩展 - 先部署 2-3 个核心部门,验证效果后再扩展
2. 技能共享 - 通用技能(如搜索、文档处理)可多个 Agent 共用
3. 定期备份 - 每周备份 memory 目录,防止数据丢失
4. 监控告警 - 配置 Gateway 健康检查,异常时及时通知
7.3 安全配置
防火墙配置:# 只允许内网访问
sudo ufw allow from 192.168.1.0/24 to any port 18789
# 禁止外网直接访问
sudo ufw deny 18789
权限管理:
{
"permissions": {
"sales": {
"allowedChannels": ["feishu-sales-group"],
"allowedSkills": ["crm-search", "quote-generator"],
"restrictedSkills": ["finance-report", "hr-data"]
}
}
}
八、常见问题
8.1 Agent 无法响应
问题:创建完 Agent 后,发消息没有响应 解决方案:1. 检查 openclaw.json 是否配置正确
2. 检查 bindings 中的 accountId 是否匹配
3. 重启 Gateway:`openclaw gateway restart`
4. 查看日志:`tail -f /var/log/openclaw/gateway.log`
8.2 内存占用过高
问题:运行多个 Agent 后,内存占用过高 解决方案:1. 限制每个 Agent 的内存:`export NODE_OPTIONS="--max-old-space-size=1024"`
2. 使用 PM2 管理进程
3. 定期清理记忆文件
4. 升级服务器内存
8.3 飞书授权失败
问题:同事收到授权码,但管理员执行命令后仍然无法使用 解决方案:1. 检查飞书应用的可见范围是否包含该同事
2. 检查授权码是否正确
3. 重新执行授权命令
4. 查看 Gateway 日志
九、成本分析
9.1 投入成本
| 项目 | 费用 | 说明 |
|---|---|---|
| 服务器 | ¥500-2000/月 | 根据规模选择 |
| API 调用 | ¥500-2000/月 | 根据使用量 |
| 人力成本 | ¥5000-10000/月 | 1 人维护 |
9.2 收益分析
效率提升:十、总结与建议
10.1 适用场景
✅ 推荐使用:
❌ 不推荐:
10.2 实施建议
1. 循序渐进 - 从 2-3 个 Agent 开始,逐步扩展
2. 选择成熟方案 - 优先使用官方推荐的配置方式
3. 重视培训 - 对使用人员进行系统培训
4. 持续优化 - 根据实际使用情况持续优化
5. 定期备份 - 每周备份记忆和配置文件
10.3 未来趋势
2026 年 OpenClaw 多 Agent 发展趋势:
1. AI 智能化 - AI 驱动的自动配置和优化
2. 一体化 - 多平台统一管理
3. 数据驱动 - 基于数据的智能决策
4. 安全升级 - 更先进的权限管理
5. 生态完善 - 更多第三方插件和服务
参考资料:
字数统计:约 4500 字(纯文本,不含代码块) 预计阅读时间:15 分钟
