惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
L
LINUX DO - 热门话题
Blog — PlanetScale
Blog — PlanetScale
博客园 - Franky
J
Java Code Geeks
腾讯CDC
博客园 - 聂微东
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
Last Week in AI
Last Week in AI
量子位
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Schneier on Security
C
CERT Recently Published Vulnerability Notes
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
有赞技术团队
有赞技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Securelist
AWS News Blog
AWS News Blog
GbyAI
GbyAI
L
LINUX DO - 最新话题
大猫的无限游戏
大猫的无限游戏
Forbes - Security
Forbes - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Attack and Defense Labs
Attack and Defense Labs
C
CXSECURITY Database RSS Feed - CXSecurity.com
Y
Y Combinator Blog
W
WeLiveSecurity
T
Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Proofpoint News Feed
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
V
V2EX
N
News and Events Feed by Topic
Google DeepMind News
Google DeepMind News
D
Docker
The Hacker News
The Hacker News
A
About on SuperTechFans
Security Latest
Security Latest
NISL@THU
NISL@THU
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
博客园_首页
H
Hacker News: Front Page

博客园 - 我才是银古

第16章:常见问题、排错与最佳实践 第15章:扩展生态、MCAD 与外部集成 第12章:实战案例:机械结构与 3D 打印零件 第14章:构建、测试、调试与贡献流程 第13章:OpenSCAD 源码架构与核心执行流程 第11章:预览、渲染、网格精度与性能优化 第09章:列表推导、递归与算法建模 第08章:参数化零件库与复用设计 第10章:导入导出、命令行与自动化 第06章:CSG 布尔建模方法 第07章:二维图形、拉伸、旋转与投影 第05章:基础几何、坐标系与变换 第04章:参数、变量、函数、模块与作用域 OpenSCAD 教程目录 第03章:OpenSCAD 语言基础 第02章:安装、环境配置与开发工作流 第01章:OpenSCAD 项目全景与学习路线 第02章:源码获取、编译与开发环境配置 第01章:OCCT项目全景与学习路线 第18章:二次开发实战与综合案例 第17章:与 Qt VTK Python pythonOCC 生态集成 第18章:综合实战案例 第17章:数据交换与协同 第16章:源码架构与二次开发 第15章:插件与自定义工作台开发 第14章:Python脚本宏与自动化 第13章:FEM仿真分析 第12章:CAM数控加工 第11章:SurfaceMesh与逆向工程 第10章:Draft二维绘图与BIM建筑 第09章:工程图TechDraw 第07章:参数化表达式与Spreadsheet 第08章:装配设计Assembly 第06章:Part工作台与几何内核 第05章:PartDesign实体特征建模 第04章:草图Sketcher约束建模 第02章:安装版本与工作环境配置 第03章:界面工作台与基础操作 第01章:项目全景与学习路线 第十章:定时任务与自动化(Cron) 第七章:技能、记忆与自学习闭环 第八章:MCP 集成与上下文文件 第六章:工具系统与终端后端 第五章:模型供应商与配置体系 Hermes Agent 教程目录 第十一章:语音、视觉、浏览器与子代理协作 第四章:CLI/TUI 与会话管理 第十二章:学习路线、实战方案与最佳实践 第十一章:源码结构、开发调试与插件开发 第十章:自动化、远程访问、日志与排障 第九章:Control UI、节点、Canvas 与语音能力 第七章:工具、技能、插件与能力扩展 第八章:安全模型、访问控制与沙箱实践 第六章:Agent 工作区、会话与多智能体路由 第五章:多通道消息接入与聊天平台配置 第四章:配置体系、模型接入与认证管理 第三章:Gateway 架构、协议与运行机制 第二章:安装、环境准备与快速上手 第一章:OpenClaw 项目概览与核心定位 oh-my-openagent 教程目录 09-命令模型回退与配置参考 10-实战案例最佳实践与故障排除 05-工作模式-Ultrawork-Prometheus-Atlas 08-Hooks与MCP系统 06-Category与Skill系统 07-核心工具链 04-智能体全景详解 03-安装与环境配置 02-整体架构与多模型编排机制 01-项目简介与核心理念 01-项目概览与学习路线 02-安装部署与工具适配 03-Skill机制与using-superpowers 05-TDD系统化调试与完成前验证 04-需求澄清方案设计与计划编写 07-并行智能体子智能体与Git-Worktree 第六章:代码审查、反馈处理与分支收尾 08-中国特色Skills与本土团队落地 09-MCP构建工作流执行与自定义Skill 第23章:FreeCAD-Python-API Clipper2 C# 源码解读教程 第19章:PolyTree 多边形树结构 第20章:实际应用与最佳实践 第18章:Minkowski 和与差 第17章:RectClip 矩形裁剪优化 第16章:ClipperOffset 偏移类详解 第15章:填充规则详解 第14章:布尔运算执行流程 第13章:ClipperD 浮点裁剪类 第11章:OutRec 与 OutPt 输出结构 第9章:Active 活动边结构 第10章:Vertex 顶点与 LocalMinima 局部极小值 第12章:Clipper64 裁剪类详解 第7章:高精度运算与128位整数 第8章:ClipperBase 基类详解 第5章:枚举类型与常量定义 第6章:InternalClipper 内部工具类 第2章:核心数据结构 - Point64、PointD 第3章:路径与多边形表示 - Path64、PathD、Paths64、PathsD 第4章:矩形边界 - Rect64、RectD
第十二章:插件开发、研究功能与最佳实践
我才是银古 · 2026-05-04 · via 博客园 - 我才是银古

第十二章:插件开发、研究功能与最佳实践

最后一章面向工程师与研究者。我们会讲 Hermes 的 插件系统(Plugin、Memory Provider、Context Engine)Hooks(Gateway / Plugin / Shell 三套)、贡献开发流程批量轨迹与 RL 训练安全与运维清单。学完之后,你不只是在"用 Hermes",而是可以"扩展、改造、研究 Hermes"。

12.1 插件系统总览

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

12.2 写一个 General 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.profilectx.home_dirctx.loggerctx.aux_llm() 等便利。

启用后即生效:

hermes plugins enable my-plugin
hermes
> /fortune

12.3 写一个 Memory Provider Plugin

继承 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 的标准实现,可以作为最完整的范例。

12.4 写一个 Context Engine Plugin

agent.context_engine.ContextEngine ABC 决定:

  • 系统提示如何拼装;
  • 何时压缩、压缩什么;
  • 输入/输出 token 估算策略。

默认实现是 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 的最佳入口。

12.5 三种 Hook 体系

Hermes 同时存在三套 hook,分工明确:

系统 注册位置 跑在哪 典型用途
Gateway Hooks ~/.hermes/hooks/<name>/HOOK.yaml + handler.py 仅 Gateway 平台日志、告警、Webhook 转发
Plugin Hooks 插件中 ctx.register_hook() CLI + Gateway 工具拦截、指标采集、护栏
Shell Hooks ~/.hermes/config.yamlhooks: CLI + Gateway 一行脚本搞定(替代写 plugin)

事件清单(节选):

agent:startagent:stepagent:endmessage:inmessage:outcommand:<name>tool:beforetool:aftertool:approvalmemory:writememory:flushcompress:startcompress:donepairing:createdsession:createsession:end 等。

Shell Hook 最简例

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

12.6 自定义平台 Adapter

如果某个 IM 平台还没在 gateway/platforms/ 中:

  1. 实现 PlatformAdapter 抽象类(gateway/platforms/base.py);
  2. 提供 start()stop()send(message)on_event(callback) 等钩子;
  3. 注册到 gateway/platforms/__init__.py
  4. 写一份 user-guide/messaging/<name>.md

详见 developer-guide/adding-platform-adapter.md(或在 developer-guide/contributing.md 找入口)。

12.7 自定义 Provider

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

12.8 自定义工具(贡献到 Hermes 主线)

绝大多数情况不需要——MCP / Plugin 已能覆盖。但若你想贡献:

  1. tools/ 加一个 my_tool.py,导出函数 + 描述 + JSON schema;
  2. tools/registry.py 注册;
  3. toolsets.py 加入合适分组;
  4. 加测试到 tests/tools/

详见 developer-guide/adding-tools.mdcreating-skills.md(用于"先沉淀技能再升级成工具")。

12.9 贡献流程

仓库 developer-guide/contributing.md

  1. Fork、clone;
  2. ./setup-hermes.sh 建 venv;
  3. 写代码;遵循 pyproject.toml 中 ruff/black/pytest 配置;
  4. scripts/run_tests.sh
  5. 提 PR,附 hermes doctor 输出与变更说明;
  6. 大改请先开 issue 讨论。

代码风格:

  • Python 3.11+;
  • 类型注解尽量完整;
  • 工具函数返回值用 dict 而非自定义 dataclass,便于通过 LLM 工具调用;
  • 任何新功能必须有 docstring + 单测。

12.10 批量轨迹(Batch)与训练数据生成

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 给了详尽参数。

12.11 Atropos / RL 训练

Hermes 与 Atropos 同源,在 environments/ 内提供若干 RL 兼容环境,让你能用 Hermes 真实跑出来的 trajectory 训练新一代工具调用模型。

user-guide/features/rl-training.md 介绍:

  • 把 Hermes 当作 trajectory 生成器;
  • 把 Hermes 当作 evaluator(rl_* 工具);
  • 与 Atropos 训练循环对接(tinker-atroposmini_swe_runner.py 等脚手架)。

如果你只是日常用户,可以忽略本节。但对模型团队,这是 Hermes 一个重要的"研究价值"。

12.12 安全与运维清单(Production Checklist)

把 Hermes 推到生产 / 团队前,过一遍下面的清单:

12.12.1 基础

12.12.2 模型与凭据

12.12.3 沙箱

12.12.4 命令审批

12.12.5 自动化

12.12.6 数据隐私

12.12.7 可观测性

12.12.8 升级前

12.13 排错总集(Troubleshooting Playbook)

现象 怀疑 操作
启动慢 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

12.14 一份"两年内的 Hermes 工作流"

把所有章节融合,一份工程师/研究者实际推荐的长期工作流:

  1. Day 0:装、hermes setup、选 OpenRouter + Anthropic 做主,DeepSeek 做 aux;启用 docker 后端;启用 Telegram + 邮件;写 SOUL.md。
  2. Week 1:把日常项目根目录都加 AGENTS.md;让 Agent 把你的环境/偏好写进 MEMORY/USER;开 Honcho。
  3. Week 2:从 Skills Hub 装 5 个常用技能;让 Agent 自己沉淀第一条 SKILL(你重复做的事情)。
  4. Month 1:上线 cron:日报、PR Review、服务巡检、知识库整理;上 Webhook:GitHub PR、Stripe 事件。
  5. Month 2:上 Kanban,建 dispatcher / researcher / writer / reviewer 几个 profile;把团队复杂工作流接进来。
  6. Month 3:写第一个 plugin(你只在用的小工具);写第一个 Memory Provider(如果你需要把记忆持久到团队 KV)。
  7. Month 6:用 hermes batch run 生成训练数据;用 Atropos 跑 RL 训练你自己的模型。
  8. Year 1:把 ~/.hermes/{memories,skills,SOUL.md} 同步进 dotfiles,跨设备无缝;个性化技能包成 hub 给同事用。
  9. Year 2:贡献回 Hermes 主线 1-2 个 PR;把这套 Agent 平台作为一个团队级"AI ops 操作系统"。

到这里,Hermes 不再是"一个工具",它是你 AI 工作方式的 底盘

12.15 本章小结

  • Hermes 提供 三类插件接口(General / Memory Provider / Context Engine),让你能在不动主线代码的前提下把任何外部能力嵌入;
  • 三套 Hook(Gateway / Plugin / Shell)覆盖一切生命周期事件;
  • 新平台 / 新 Provider / 新工具 都有清晰的扩展点;
  • Batch 与 Atropos RL 让 Hermes 也能作为研究/训练平台;
  • 上线前请走完 生产清单,特别是沙箱、审批、凭据、cron 上限、可观测性。

至此 12 章教程结束。Hermes Agent 不只是一个 Agent 框架——它是一份对"长期共生型 AI 助理"应该是什么样子的工程化答卷。 把它跑起来、用起来、调起来、扩起来,你会越来越体会到这套架构的诚意。Happy hacking ☤