跳到主要内容OpenClaw 高级使用:多 Agent 协作、模型容灾与云端 Gateway 操控本地 macOS | 极客日志JavaScriptNode.jsAI
OpenClaw 高级使用:多 Agent 协作、模型容灾与云端 Gateway 操控本地 macOS
OpenClaw 是一款支持多模型调度与多 Agent 协作的 AI 智能体平台。详述了模型容灾机制配置、记忆检索设置及云端 Gateway 与本地 macOS 通过 SSH 反向隧道的配对流程。通过配置主备模型、Token 轮换及混合搜索策略,确保服务高可用。利用 SSH 隧道实现内网 Mac 受云端控制,完成远程命令执行与浏览器操作,构建跨端开发环境。
OpenClaw 是一款基于开源架构的 AI 智能体平台。它以强大的多模型调度能力为核心,支持 Anthropic、OpenAI、Google 等主流 AI 模型的自动容灾切换,确保服务高可用。内置智能记忆检索系统,通过 Embedding 模型实现混合搜索,让 Agent 在持续使用中不断积累经验。其核心亮点在于多 Agent 协作机制——支持线性流水线、依赖图并行、多 Agent 辩论三种协作模式,可组建由编码、测试、文档、审查等专职 AI 成员构成的虚拟开发团队。此外,OpenClaw 还支持云端与本地设备通过 SSH 反向隧道配对,实现远程操控浏览器、执行命令等跨端能力。
相关资源:
模型容灾机制
文件路径:/home/ubuntu/.openclaw/openclaw.json
{
"agents": {
"defaults": {
"model": {
"primary": "anthropic/claude-opus-4-6",
"fallbacks": [
"openai-codex/gpt-5.3-codex",
"google-antigravity/claude-opus-4-6-thinking"
]
}
},
"list": [
{
"id": "main",
"default": true,
"model": {
"primary"
:
"anthropic/claude-opus-4-6"
,
"fallbacks"
:
[
"openai-codex/gpt-5.3-codex"
,
"google-antigravity/claude-opus-4-6-thinking"
]
}
}
]
}
}
多认证 Profile + Token 轮换
{
"auth": {
"profiles": {
"openai-codex:default": { "provider": "openai-codex", "mode": "oauth" },
"anthropic:default": { "provider": "anthropic", "mode": "token" },
"anthropic:manual": { "provider": "anthropic", "mode": "token" },
"google-antigravity:[email protected]": { "provider": "google-antigravity", "mode": "oauth", "email": "[email protected]" },
"google-antigravity:[email protected]": { "provider": "google-antigravity", "mode": "oauth" }
},
"order": {
"anthropic": ["anthropic:default", "anthropic:manual"],
"google-antigravity": ["google-antigravity:[email protected]", "google-antigravity:[email protected]"]
}
}
}
memory_search 配置
文件路径:/home/ubuntu/.openclaw/openclaw.json
{
"agents": {
"defaults": {
"memorySearch": {
"sources": ["memory", "sessions"],
"experimental": { "sessionMemory": true },
"provider": "gemini",
"remote": { "apiKey": "AIzaSy***************" },
"fallback": "gemini",
"model": "gemini-embedding-001",
"query": {
"hybrid": {
"enabled": true,
"vectorWeight": 0.7,
"textWeight": 0.3
}
}
}
}
}
}
云端 OpenClaw 与本地 macOS 通过 Node 配对步骤
架构概览
┌─────────────────────────┐ SSH 反向隧道 ┌─────────────────────────┐
│ 云端 AWS (Ubuntu) │ ◄────────────── │ 本地 macOS (MacBook) │
│ │ │ │
│ 端口 18790 │ │ OpenClaw Node │
│ OpenClaw Gateway │ │ 连接:localhost:18790 │
│ 监听:127.0.0.1:18789 │ │ NAT 内网(无公网 IP) │
│ 公网 IP: xx.xx.xx.xx │ │ │
└─────────────────────────┘ └─────────────────────────┘
核心思路:Mac 在 NAT 内网无公网 IP,无法被 AWS 主动连接。解决方案是 Mac 主动通过 SSH 隧道连到 AWS,在 AWS 本地开一个端口(18790),将流量转发到 Mac 上的 Node 服务。
前置条件
| 项目 | 要求 |
|---|
| AWS 服务器 | OpenClaw Gateway 已安装并运行 |
| macOS | Node.js ≥ 22, npm |
| SSH | Mac 能 SSH 到 AWS(公钥已添加到 ~/.ssh/authorized_keys) |
| 网络 | Mac 有互联网访问(不需要公网 IP) |
步骤 1:Mac 安装 OpenClaw
步骤 2:获取 Gateway Token
在 AWS 上查看配置文件中的 Gateway Token:
cat ~/.openclaw/openclaw.json | grep -A2 '"auth"'
找到 gateway.auth.token 的值,后续步骤需要用到。
也可以通过 OpenClaw 工具获取:
openclaw gateway config | grep token
步骤 3:建立 SSH 反向隧道
ssh -N -L 18790:127.0.0.1:18789 ubuntu@<AWS 公网 IP>
| 参数 | 说明 |
|---|
-N | 不执行远程命令,只做端口转发 |
-L 18790:127.0.0.1:18789 | Mac 本地 18790 → AWS 的 127.0.0.1:18789(Gateway) |
ubuntu@<IP> | AWS 服务器 SSH 地址 |
⚠️ 首次连接需要确认 SSH 指纹(输入 yes)。
curl -s http://localhost:18790/health
步骤 4:启动 Node 服务
OPENCLAW_GATEWAY_TOKEN="<你的 Gateway Token>" openclaw node run \
--host 127.0.0.1 \
--port 18790 \
--display-name "Master-Mac"
| 参数 | 说明 |
|---|
OPENCLAW_GATEWAY_TOKEN | Gateway 认证令牌 |
--host 127.0.0.1 | 连接到本地(通过 SSH 隧道转发) |
--port 18790 | SSH 隧道的本地端口 |
--display-name | Node 的显示名称(方便识别) |
🔗 Connecting to gateway at ws:
✅ Connected! Waiting for pairing approval...
步骤 5:AWS 端批准配对
在 AWS 终端或通过 OpenClaw Agent 执行:
openclaw node pending
openclaw node approve <node-id>
✅ Paired successfully! Node is now active.
步骤 6:配置执行权限
openclaw node exec-approvals set defaults.security full
或者手动创建配置文件 ~/.openclaw/exec-approvals.json:
{
"defaults": {
"security": "full"
}
}
⚠️ 关键:defaults.security 必须设为 "full",否则即使 allowlist 配了 * 也会拒绝执行命令。
步骤 7:验证连接
从 AWS 的 OpenClaw Agent 测试远程执行:
nodes(action="status")
nodes(action="run", node="Master-Mac", command=["echo", "Hello from Mac!"])
nodes(action="run", node="Master-Mac", command=["sw_vers"])
相关免费在线工具
- RSA密钥对生成器
生成新的随机RSA私钥和公钥pem证书。 在线工具,RSA密钥对生成器在线工具,online
- Mermaid 预览与可视化编辑
基于 Mermaid.js 实时预览流程图、时序图等图表,支持源码编辑与即时渲染。 在线工具,Mermaid 预览与可视化编辑在线工具,online
- 随机西班牙地址生成器
随机生成西班牙地址(支持马德里、加泰罗尼亚、安达卢西亚、瓦伦西亚筛选),支持数量快捷选择、显示全部与下载。 在线工具,随机西班牙地址生成器在线工具,online
- Keycode 信息
查找任何按下的键的javascript键代码、代码、位置和修饰符。 在线工具,Keycode 信息在线工具,online
- Escape 与 Native 编解码
JavaScript 字符串转义/反转义;Java 风格 \uXXXX(Native2Ascii)编码与解码。 在线工具,Escape 与 Native 编解码在线工具,online
- JavaScript / HTML 格式化
使用 Prettier 在浏览器内格式化 JavaScript 或 HTML 片段。 在线工具,JavaScript / HTML 格式化在线工具,online