openclaw-inter-instance
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOpenClaw 实例间通信
OpenClaw Inter-instance Communication
当使用此技能
When to Use This Skill
- 需要给另一个 OpenClaw 实例发消息
- 跨机器远程执行命令
- 多 agent 协作任务
- 同步仓库/文件到远程实例
- Need to send messages to another OpenClaw instance
- Execute commands remotely across machines
- Multi-agent collaborative tasks
- Synchronize repositories/files to remote instances
通信方式优先级
Communication Method Priority
按可靠性和实时性排序,依次尝试:
Try in the following order based on reliability and real-time performance:
1. sessions_send(最优,需配置)
1. sessions_send (Optimal, requires configuration)
直接 agent-to-agent 消息,实时双向。
前提: 双方配置中开启:
json
// ~/.openclaw/openclaw.json
"tools": { "agentToAgent": { "enabled": true } }用法:
sessions_send(sessionKey="agent:<target-agent>:main", message="...")优点: 实时、双向、最简洁
缺点: 默认禁用,需要两端都开启
Direct agent-to-agent messaging, real-time bidirectional.
Prerequisites: Enabled in both parties' configurations:
json
// ~/.openclaw/openclaw.json
"tools": { "agentToAgent": { "enabled": true } }Usage:
sessions_send(sessionKey="agent:<target-agent>:main", message="...")Advantages: Real-time, bidirectional, most concise
Disadvantages: Disabled by default, requires enabling on both ends
2. nodes.run(远程命令执行)
2. nodes.run (Remote Command Execution)
通过已配对的 node 在远程机器上执行命令。
前提: 目标机器已配对为 node 且在线( 检查)
nodes status用法:
nodes(action="run", node="<node-name>", command=["bash", "-c", "<command>"], commandTimeoutMs=30000)注意事项:
- 环境变量可能与本地不同(如代理设置)
- 用 绕过不通的代理
env -u HTTP_PROXY -u HTTPS_PROXY - 复杂命令容易超时,拆分为多个小步骤
- gateway 响应慢时会超时(默认 30s),可调大
commandTimeoutMs
典型场景:
bash
undefinedExecute commands on remote machines via paired nodes.
Prerequisites: Target machine is paired as a node and online (check with )
nodes statusUsage:
nodes(action="run", node="<node-name>", command=["bash", "-c", "<command>"], commandTimeoutMs=30000)Notes:
- Environment variables may differ from local ones (e.g., proxy settings)
- Use to bypass unavailable proxies
env -u HTTP_PROXY -u HTTPS_PROXY - Complex commands are prone to timeouts; split into multiple small steps
- Timeout occurs if gateway responds slowly (default 30s), adjust to a larger value
commandTimeoutMs
Typical Scenarios:
bash
undefined检查文件是否存在
Check if file exists
nodes run: ["bash", "-c", "ls ~/target-dir 2>/dev/null && echo EXISTS || echo NOT_FOUND"]
nodes run: ["bash", "-c", "ls ~/target-dir 2>/dev/null && echo EXISTS || echo NOT_FOUND"]
clone 仓库(注意代理问题)
Clone repository (note proxy issues)
nodes run: ["bash", "-c", "env -u HTTP_PROXY -u HTTPS_PROXY git clone https://github.com/user/repo.git ~/repo 2>&1"]
nodes run: ["bash", "-c", "env -u HTTP_PROXY -u HTTPS_PROXY git clone https://github.com/user/repo.git ~/repo 2>&1"]
创建软链接
Create symbolic link
nodes run: ["bash", "-c", "ln -sfn /source/path /target/path && readlink /target/path"]
undefinednodes run: ["bash", "-c", "ln -sfn /source/path /target/path && readlink /target/path"]
undefined3. openclaw agent CLI(通过 node 调用远程 gateway)
3. openclaw agent CLI (Call Remote Gateway via Node)
在远程 node 上通过 CLI 向目标实例注入消息。
用法:
bash
openclaw agent --session-id <session-id> -m '<message>' --json注意: 需要等 gateway 处理 agent turn,容易超时(60-120s)。适合非紧急通知。
Inject messages to target instances via CLI on remote nodes.
Usage:
bash
openclaw agent --session-id <session-id> -m '<message>' --jsonNote: Requires waiting for gateway to process agent turn, prone to timeouts (60-120s). Suitable for non-urgent notifications.
4. 文件级通信(兜底方案)
4. File-level Communication (Fallback Solution)
直接写入目标实例的 memory 文件,等待 heartbeat 读取。
用法:
bash
undefinedDirectly write to the target instance's memory file and wait for heartbeat to read.
Usage:
bash
undefined通过 nodes.run 写入远程 memory 文件
Write to remote memory file via nodes.run
cat >> <workspace>/memory/YYYY-MM-DD.md << 'EOF'
cat >> <workspace>/memory/YYYY-MM-DD.md << 'EOF'
来自小a的通知 (HH:MM)
Notification from Xiaoa (HH:MM)
<消息内容>
EOF
**优点**: 一定能送达,不依赖实时连接
**缺点**: 非实时,需要等 heartbeat 或新 session 才能读到<Message content>
EOF
```
Advantages: Guaranteed delivery, no dependency on real-time connection
Disadvantages: Non-real-time, requires waiting for heartbeat or new session to read
5. Telegram/消息渠道(受限)
5. Telegram/Messaging Channels (Restricted)
通过 工具发送。
message限制: Telegram bot 之间不能互发消息(403 Forbidden)。仅适用于 bot → 人类 的场景。
Send via tool.
messageRestrictions: Telegram bots cannot send messages to each other (403 Forbidden). Only applicable to bot → human scenarios.
不可行的方式
Infeasible Methods
| 方式 | 原因 |
|---|---|
| Telegram bot → bot | Telegram API 禁止 |
| curl 调远程 gateway REST API | gateway 不暴露 REST 消息接口 |
| sessions_send 未开启 agentToAgent | 返回 forbidden |
| Method | Reason |
|---|---|
| Telegram bot → bot | Prohibited by Telegram API |
| curl calling remote gateway REST API | Gateway does not expose REST messaging interface |
| sessions_send without agentToAgent enabled | Returns forbidden |
实战检查清单
Practical Checklist
- — 目标 node 是否在线?
nodes status - 目标机器有无代理/网络限制?
- SSH key 是否配置?(git clone 用 HTTPS 更稳)
- 超时设置是否足够?
- 软链接路径是否正确?
- — Is the target node online?
nodes status - Does the target machine have proxy/network restrictions?
- Is the SSH key configured? (HTTPS is more stable for git clone)
- Is the timeout setting sufficient?
- Is the symbolic link path correct?
推荐架构
Recommended Architecture
小a (Linux VPS) 小m (Mac-Mini)
├── OpenClaw gateway ├── OpenClaw gateway
├── ~/AGI-Super-Skills (git repo) ├── ~/AGI-Super-Skills (git clone)
├── ~/clawd/skills/ (workspace) ├── ~/.openclaw/workspace/skills → ~/AGI-Super-Skills/skills
│ │
├── nodes.run ──────────────────── ├── paired node (connected)
└── sessions_send ─────────────── └── agent-to-agent (需开启)Xiaoa (Linux VPS) Xiaom (Mac-Mini)
├── OpenClaw gateway ├── OpenClaw gateway
├── ~/AGI-Super-Skills (git repo) ├── ~/AGI-Super-Skills (git clone)
├── ~/clawd/skills/ (workspace) ├── ~/.openclaw/workspace/skills → ~/AGI-Super-Skills/skills
│ │
├── nodes.run ──────────────────── ├── paired node (connected)
└── sessions_send ─────────────── └── agent-to-agent (requires enabling)触发词
Trigger Words
- "给小m发消息"
- "通知另一个实例"
- "跨机器执行"
- "同步到远程"
- "agent间通信"
- "实例间通信"
- "Send message to Xiaom"
- "Notify another instance"
- "Cross-machine execution"
- "Synchronize to remote"
- "Inter-agent communication"
- "Inter-instance communication"