一、Gateway 消息网关:接入 Telegram / 微信等平台

Gateway 是 Hermes 的消息平台接入层,负责连接 Telegram、Discord、Slack、微信等 23+ 平台,接收消息、维护会话、转发处理、回发结果。它还负责跑 cron 调度循环。

Gateway 和 CLI 用同一套数据(配置、会话、记忆、技能),区别是 CLI 是终端一次性交互,Gateway 是长期运行的消息平台进程。

1. 命令

hermes gateway setup                 # 交互式配置消息平台
hermes gateway                       # 前台启动(调试用)
hermes gateway install               # 安装为用户服务(Linux)
sudo hermes gateway install --system # 安装为开机启动系统服务(Linux)
hermes gateway start / stop / status # 启停/查看

2. Telegram Bot 端到端搭建

步骤 1:在 Telegram 搜 @BotFather,发 /newbot,按提示获得 Bot Token。

步骤 2:写入 .env:

echo "TELEGRAM_BOT_TOKEN=1234567890:ABCdef..." >> ~/.hermes/.env
hermes gateway setup

步骤 3:启动:

hermes gateway            # 调试用前台
hermes gateway install && hermes gateway start   # 生产推荐

步骤 4:首次私信 Bot 会收到配对码,本机批准:

hermes pairing list
hermes pairing approve telegram XKGH5N7P

3. 用户权限控制

允许列表(.env):

TELEGRAM_ALLOWED_USERS=123456789,987654321
GATEWAY_ALLOW_ALL_USERS=true   # 不推荐给有终端权限的 bot 开

私信配对:未知用户私信得到一次性配对码,管理员 hermes pairing approve 批准。

配对码 1 小时过期,有速率限制。

4. 支持平台(23+)

Telegram、Discord、Slack、WhatsApp、Signal、钉钉、飞书、企业微信、微信、QQBot、Matrix、Mattermost、Matrix、Email、ntfy(v0.15+ 免账号推送)等。

微信配置示例(.env):

WEIXIN_ACCOUNT_ID=c94b6aa27d45@im.bot
WEIXIN_TOKEN=...
WEIXIN_BASE_URL=https://ilinkai.weixin.qq.com
WEIXIN_DM_POLICY=pairing
WEIXIN_ALLOW_ALL_USERS=true

二、Profile 多实例:跑多个互相隔离的 Agent

Profile 让你跑多个独立的 Hermes 实例,各有一份配置、会话、技能、记忆。用途:一个 coder 写代码,一个 researcher 查资料,互不混淆。

1. 创建 Profile

hermes profile create coder                  # 创建空白 Profile
hermes profile create coder --clone          # 克隆当前配置
hermes profile create backup --clone-all     # 克隆完整状态
hermes profile delete coder                  # 删除

创建后会自动生成同名命令别名,如 coder chat = hermes -p coder chat。

2. 使用 Profile

coder chat                        # 启动 coder 的对话
coder setup                       # coder 的配置向导
coder gateway start               # coder 的 Gateway 服务
coder config set model.default anthropic/claude-sonnet-4

设置默认 Profile:

hermes profile use coder     # 默认用 coder
hermes profile use default   # 恢复

3. 原理

Profile 用 HERMES_HOME 环境变量,每个 Profile 的数据在 ~/.hermes/profiles/<name>/。每个可独立跑自己的 Gateway、自己的 bot token。

三、Delegation 任务委派:创建子 Agent

Hermes 能创建子 Agent 处理独立任务,子 Agent 有自己的对话和终端环境。

1. 单任务

delegate_task(
    goal="Debug why tests fail",
    context="Error: assertion in test_foo.py line 42",
    toolsets=["terminal", "file"],
)

2. 并行批量(默认最多 3 并发)

delegate_task(tasks=[
    {"goal": "Research topic A", "toolsets": ["web"]},
    {"goal": "Research topic B", "toolsets": ["web"]},
    {"goal": "Fix the build", "toolsets": ["terminal", "file"]},
])

3. 关键规则

  • 子 Agent 从零开始,只知道 goal 和 context 两个字段

  • 完成后只把结构化摘要回传(详细过程不保留,省 token)

  • 某些工具子 Agent 不能用:delegation(叶子禁止再委派)、clarify(不能和用户交互)、memory(不写共享记忆)等

4. 嵌套委派

默认是扁平的一层委派。要多层需配置:

delegation:
  max_concurrent_children: 3
  max_spawn_depth: 1
  orchestrator_enabled: true

四、Kanban 多 Agent 协作:核心重点

Kanban 是 Hermes 的多 Agent 协作层——一个可恢复、可审计、可中途介入的工作队列,把任务、依赖、评论、运行记录、工作目录放进持久任务板,让多个具名 Profile 异步协作。

delegate_task 适合短的子任务,Kanban 补上:研究分流、定时循环工作流、数字分身、端到端工程流水线等场景。

1. 三层架构

  • Control Plane:CLI / Gateway / Dashboard(交互入口)

  • State Plane:SQLite board + dispatcher(唯一事实来源)

  • Execution Plane:独立 profile worker 进程(隔离状态)

协调全靠任务板,Profile 之间无直接进程通信。

2. 核心概念

Task 状态流转:

triage → todo → ready → running → done
                    ↓       ↓
                  (依赖满足)  blocked → unblock → ready
  • triage:入口,待拆分

  • todo:已创建等依赖

  • ready:可被 dispatcher 认领

  • running:执行中

  • blocked:需人工介入

  • done / archived:完成/归档

Link:任务间父子依赖,父任务完成子任务才推进。

Comment:跨 Agent 交接协议,worker 启动时读完整评论串。

Workspace:scratch(临时目录)、dir:<path>(已有路径)、worktree(git worktree)。

3. 常用命令

hermes kanban init                          # 初始化看板
hermes kanban create "任务标题" --assignee researcher --body "说明"
hermes kanban list [--mine] [--status S]
hermes kanban show <id>
hermes kanban comment <id> "评论"
hermes kanban complete <id> --summary "..."
hermes kanban block <id> "原因" / unblock <id>
hermes kanban archive <id>
hermes kanban swarm "提示词"               # v0.15+ 一键启动协作拓扑

4. Kanban Swarm:一键协作

一条命令创建 researcher + writer + reviewer 协作拓扑:

hermes kanban swarm "研究 Hermes Agent 的架构并写分析报告" \
  --worker "default:Agent Loop 分析" \
  --worker "default:Skills 系统分析" \
  --worker "default:Gateway 架构分析" \
  --verifier default \
  --synthesizer default

5. Orchestrator Profile:编排者

Orchestrator 负责协调,不执行。拆解流程:

  1. Decomposer 处理 triage 任务,创建子任务图

  2. Orchestrator profile 承接 root task,汇总结果

创建:

hermes profile create orchestrator --clone \
  --description "Kanban 编排者。负责拆解目标、创建任务、指派 profile、汇总结果。"
​
orchestrator tools disable terminal file web browser code_execution
​
hermes config set kanban.orchestrator_profile orchestrator
hermes config set kanban.auto_decompose true

6. 六种协作模式

模式

说明

场景

Fan-out

一个目标拆多个同级并行

多角度研究

Pipeline

上游完成→下游启动

研→写→审→发

Fan-in

多任务汇总到聚合任务

研究综合

Long-running journal

定时反复处理

日报/周报

Human-in-the-loop

阻塞→人工→恢复

需要审批

Fleet farming

一 Profile 管 N 对象

多账号管理

7. Dispatcher 调度器

Dispatcher 是长期循环(默认在 Gateway 内),每 60 秒扫看板,做四件事:

  1. stale recovery:回收异常 running 任务

  2. recompute ready:推进依赖满足的任务

  3. atomic claim:CAS 式 SQL 原子认领(保证并发安全)

  4. 启动 worker:启动对应 profile worker

连续失败超重试上限会进入 blocked 等待人工。

五、Dashboard 与监控

Hermes 提供 Web 管理面板:

hermes dashboard --port 8080   # 浏览器打开 http://127.0.0.1:8080

v0.16 升级为完整 Web 面板,支持:消息渠道配置、MCP 目录管理、凭证管理、Webhooks、Gateway 控制、看板监控,且支持简体中文界面。