name: interagent-communication title: Agent 跨实例通信工具 description: 两个 Hermes Agent 实例通过 API Server 互调,实现跨实例协作
Agent 跨实例通信
架构
通信方式:通过 OpenAI 兼容的 POST /v1/chat/completions API。
脚本位置
/root/.hermes/scripts/
├── interagent.py # 核心通信脚本
├── agent-a-to-b.sh # friend → niouma-doufu 快捷命令
└── agent-b-to-a.sh # niouma-doufu → friend 快捷命令
用法
从当前实例(friend)调 niouma-doufu
# 基本用法
python3 /root/.hermes/scripts/interagent.py --to niouma "帮我查一下服务器负载"
# 用快捷脚本
/root/.hermes/scripts/agent-a-to-b.sh "ping,回复pong即可"
# 设置最大 token 数
python3 /root/.hermes/scripts/interagent.py --to niouma "写首诗" --max-tokens 500
从 niouma-doufu 调 friend
在 niouma-doufu 的终端环境里执行:
python3 /root/.hermes/scripts/interagent.py --to friend "你是哪个实例?"
# 或用快捷脚本
/root/.hermes/scripts/agent-b-to-a.sh "ping"
通过 stdin 传消息
实例配置
| 实例 | 端口 | API Key | Profile |
|---|---|---|---|
| friend | 8644 | f-597cf6...86a8e | friend |
| niouma-doufu | 8643 | 3a9146e8...41b | niouma-doufu |
合作模式建议
| 场景 | 方式 | 说明 |
|---|---|---|
| 派单式协作 | interagent.py → API | A 让 B 执行任务并返回结果 |
| 协商纠错 | 飞书同一群聊 | 双方都能看到消息,互相引用 |
| 持久化状态共享 | 共享文件 | 大量结构化数据、中间状态 |
限制
- 只能同步调用,无法做 SSE 流式实时响应
- 被调用的 agent 没有当前对话上下文,消息需要自包含
- 不能跨机器(都是 localhost)