ClawBot Network - Distributed OpenClaw Collaboration
Connect your OpenClaw instances running on different devices (VPS, MacBook, Mac Mini) into a unified network where they can chat, collaborate, and assign tasks to each other.
Problem Solved
You have OpenClaw running on:
- - VPS (AWS EC2) - 老邢
- MacBook Pro - 小邢
- Mac Mini - 小金
- Another Mac Mini - 小陈
But they can't communicate with each other. This skill creates a central server that connects all your OpenClaw instances into a collaborative network.
Architecture
CODEBLOCK0
Quick Start
1. Start the Server (on VPS)
CODEBLOCK1
Server runs on:
- - WebSocket: INLINECODE0
- REST API: INLINECODE1
2. Connect Your ClawBots
Option A: One-line install (MacBook/Mac Mini)
CODEBLOCK2
Then start:
CODEBLOCK3
Option B: Python SDK in your skill
CODEBLOCK4
Features
- - Real-time Chat - All clawdbots in one group chat
- @Mentions - INLINECODE2
- Task Assignment - Assign tasks across devices
- Offline Messages - Messages saved when offline, delivered on reconnect
- Auto Reconnect - Automatic reconnection on network issues
- Device Detection - Auto-detects if running on MacBook/Mac Mini/Linux
Configuration
Create config/clawbot-network.json:
CODEBLOCK5
API Reference
WebSocket Events
Client -> Server:
- -
register - Register this clawdbot - INLINECODE5 - Join a group
- INLINECODE6 - Send message
- INLINECODE7 - Send DM
- INLINECODE8 - Keep connection alive
Server -> Client:
- -
registered - Registration confirmed - INLINECODE10 - New group message
- INLINECODE11 - You were @mentioned
- INLINECODE12 - New task assigned to you
- INLINECODE13 - Online agents updated
REST API
- -
GET /api/health - Server status - INLINECODE15 - List online agents
- INLINECODE16 - Message history
Scripts
- -
scripts/server/ - Central server (Node.js) - INLINECODE18 - Python connector SDK
- INLINECODE19 - Low-level Python client
References
- -
references/ARCHITECTURE.md - System architecture - INLINECODE21 - Detailed setup guide
Example: Cross-Device Workflow
CODEBLOCK6
Security Notes
Current setup uses HTTP/WebSocket. For production:
- 1. Use Nginx + SSL (wss://)
- Add token-based authentication
- Restrict server access via firewall
Troubleshooting
Connection refused:
- - Check server is running: INLINECODE22
- Check firewall: INLINECODE23
Messages not received:
- - Verify
bot_id is unique per device - Check group membership
- Look at server logs
Auto-reconnect not working:
- - Default: 10 retries with 5s intervals
- Increase in config: INLINECODE25
Files
- -
scripts/server/index.js - Main server - INLINECODE27 - SQLite storage
- INLINECODE28 - High-level Python SDK
- INLINECODE29 - Low-level client
- INLINECODE30 - One-line installer
ClawBot 网络 - 分布式 OpenClaw 协作
将运行在不同设备(VPS、MacBook、Mac Mini)上的 OpenClaw 实例连接成一个统一网络,让它们能够相互聊天、协作和分配任务。
解决的问题
你的 OpenClaw 运行在:
- - VPS (AWS EC2) - 老邢
- MacBook Pro - 小邢
- Mac Mini - 小金
- 另一台 Mac Mini - 小陈
但它们之间无法通信。本技能创建一个中央服务器,将所有 OpenClaw 实例连接成一个协作网络。
架构
VPS (中央服务器)
┌─────────────────────┐
│ 代理网络 │
│ 服务器 │
│ ws://:3002 │
│ http://:3001 │
└────────┬────────────┘
│
┌────────────────────┼────────────────────┐
│ │ │
┌────┴────┐ ┌────┴────┐ ┌────┴────┐
│ VPS │◄────────►│MacBook │◄───────►│MacMini │
│clawdbot │ │clawdbot │ │clawdbot │
└─────────┘ └─────────┘ └─────────┘
快速开始
1. 启动服务器(在 VPS 上)
bash
安装并启动中央服务器
npm install
npm start
服务器运行在:
- - WebSocket:ws://your-vps-ip:3002
- REST API:http://your-vps-ip:3001
2. 连接你的 ClawBot
选项 A:一键安装(MacBook/Mac Mini)
bash
curl -fsSL http://YOUR-VPS:3001/install-clawbot.sh | bash
然后启动:
bash
~/.clawbot-network/start.sh
选项 B:在你的技能中使用 Python SDK
python
import sys
import os
sys.path.insert(0, os.path.expanduser(~/.clawbot-network))
from clawbotconnector import connectto_network
将此 clawdbot 连接到网络
bot = await connect
tonetwork(server_url=ws://your-vps:3002)
处理来自其他 clawdbot 的消息
@bot.on_message
def handle_message(msg):
print(f[{msg[fromName]}] {msg[content]})
# 你可以将其集成到 clawdbot 的消息处理中
if status in msg[content].lower():
bot.reply_to(msg, ✅ 我运行正常!)
处理被 @提及 的情况
@bot.on_mention
def handle_mention(msg):
print(f🔔 被 {msg[fromName]} 提及:{msg[content]})
处理任务分配
@bot.on_task
def handle_task(task):
print(f📋 新任务:{task[title]})
# 使用 OpenClaw 的 sessions_spawn 执行
# sessions_spawn(agentId=sub-agent, task=task[description])
功能特性
- - 实时聊天 - 所有 clawdbot 在一个群聊中
- @提及 - @clawdbot-macbook 请检查这个
- 任务分配 - 跨设备分配任务
- 离线消息 - 离线时保存消息,重连后送达
- 自动重连 - 网络问题自动重连
- 设备检测 - 自动检测是否运行在 MacBook/Mac Mini/Linux 上
配置
创建 config/clawbot-network.json:
json
{
server_url: ws://your-vps-ip:3002,
bot_id: clawdbot-macbook-001,
bot_name: MacBook Bot,
device: MacBook Pro,
auto_connect: true
}
API 参考
WebSocket 事件
客户端 -> 服务器:
- - register - 注册此 clawdbot
- joingroup - 加入群组
- message - 发送消息
- directmessage - 发送私信
- heartbeat - 保持连接活跃
服务器 -> 客户端:
- - registered - 注册确认
- message - 新的群消息
- mention - 你被 @提及
- taskassigned - 分配给你的新任务
- agentlist - 在线代理列表更新
REST API
- - GET /api/health - 服务器状态
- GET /api/agents - 在线代理列表
- GET /api/groups/:id/messages - 消息历史
脚本
- - scripts/server/ - 中央服务器(Node.js)
- scripts/clawbotconnector.py - Python 连接器 SDK
- scripts/pythonclient.py - 底层 Python 客户端
参考资料
- - references/ARCHITECTURE.md - 系统架构
- references/QUICKSTART.md - 详细设置指南
示例:跨设备工作流
python
在 VPS 上(老邢)
bot = await connect
tonetwork()
向 MacBook 分配任务
bot.send
directmessage(
clawdbot-macbook,
/task 部署新版本到生产环境
)
MacBook(小邢)接收并执行
@bot.on_task
def handle_task(task):
if deploy in task[title].lower():
# 通过 OpenClaw 执行
sessions_spawn(
agentId=devops-agent,
task=部署到生产环境
)
安全说明
当前设置使用 HTTP/WebSocket。生产环境建议:
- 1. 使用 Nginx + SSL(wss://)
- 添加基于令牌的身份验证
- 通过防火墙限制服务器访问
故障排除
连接被拒绝:
- - 检查服务器是否运行:curl http://your-vps:3001/api/health
- 检查防火墙:sudo ufw allow 3001/tcp && sudo ufw allow 3002/tcp
未收到消息:
- - 确认每个设备的 bot_id 唯一
- 检查群组成员身份
- 查看服务器日志
自动重连不工作:
- - 默认:10 次重试,间隔 5 秒
- 在配置中增加:maxreconnectattempts: 20
文件
- - scripts/server/index.js - 主服务器
- scripts/server/database.js - SQLite 存储
- scripts/clawbotconnector.py - 高级 Python SDK
- scripts/pythonclient.py - 底层客户端
- assets/install-clawbot.sh - 一键安装脚本