1. 架构
1
2
3
4
5
6
7
| ┌──────────────────────┐ A2A/JSON-RPC ┌──────────────────────┐
│ OpenClaw 服务器 A │ ◄──────────────────────────► │ OpenClaw 服务器 B │
│ │ (Tailscale / 内网) │ │
│ Agent: AGI │ │ Agent: Coco │
│ A2A 端口: 18800 │ │ A2A 端口: 18800 │
│ Peer: Server-B │ │ Peer: Server-A │
└──────────────────────┘ └──────────────────────┘
|
要求:
- OpenClaw ≥ 2026.3.0 已安装并运行
- OpenClaw 之间网络连通
- Node.js ≥ 22
2. 安装
1
2
3
4
5
| mkdir -p ~/.openclaw/workspace/plugins
cd ~/.openclaw/workspace/plugins
git clone https://github.com/win4r/openclaw-a2a-gateway.git a2a-gateway
cd a2a-gateway
npm install --production
|
1
| openclaw plugins install ~/.openclaw/workspace/plugins/a2a-gateway --dangerously-force-unsafe-install
|
不同的 OpenClaw 版本,忽略安全的参数会有所差异,需要查看一下 --help 的说明。
1
| openclaw gateway restart
|
3. 注册插件
1
| openclaw config get plugins.allow
|
1
2
3
4
5
| openclaw config set plugins.allow '["a2a-gateway"]'
openclaw config set plugins.load.paths '["/root/.openclaw/workspace/plugins/a2a-gateway"]'
openclaw config set plugins.entries.a2a-gateway.enabled true
|
4. 配置 Agent
配置当前 Agent 所需的信息
1
2
3
4
| openclaw config set plugins.entries.a2a-gateway.config.agentCard.name 'Ops-Copilot'
openclaw config set plugins.entries.a2a-gateway.config.agentCard.description '智能运维助手'
openclaw config set plugins.entries.a2a-gateway.config.agentCard.url 'http://1.1.1.1:18800/a2a/jsonrpc'
openclaw config set plugins.entries.a2a-gateway.config.agentCard.skills '[{"id":"ops-doctor","name":"运维诊断","description":"针对节点、集群、负载的异常诊断"}]'
|
1
2
| openclaw config set plugins.entries.a2a-gateway.config.server.host '0.0.0.0'
openclaw config set plugins.entries.a2a-gateway.config.server.port 18800
|
生成入站认证 Token:
1
2
| TOKEN=$(openssl rand -hex 24)
echo "A2A Token: $TOKEN"
|
1
2
| openclaw config set plugins.entries.a2a-gateway.config.security.inboundAuth 'bearer'
openclaw config set plugins.entries.a2a-gateway.config.security.token "$TOKEN"
|
这个 TOKEN 其他 Agent 连接过来时,进行鉴权。
1
| openclaw config set plugins.entries.a2a-gateway.config.routing.defaultAgentId 'main'
|
默认使用 main
1
| openclaw gateway restart
|
1
| curl -s http://localhost:18800/.well-known/agent-card.json | python3 -m json.tool
|
- 验证 agent 能正常接收其他 agent 的调用
1
2
3
4
| node /home/kas/.openclaw/workspace/plugins/a2a-gateway/skill/scripts/a2a-send.mjs \
--peer-url http://x.x.x.x:18800 \
--token xxx \
--message "你好,来自外部调用的消息"
|
其实另外一个消息调用此 agent 也是基于此方法。
5. 其他 Agent 配置
参考上面的步骤
1
2
3
4
5
6
7
8
9
10
| openclaw config set plugins.entries.a2a-gateway.config.peers '[
{
"name": "ops-copilot",
"agentCardUrl": "http://1.1.1.1:18800/.well-known/agent-card.json",
"auth": {
"type": "bearer",
"token": "xxxxxxxxxxx"
}
}
]'
|
在 workspace/TOOLS.md 添加以下内容,告诉 OpenClaw 怎么使用。
https://raw.githubusercontent.com/win4r/openclaw-a2a-gateway/refs/heads/master/skill/references/tools-md-template.md
1
| openclaw agent --agent main -m "通过 A2A 让 ops-copilot 查一下集群状态"
|
此时,会向另外一个 agent 发送处理请求。
6. 参考
https://github.com/win4r/openclaw-a2a-gateway/issues/53
https://github.com/win4r/openclaw-a2a-gateway/blob/master/README_CN.md#3-配置-agent-card