Phase 0-2: Schema cleanup, typed relations, event-driven automation

- Phase 0: AGENTS.md cleanup (dedup quotes, renumber sections, merge qmd)
- Phase 1: typed relations (manage-relations.py, graph-search.py, check-staleness.py, detect-conflicts.py)
- Phase 2: frontmatter validator, weekly lint, knowledge promotion, git hooks
- Fix .gitignore to track tools/ and .githooks/
- Fix git remote URL (remove plaintext token)
- New wiki pages: 504 pages, 34 raw sources
This commit is contained in:
hehaiguang1123
2026-07-01 08:05:43 +08:00
parent e544d6e04a
commit a6f05ab2d5
1067 changed files with 522992 additions and 819 deletions
@@ -0,0 +1,265 @@
# Hermes 多 Agent 协作机制官方文档解析
> 来源:Hermes Agent 官方文档(hermesagent.org.cn
> 整理时间:2026-05-20
> 用途:Hermes(二休)建立独立于 OpenClaw 的多 Agent 协作闭环
---
## 核心发现:Hermes 有三套独立的 Multi-Agent 机制
这和 OpenClaw 的持久 Agentmain/news/assistant/research)模式完全不同。Hermes 的多 Agent 是**可组合的三层架构**:
| 机制 | OpenClaw 对应 | 用途 | 特点 |
|------|-------------|------|------|
| **Profiles** | 配置文件 | 同一机器运行多个独立 Agent | 完全隔离的配置/记忆/技能/网关 |
| **delegate_task** | agentToAgent | 临时委派子 Agent | 最多 3 并发,隔离上下文,父 Agent 只收摘要 |
| **cron jobs** | 定时任务 | autonomous Agent | 后台自动运行,可链式编排 |
---
## 1. Profiles(配置文件)
### 核心概念
> 在同一台机器上运行多个独立的 Hermes Agent —— 每个 Agent 拥有自己的配置、API 密钥、记忆、会话、技能和网关。
### 关键特点
- 创建 Profile 后自动获得命令别名(如 `hermes profile create coder``coder chat`
- **完全隔离**:每个 Profile 有独立的 `config.yaml``.env``SOUL.md`、记忆、会话、技能、定时任务
- 不同用途可运行不同 Profile:代码助手、个人机器人、研究 Agent
- 不会相互干扰
### 命令示例
```bash
hermes profile create research # 创建 research Profile
research setup # 配置 API 密钥和模型
research chat # 开始聊天
hermes profile list # 列出所有 Profile
hermes profile use research # 切换默认 Profile
```
### 适用场景
- 需要**长期运行**的专用 Agent(如专门的代码 Agent、研究 Agent
- 不同 Agent 需要不同模型或 API 密钥
- 需要完全隔离的记忆和上下文
---
## 2. delegate_task(子 Agent 委派)
### 官方文档核心要点
> `delegate_task` 工具会启动具有隔离上下文、受限工具集和独立终端会话的子 AIAgent 实例。每个子 Agent 都会获得一个全新的对话,并独立工作——只有其最终摘要才会进入父 Agent 的上下文。
### 重要约束
:::warning 子 Agent 一无所知
子 Agent 从一个**完全全新的对话**开始。它们对父 Agent 的对话历史、之前的工具调用或任何先前讨论的内容都**一无所知**。唯一上下文来自 `goal``context` 字段。
:::
**正确传递上下文:**
```python
# BAD - subagent 不知道 "the error" 是什么
delegate_task(goal="Fix the error")
# GOOD - subagent 拥有所需的所有内容
delegate_task(
goal="Fix the TypeError in api/handlers.py",
context="""The file api/handlers.py has a TypeError on line 47:
'NoneType' object has no attribute 'get'.
The function process_request() receives a dict from parse_body(),
but parse_body() returns None when Content-Type is missing.
The project is at /home/user/myproject and uses Python 3.11."""
)
```
### 单个任务
```python
delegate_task(
goal="Debug why tests fail",
context="Error: assertion in test_foo.py line 42",
toolsets=["terminal", "file"]
)
```
### 并行批量任务(最多 3 并发)
```python
delegate_task(tasks=[
{"goal": "Research topic A", "toolsets": ["web"]},
{"goal": "Research topic B", "toolsets": ["web"]},
{"goal": "Fix the build", "toolsets": ["terminal", "file"]}
])
```
### 工具集选择建议
| 任务类型 | 工具集 |
|---------|--------|
| 代码审查 / 重构 | `["terminal", "file"]` |
| 网络研究 | `["web"]` |
| 浏览器自动化 | `["browser"]` |
| 定时任务管理 | `["cronjob"]` |
| 文件操作 | `["file"]` |
| 混合任务 | `["terminal", "file", "web"]` |
### 最大并发数
默认最多 **3 个并发子 Agent**。超出则排队等待。
### 深度限制
子 Agentleaf role**不能**进一步委派。Orchestrator role 可以委派,但 nesting depth 有限制。
---
## 3. cron jobs(定时 Autonomous Agent
### 官方文档要点
- Jobs 运行在**新鲜 session** 中,无当前聊天上下文
- Prompts 必须**自包含**
- 如果提供 skills,按顺序加载后执行 prompt
- 支持**链式编排**:Job A 收集数据 → Job B 处理 → Job C 汇总
- Delivery 可指定:`origin`(回当前聊天)、`local`(仅保存)、`all`(所有连接渠道)
### delivery 参数
| 值 | 行为 |
|---|------|
| `origin` | 回当前聊天(默认) |
| `local` | 仅保存到 `~/.hermes/cron/output/` |
| `all` | 广播到所有已连接渠道 |
| `platform:chat_id` | 指定特定渠道 |
### 关键安全规则
> **cron-run sessions should not recursively schedule more cron jobs.**
---
## Hermes Multi-Agent 协作闭环设计
基于官方文档三机制,设计 Hermes(二休)的多 Agent 协作闭环:
### 机制选型
| 任务类型 | 推荐机制 | 说明 |
|---------|---------|------|
| 临时性研究任务 | `delegate_task` | Web 并行研究,1 次性 |
| 临时性编码任务 | `delegate_task` | Terminal/File 工具集 |
| 长期专用 Agent | **Profiles** | 独立的 research/coder Agent |
| 定期自动任务 | **cron jobs** | 每小时/每天执行 |
### Hermes 协作闭环架构
```
微信指令(老何)
┌─────────────────────────────────────┐
│ Hermes(二休)- 主 Agent │
│ - 理解任务 │
│ - 拆解步骤 │
│ - 判断:直接做 / delegate / cron │
└─────────────────────────────────────┘
├──────────────────┬──────────────────┐
▼ ▼ ▼
delegate_task delegate_task cron job
│ │ │
▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────────┐
│Research │ │ Coding │ │ Autonomous │
│ Agent │ │ Agent │ │ Agent │
│(临时) │ │(临时) │ │(定时) │
└─────────┘ └─────────┘ └─────────────┘
│ │ │
└──────────────────┴──────────────────┘
结果写 Wiki / Git push
PC 端 OpenCode 读取处理
```
### 与 OpenClaw 的关键区别
| 维度 | OpenClaw | Hermes |
|------|----------|--------|
| Agent 类型 | 持久 Agentmain/news/assistant/research | Profiles(持久)+ delegate_task(临时)+ cron(定时) |
| 上下文共享 | 共享对话历史 | delegate_task 完全隔离,Profiles 独立隔离 |
| 委派方式 | agentToAgent 配置 | delegate_task 工具调用 |
| 通信机制 | 共享消息通道 | Profile 间通过 Wiki/Git 间接协作 |
| 向量检索 | embedding-3OpenAI API | embedding-3OpenAI API |
### Wiki 协作路径
```
Hermes委派子Agent → 处理结果写入Wiki → Git push到Gitee
PC端 OpenCode 读取Wiki
处理结果写回Wiki → Git push
Hermes 读取Wiki → 汇总结果
```
---
## 实际配置记录
### Profile 创建(2026-05-20
| Profile | 模型 | 用途 | 目录 |
|--------|------|------|------|
| `research` | glm-4.7 | 网络研究、信息收集 | `/home/ubuntu/.hermes/profiles/research/` |
| `coder` | MiniMax-M2.7 | 代码审查/重构/执行 | `/home/ubuntu/.hermes/profiles/coder/` |
### Wiki 协作目录
```
raw/
├── research/ # research profile 输出
└── coder/ # coder profile 输出
```
### PC 端协作流程
```
1. Hermes 委派 research/coder 子 Agent
2. 结果写入 /home/obsidian/wiki/raw/research/ 或 raw/coder/
3. Git push 到 Gitee
4. PC 端 Obsidian Git 插件定时拉取
5. PC OpenCode 读取处理
6. PC 端处理结果写回 Wiki → Git push
7. Hermes 读取 Wiki 汇总
```
### Profile 命令
```bash
research chat # 进入 research profile
coder chat # 进入 coder profile
research gateway start # 启动 research 网关(当前不需要)
coder gateway start # 启动 coder 网关(当前不需要)
```
---
## 参考文档
- [子 Agent 委派](https://hermesagent.org.cn/docs/user-guide/features/delegation)
- [配置文件](https://hermesagent.org.cn/docs/user-guide/profiles)
- [Agent Loop 内部机制](https://hermesagent.org.cn/docs/developer-guide/agent-loop)
- [架构](https://hermesagent.org.cn/docs/developer-guide/architecture)