






















最后一章面向工程师与研究者。我们会讲 Hermes 的 插件系统(Plugin、Memory Provider、Context Engine)、Hooks(Gateway / Plugin / Shell 三套)、贡献开发流程、批量轨迹与 RL 训练、安全与运维清单。学完之后,你不只是在"用 Hermes",而是可以"扩展、改造、研究 Hermes"。
Hermes 的插件接口分三类(hermes_cli/plugins.py):
| 类型 | 解决什么 | 注册形式 |
|---|---|---|
| General Plugin | 加新工具、注册 hook、贴自定义命令 | plugins/<name>/plugin.py 暴露 register(ctx) |
| Memory Provider Plugin | 替换或扩展记忆后端(典型:Honcho、ByteRover、Mem0、Hindsight…) | 实现 MemoryProvider ABC |
| Context Engine Plugin | 替换默认的"上下文压缩 / 窗口管理" 策略 | 实现 ContextEngine ABC |
插件目录默认在:
hermes-agent/plugins/~/.hermes/plugins/<name>/启用:
hermes plugins list
hermes plugins enable my-plugin
hermes plugins disable my-plugin
hermes plugins reload my-plugin
或在 config.yaml:
plugins:
enabled:
- memory:honcho
- context:summarizer-v2
- my-plugin
最小目录:
~/.hermes/plugins/my-plugin/
├── plugin.yaml
└── plugin.py
plugin.yaml:
name: my-plugin
description: Demo plugin that adds a fortune tool and a hook
version: 0.1.0
entry: plugin:register
requires:
hermes_agent: ">=0.10.0"
plugin.py:
from hermes_cli.plugins import PluginContext
def register(ctx: PluginContext):
@ctx.tool(name="fortune", description="返回一句箴言")
def fortune(category: str = "default") -> str:
return random.choice(...)
@ctx.hook("agent:end")
async def log_end(event_type, context):
ctx.logger.info(f"agent done in {context['duration_ms']}ms")
PluginContext 提供:
ctx.tool(...):注册工具;ctx.hook(event):注册 hook;ctx.command(...):注册斜杠命令;ctx.config:访问 config.yaml;ctx.profile、ctx.home_dir、ctx.logger、ctx.aux_llm() 等便利。启用后即生效:
hermes plugins enable my-plugin
hermes
> /fortune
继承 agent.memory_provider.MemoryProvider:
from agent.memory_provider import MemoryProvider, MemoryEntry
class MyKVMemory(MemoryProvider):
def __init__(self, ctx):
self.kv = SomeKV("...")
async def load(self, target: str) -> list[MemoryEntry]:
return [MemoryEntry(**e) for e in await self.kv.list(target)]
async def add(self, target, content): ...
async def replace(self, target, old_text, content): ...
async def remove(self, target, old_text): ...
async def render_for_prompt(self, target) -> str:
...
注册:
def register(ctx):
ctx.register_memory_provider("my-kv", MyKVMemory(ctx))
启用:hermes plugins enable memory:my-kv,然后 hermes config set memory.provider my-kv。
Hermes 仓库里 plugins/memory/honcho/ 是 Honcho 的标准实现,可以作为最完整的范例。
agent.context_engine.ContextEngine ABC 决定:
默认实现是 agent.context_compressor.DefaultContextEngine(有损摘要)。如果你想接 retrieval、滑窗、长上下文压缩等:
class RetrievalAugContextEngine(ContextEngine):
def assemble_system_prompt(self, ctx): ...
def compress(self, history, target_tokens): ...
def estimate_tokens(self, msgs): ...
注册并 hermes config set context.engine my-engine 即可。这是研究者把自己的 idea 嵌进 Hermes 的最佳入口。
Hermes 同时存在三套 hook,分工明确:
| 系统 | 注册位置 | 跑在哪 | 典型用途 |
|---|---|---|---|
| Gateway Hooks | ~/.hermes/hooks/<name>/HOOK.yaml + handler.py |
仅 Gateway | 平台日志、告警、Webhook 转发 |
| Plugin Hooks | 插件中 ctx.register_hook() |
CLI + Gateway | 工具拦截、指标采集、护栏 |
| Shell Hooks | ~/.hermes/config.yaml 的 hooks: 块 |
CLI + Gateway | 一行脚本搞定(替代写 plugin) |
事件清单(节选):
agent:start、agent:step、agent:end、message:in、message:out、command:<name>、tool:before、tool:after、tool:approval、memory:write、memory:flush、compress:start、compress:done、pairing:created、session:create、session:end 等。
hooks:
pre_tool_terminal: ~/.hermes/hooks/redact-secrets.sh
post_message_out: ~/.hermes/hooks/log-out.sh
脚本通过 stdin 拿 JSON event,stdout 返回的 JSON 可以拒绝({"deny": true, "reason": "..."})或修改输出。详细见 user-guide/features/hooks.md。
如果某个 IM 平台还没在 gateway/platforms/ 中:
PlatformAdapter 抽象类(gateway/platforms/base.py);start()、stop()、send(message)、on_event(callback) 等钩子;gateway/platforms/__init__.py;user-guide/messaging/<name>.md。详见 developer-guide/adding-platform-adapter.md(或在 developer-guide/contributing.md 找入口)。
hermes_cli/auth.py + hermes_cli/runtime_provider.py 是 Provider 的核心。新增一个 OpenAI 兼容 Provider 几乎只要:
PROVIDER_REGISTRY["my-provider"] = ProviderSpec(
label="My Provider",
api_mode="chat_completions",
base_url="https://api.my.example/v1",
api_key_env="MY_API_KEY",
list_models=lambda: ["my/model-1", "my/model-2"],
)
然后 hermes model 就会列出来。详细见 developer-guide/adding-providers.md。
绝大多数情况不需要——MCP / Plugin 已能覆盖。但若你想贡献:
tools/ 加一个 my_tool.py,导出函数 + 描述 + JSON schema;tools/registry.py 注册;toolsets.py 加入合适分组;tests/tools/。详见 developer-guide/adding-tools.md 与 creating-skills.md(用于"先沉淀技能再升级成工具")。
仓库 developer-guide/contributing.md:
./setup-hermes.sh 建 venv;pyproject.toml 中 ruff/black/pytest 配置;scripts/run_tests.sh;hermes doctor 输出与变更说明;代码风格:
batch_runner.py 是 Hermes 把"日常对话/工具调用"转成训练数据的入口。
hermes batch run \
--prompts ./prompts.jsonl \
--model anthropic/claude-opus-4.6 \
--concurrency 8 \
--toolsets web,terminal,file \
--output ./trajectories.jsonl
输出每行一份 ShareGPT-format 轨迹(含 system / user / assistant / tool 完整序列)。可以直接喂给 LoRA / SFT 训练。
user-guide/features/batch-processing.md 给了详尽参数。
Hermes 与 Atropos 同源,在 environments/ 内提供若干 RL 兼容环境,让你能用 Hermes 真实跑出来的 trajectory 训练新一代工具调用模型。
user-guide/features/rl-training.md 介绍:
tinker-atropos、mini_swe_runner.py 等脚手架)。如果你只是日常用户,可以忽略本节。但对模型团队,这是 Hermes 一个重要的"研究价值"。
把 Hermes 推到生产 / 团队前,过一遍下面的清单:
| 现象 | 怀疑 | 操作 |
|---|---|---|
| 启动慢 | MCP server 被 npx 拉拽 | 预装包;分服务延迟启动 |
| 频繁重新压缩 | 上下文阈值太低 | 调高 context.compress_threshold |
| 子代理超时 | iteration_budget 不够 | 加 delegation.iteration_budget_per_subagent |
| Provider 反复 fallback | 主家长期挂 | 重排 fallback 优先级;考虑切主家 |
| 工具 schema 报错 | 自定义 plugin 写错 | HERMES_LOG_LEVEL=debug hermes;看 plugin loader 输出 |
| Telegram 一直 "Conflict" | 多个进程登录同一 bot | 用 hermes gateway status;关其它实例 |
| Cron 漂移 | 时区错 / 系统时间没同步 | 配 cron.timezone;装 chrony/systemd-timesyncd |
| 浏览器 hang | chromium-local 在 headless 服务器没 X |
切 browserbase;或 Xvfb |
| Voice STT 慢 | OpenAI Whisper 跨海延迟 | 切 Groq;或本地 whisper.cpp |
把所有章节融合,一份工程师/研究者实际推荐的长期工作流:
hermes setup、选 OpenRouter + Anthropic 做主,DeepSeek 做 aux;启用 docker 后端;启用 Telegram + 邮件;写 SOUL.md。AGENTS.md;让 Agent 把你的环境/偏好写进 MEMORY/USER;开 Honcho。hermes batch run 生成训练数据;用 Atropos 跑 RL 训练你自己的模型。~/.hermes/{memories,skills,SOUL.md} 同步进 dotfiles,跨设备无缝;个性化技能包成 hub 给同事用。到这里,Hermes 不再是"一个工具",它是你 AI 工作方式的 底盘。
至此 12 章教程结束。Hermes Agent 不只是一个 Agent 框架——它是一份对"长期共生型 AI 助理"应该是什么样子的工程化答卷。 把它跑起来、用起来、调起来、扩起来,你会越来越体会到这套架构的诚意。Happy hacking ☤
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。