🏗️ 架构概览
🌐 Soraecho 网络
Agent 注册 & 发现
🔀 Unified Gateway (8888)
统一网关 / A2A 路由 / OpenAI 兼容
🏭 Agent Factory (8877)
Agent 生命周期 & 任务委托
🧠 maian-main
协调者 / 模型对话
⚙️ maian-worker
代码执行 / 工具调用
🔧 maian-tool
文件系统 / 工具
🎭 Agent 角色定义
maian-main 协调者 Agent
能力: model.chat · a2a · discovery
负责接收用户请求,协调其他 Agent 完成任务。通过 /delegate/ 接口委托任务给 worker 或 tool。
maian-worker 执行者 Agent
能力: tool.execute · code.run · a2a
执行代码、运行工具、处理计算任务。被 main 委托执行具体工作。
maian-tool 工具 Agent
能力: tool.execute · filesystem · a2a
提供文件系统访问、外部工具调用等能力。
🔗 任务委托协议
Agent 间通过 POST /delegate/{from}/{to} 实现任务委托:
# maian-main 委托 maian-worker 执行代码
POST /delegate/maian-main/maian-worker
{
"action": "run_code",
"code": "print(1+1)"
}
# 响应
{
"task_id": "f3a036a1-...",
"status": "completed",
"result": {"output": "2\n", "error": null}
}
委托过程:
1️⃣ maian-main 接收用户请求
2️⃣ 判断需要代码执行能力 → 委托给 maian-worker
3️⃣ Agent Factory 直接执行 worker 的逻辑(无需 HTTP 回环)
4️⃣ 返回结果 + 记录任务状态(GET /tasks/{task_id})
📡 A2A (Agent-to-Agent) 协议
基于 HTTP 的 Agent 间通信协议,兼容 Soraecho 网络:
# A2A 任务请求
POST /a2a/v1/task/{agent_name}
{
"task_id": "uuid",
"payload": {
"action": "run_code",
"code": "..."
}
}
# A2A 任务响应
{
"status": "completed",
"result": {...}
}
跨 OS 调用:通过 Soraecho 发现远程 Agent → 获取 endpoints → 直连调用(不经过 Soraecho 转发)
🔀 Unified Gateway (8888)
对外统一入口,整合:
✅ OpenAI 兼容接口 POST /v1/chat/completions
✅ A2A 路由 POST /a2a/v1/task/{agent_id} → 转发到 Agent Factory (8877)
✅ Agent 列表 GET /a2a/v1/agents
✅ Soraecho 注册 启动时自动注册到 Soraecho 网络
🔐 DID 签名验证
跨 OS 调用强制 Ed25519 签名验证,确保请求完整性和来源可信。
签名流程
1. Agent 用 Ed25519 私钥对 payload 签名
2. 签名放入 HTTP 头 X-Maian-Signature
3. 接收方验证签名 + payload hash
4. 防篡改 / 防重放(timestamp ±5 分钟窗口)
信任等级
L0 同进程 L1 同OS内网 L2 跨OS签名 L3 跨OS+结算
向后兼容:无签名请求允许(L0/L1),跨 OS 建议强制签名(L2+)。
🚀 快速开始
1. 启动服务
# Agent Factory (8877)
python3 maian_agent_factory.py
# Unified Gateway (8888)
python3 -m uvicorn hermes_adapter:app --host 0.0.0.0 --port 8888
2. 调用 Agent
# 直接调用(OpenAI 兼容)
curl http://43.156.25.118:8888/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"deepseek-v4-flash","messages":[{"role":"user","content":"hi"}]}'
# A2A 调用
curl http://43.156.25.118/a2a/v1/task/maian-main \
-H "Content-Type: application/json" \
-d '{"task_id":"t1","payload":{"prompt":"hi"}}'