
痛点场景 #
你有没有过这种经历:
想同时运行多个 AI 助手,一个写代码、一个查资料、一个做分析。
每次只能用一个 Agent,切换来切换去,效率极低。 想在家里部署 OpenClaw,但不知道如何配置多 Agent 支持。
这活本该一台 Mac mini 搞定。
为什么需要多 Agent 架构? #
单个 AI 助手有个问题:同时只能做一件事。
你想让它:
- 写代码
- 查航班
- 分析数据
- 写文章
结果呢?它只能一件一件来,你得等着。
更好的方式是:多个 Agent 并行工作。
- Agent 1:专门写代码(Coder 模型)
- Agent 2:专门查资料(快速模型)
- Agent 3:专门做分析(Qwen 3.5 Plus)
- 你:负责决策和审核
这才是 AI 助手该有的工作方式。
架构设计 #
整体架构 #
┌─────────────────────────────────────────────────────┐
│ Mac mini (Host) │
│ │
│ ┌─────────────────────────────────────────────┐ │
│ │ OpenClaw Gateway │ │
│ │ Port: 18789 (WebSocket) │ │
│ │ │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Agent 1 │ │ Agent 2 │ │ Agent N │ │ │
│ │ │ (main) │ │ (dev) │ │ (custom) │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ │ │
│ └─────────────────────────────────────────────┘ │
│ │
│ ┌──────────────┬──────────────┐ │
│ ┌────▼────┐ ┌─────▼─────┐ │ │
│ │ Feishu │ │ Telegram │ │ │
│ │ Bot │ │ Bot │ │ │
│ └─────────┘ └───────────┘ │ │
└─────────────────────────────────────────────────────┘组件说明 #
| 组件 | 作用 | 端口 |
|---|---|---|
| Gateway | 核心服务,管理所有 Agent | 18789 |
| Agent 实例 | 独立的 AI 助手进程 | 动态 |
| Feishu Bot | 飞书机器人接入 | HTTPS |
| Telegram Bot | Telegram 机器人接入 | HTTPS |
端口规划 #
| 服务 | 默认端口 | 用途 |
|---|---|---|
| Gateway WebSocket | 18789 | Agent 和客户端连接 |
| Gateway HTTP | 18790 | 健康检查、API(可选) |
| Nginx 反向代理 | 80/443 | 外部访问入口(可选) |
环境准备 #
系统要求 #
| 项目 | 最低要求 | 推荐配置 |
|---|---|---|
| macOS 版本 | 12.0 (Monterey) | 14.0 (Sonoma) 或更新 |
| CPU | Intel Core i5 / M1 | M2/M3 系列 |
| 内存 | 8 GB | 16 GB 或更高 |
| 存储 | 20 GB 可用空间 | 50 GB+ SSD |
| Node.js | v18.0+ | v22 LTS |
安装 Node.js #
使用 Homebrew(推荐):
# 安装 Homebrew(如未安装)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# 安装 Node.js LTS
brew install node@22
# 验证安装
node --version
npm --version安装 OpenClaw #
# 全局安装 OpenClaw
npm install -g openclaw
# 验证安装
openclaw --version
# 查看帮助
openclaw --helpGateway 配置 #
配置文件位置 #
~/.openclaw/gateway.json基础配置 #
{
"port": 18789,
"host": "127.0.0.1",
"agents": {
"main": {
"model": "bailian/qwen3.5-plus",
"workspace": "/Users/jason/.openclaw/workspace/main",
"thinking": "on"
},
"dev": {
"model": "bailian/qwen-coder",
"workspace": "/Users/jason/.openclaw/workspace/dev",
"thinking": "off"
},
"fast": {
"model": "bailian/qwen-turbo",
"workspace": "/Users/jason/.openclaw/workspace/fast",
"thinking": "off"
}
},
"channels": {
"feishu": {
"enabled": true,
"appId": "cli_xxxxxx",
"appSecret": "xxxxxx"
}
}
}配置说明 #
| 字段 | 说明 | 示例 |
|---|---|---|
port |
Gateway 端口 | 18789 |
host |
绑定地址 | 127.0.0.1(仅本地)或 0.0.0.0(局域网) |
agents.main |
主 Agent 配置 | 日常对话 |
agents.dev |
开发 Agent 配置 | 写代码专用 |
agents.fast |
快速 Agent 配置 | 简单查询 |
channels.feishu |
飞书通道配置 | 机器人凭证 |
启动 Gateway #
# 启动 Gateway
openclaw gateway start
# 查看状态
openclaw gateway status
# 停止 Gateway
openclaw gateway stop
# 重启 Gateway
openclaw gateway restart开机自启(launchd) #
创建启动脚本:
# 创建启动脚本
cat > ~/openclaw-gateway.sh << 'EOF'
#!/bin/bash
export PATH="/opt/homebrew/bin:$PATH"
openclaw gateway start
EOF
chmod +x ~/openclaw-gateway.sh创建 launchd 配置:
cat > ~/Library/LaunchAgents/com.openclaw.gateway.plist << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.openclaw.gateway</string>
<key>ProgramArguments</key>
<array>
<string>/Users/jason/openclaw-gateway.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/Users/jason/.openclaw/logs/gateway.log</string>
<key>StandardErrorPath</key>
<string>/Users/jason/.openclaw/logs/gateway.err</string>
</dict>
</plist>
EOF
# 加载配置
launchctl load ~/Library/LaunchAgents/com.openclaw.gateway.plist多 Agent 配置 #
Agent 命名规范 #
| Agent 名称 | 用途 | 推荐模型 |
|---|---|---|
main |
主 Agent,日常对话 | Qwen 3.5 Plus |
dev |
开发专用,写代码 | Coder 模型 |
fast |
快速查询,简单任务 | Qwen Turbo |
analysis |
数据分析,复杂任务 | Qwen 3.5 Plus |
工作区隔离 #
每个 Agent 有独立的工作区:
/Users/jason/.openclaw/workspace/
├── main/ # 主 Agent 工作区
│ ├── MEMORY.md
│ ├── TODO.md
│ └── ...
├── dev/ # 开发 Agent 工作区
│ ├── projects/
│ └── scripts/
└── fast/ # 快速 Agent 工作区
└── queries/资源限制 #
在配置文件中设置:
{
"agents": {
"main": {
"maxTokens": 1000000,
"maxSessionTime": 3600
},
"dev": {
"maxTokens": 500000,
"maxSessionTime": 1800
}
}
}网络配置 #
内网模式(推荐) #
Gateway 仅绑定本地:
{
"host": "127.0.0.1"
}优点:
- 安全性高
- 外部无法访问
- 适合单机使用
局域网模式 #
允许同一局域网内设备访问:
{
"host": "0.0.0.0"
}注意:
- 需要配置防火墙
- 仅信任网络环境使用
反向代理(Nginx) #
需要外网访问时,配置 Nginx:
server {
listen 443 ssl;
server_name openclaw.example.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
location / {
proxy_pass http://127.0.0.1:18789;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}运维管理 #
启动/停止/重启 #
# 启动
openclaw gateway start
# 停止
openclaw gateway stop
# 重启
openclaw gateway restart
# 查看状态
openclaw gateway status日志查看 #
# 实时查看日志
tail -f ~/.openclaw/logs/gateway.log
# 查看错误日志
tail -f ~/.openclaw/logs/gateway.err
# 查看最近 100 行
tail -n 100 ~/.openclaw/logs/gateway.log监控资源使用 #
# 查看 Gateway 进程
ps aux | grep openclaw
# 查看内存使用
top -pid $(pgrep -f "openclaw gateway")
# 查看网络连接
lsof -i :18789备份策略 #
# 备份配置文件
cp ~/.openclaw/gateway.json ~/.openclaw/gateway.json.bak.$(date +%Y%m%d)
# 备份工作区
tar -czf ~/backups/openclaw-workspace-$(date +%Y%m%d).tar.gz \
~/.openclaw/workspace/常见问题 #
问题 1: 端口冲突 #
错误:
Error: Port 18789 is already in use解决:
# 查找占用端口的进程
lsof -i :18789
# 杀死进程
kill -9 <PID>
# 或者修改配置使用其他端口问题 2: Agent 崩溃 #
现象:
- Agent 无响应
- 会话中断
解决:
# 重启 Gateway
openclaw gateway restart
# 检查日志
tail -f ~/.openclaw/logs/gateway.log问题 3: 无法连接 #
错误:
WebSocket connection failed排查:
# 检查 Gateway 是否运行
openclaw gateway status
# 检查端口是否监听
lsof -i :18789
# 检查防火墙
sudo lsof -iTCP -sTCP:LISTEN问题 4: 性能优化 #
建议:
- 限制同时运行的 Agent 数量(建议 3-5 个)
- 为每个 Agent 设置合理的 token 限制
- 定期清理会话历史
- 使用 SSD 存储
成本对比 #
| 方案 | 成本 | 性能 | 推荐 |
|---|---|---|---|
| 单 Agent | 低 | 低(串行) | 个人使用 |
| 多 Agent(本方案) | 中 | 高(并行) | 团队/重度用户 |
| 云服务 | 高 | 高 | 企业级 |
下一步行动 #
- 安装 Node.js:
brew install node@22 - 安装 OpenClaw:
npm install -g openclaw - 配置 Gateway:编辑
~/.openclaw/gateway.json - 启动服务:
openclaw gateway start - 测试连接:通过飞书/Telegram 发送消息
老黄的笔记:
我花了一下午配置好这套多 Agent 架构。
现在可以同时运行 3 个 Agent:
- 一个写代码(Coder 模型)
- 一个查资料(快速模型)
- 一个做分析(Qwen 3.5 Plus)
效率提升了不止 3 倍。
这个投资,值。⚙️