背景
OpenRouter 排行榜上正在发生一场换代:Hermes Agent 增速 +204%,Top Coding Agents 排第一,Top Productivity 排第二。上线不到半年,GitHub 从 0 到 106k+ Star。开发者在用数据说话——选的不是"另一个 OpenClaw",是一种完全不同的东西。
区别在哪?OpenClaw 的 Skill 是手写的 Markdown 文件——你写多少它会多少,你不写它就不会。Hermes 做了一件 OpenClaw 架构上做不了的事:Agent 干完活之后,会自动把踩坑经验提炼成可复用的 Skill,下次遇到同类问题直接调用。用得越久,能力越强。这不是功能差异,是设计哲学的分野——一个靠人喂,一个自己长。
这篇文章拆开 Hermes 的源码,看看这个 Self-Improving 闭环到底怎么跑的。文末也会聊聊 RDSHermes 怎么把这套能力搬给不写代码的人用。
仓库地址:
github.com/NousResearch/hermes-agent
总览:三个子系统,一个闭环
大多数 Agent 每次会话结束后就"失忆"了。Hermes 在内部搭了一套学习闭环,由三个子系统撑起来:
打个比方:Memory 是助理随身带的小本子,记着"老板喜欢喝美式"这些事实;Skill 是助理积累的操作手册——"部署 K8s 第 2 步一定要先推镜像";Nudge Engine 是定时响的闹钟,提醒助理回头想想有没有什么值得记的。
Memory:越用越懂你
两个文件,就是 Agent 对你的全部认知
Memory 系统设计得很克制——两个纯文本文件,用 § 分隔条目:
~/.hermes/memories/├── MEMORY.md # Agent 的个人笔记(环境事实、项目约定、工具怪癖)└── USER.md # Agent 对用户的认知(偏好、沟通风格、工作习惯)
字符上限故意设得很紧:MEMORY 限 2200 chars,USER 限 1375 chars。容量有限就迫使 Agent 挑重要的记,不重要的自然被挤掉。对比 OpenClaw——它的 MEMORY.md 是纯追加模式,用几个月就膨胀成几万行的怪兽文件,找几个月前的一句话只能笨拙地通读全文。Hermes 的做法反过来:容量有限就倒逼 Agent 做信息压缩,过时的自然被挤掉,留下的都是高密度事实。
具体实现上,MemoryStore 维护两组平行状态——实时可写的条目列表,和会话开始时冻结的快照:
## tools/memory_tool.py:116-122class MemoryStore: def __init__(self, memory_char_limit=2200, user_char_limit=1375): self.memory_entries: List[str] = [ ] self.user_entries: List[str] = [ ] self.memory_char_limit = memory_char_limit self.user_char_limit = user_char_limit self._system_prompt_snapshot: Dict[str, str] = {"memory": "", "user": ""}
但"设了上限"只是第一步,关键是超限之后怎么处理。Hermes 不会静默丢弃旧条目,也不会自动压缩——它选择让 add 直接失败,然后把当前所有条目返回给模型:
## tools/memory_tool.py:248-259if new_total > limit: current = self._char_count(target) return { "success": False, "error": ( f"Memory at {current:,}/{limit:,} chars. " f"Adding this entry ({len(content)} chars) would exceed the limit. " f"Replace or remove existing entries first." ), "current_entries": entries, "usage": f"{current:,}/{limit:,}", }
错误信息里一句 "Replace or remove existing entries first" 就把模型引导到了 replace 和 remove 操作上。同时返回 current_entries,让模型能看到现有的所有条目,自己决定哪些过时了该删、哪些可以合并压缩。模型不是被动地执行淘汰规则,而是主动做信息整理——这本身就是一次"自我反思"。
冻结快照机制
每次会话启动时,Memory 加载后立刻捕获一份快照,之后系统提示词里用的都是这份快照:
## tools/memory_tool.py:124-140def load_from_disk(self): mem_dir = get_memory_dir() self.memory_entries = self._read_file(mem_dir / "MEMORY.md") self.user_entries = self._read_file(mem_dir / "USER.md") # 会话开始时冻结快照,之后不再变动 self._system_prompt_snapshot = { "memory": self._render_block("memory", self.memory_entries), "user": self._render_block("user", self.user_entries), }
快照注入系统提示词后,Agent 还没看到用户消息就已经知道你的环境和偏好了。为什么"冻结"而不是实时更新?因为系统提示词会话内不变就能共享前缀缓存(Prefix Cache),省掉重复计费。新写入的内容只改磁盘,下一个会话才刷新进来。提示词引导:什么该记、什么不该记
Agent 怎么知道什么时候该往 Memory 里写东西?靠 Prompt 引导。系统提示词中的 MEMORY_GUIDANCE:
## agent/prompt_builder.py:144-162MEMORY_GUIDANCE = ( "You have persistent memory across sessions. Save durable facts using the memory " "tool: user preferences, environment details, tool quirks, and stable conventions.\n" "Prioritize what reduces future user steering — the most valuable memory is one " "that prevents the user from having to correct or remind you again.\n" "Write memories as declarative facts, not instructions to yourself. " "'User prefers concise responses' ✓ — 'Always respond concisely' ✗. " "'Project uses pytest with xdist' ✓ — 'Run tests with pytest -n 4' ✗.")
注意这里的区别:Memory 要求写成声明式事实("User prefers concise responses"),而不是命令式指令("Always respond concisely")。前者是偏好,可以被当前上下文覆盖;后者是死命令,会限制 Agent 的灵活性。
Tool Schema 里还有一句关键的边界规则:"If you've discovered a new way to do something, save it as a skill." —— Memory 不存操作步骤,操作步骤归 Skill 管。这一句话把两个系统的分工画清了。
Skill:把做过的事变成会做的事
Skill 长什么样
Memory 是"我知道什么",Skill 是"我会做什么"。每个 Skill 是一个目录,核心是 SKILL.md 文件:
~/.hermes/skills/├── devops/│ └── flask-k8s-deploy/│ ├── SKILL.md # 主指令│ ├── references/ # 参考文档│ └── templates/ # 模板文件└── software-development/ └── fix-pytest-fixtures/ └── SKILL.md
一个典型的 SKILL.md:
---name: flask-k8s-deploydescription: Deploy a Flask app to Kubernetes with health checksversion: 1.0.0---# Flask K8s Deployment## When to use- User wants to deploy a Flask/Python app to Kubernetes- User mentions K8s, kubectl, or container deployment## Steps1. Create Dockerfile with gunicorn (not dev server)2. Build and push image to registry BEFORE creating deployment3. Write deployment.yaml with livenessProbe pointing to /health4. Write service.yaml with correct port mapping5. kubectl apply both files6. Verify with kubectl get pods and kubectl logs## Pitfalls- MUST push image to registry before kubectl apply, otherwise ImagePullBackOff- Flask 默认没有 /health 端点,需要手动添加- Django 需要额外设置 ALLOWED_HOSTS 环境变量- livenessProbe path 必须返回 200,不能用需要认证的路径
Pitfalls 这一节不是预先写好的,而是 Agent 踩坑后追加的——这就是 Skill 层面的"self-improving"。
什么时候创建 Skill
Agent 不需要用户说"帮我创建一个 Skill"。驱动力来自 skill_manage 工具的 schema:
## tools/skill_manager_tool.py:681-701SKILL_MANAGE_SCHEMA = { "name": "skill_manage", "description": ( "Manage skills (create, update, delete). Skills are your procedural " "memory — reusable approaches for recurring task types.\n\n" "Create when: complex task succeeded (5+ calls), errors overcome, " "user-corrected approach worked, non-trivial workflow discovered, " "or user asks you to remember a procedure.\n" "Update when: instructions stale/wrong, OS-specific failures, " "missing steps or pitfalls found during use. " "If you used a skill and hit issues not covered by it, " "patch it immediately with skill_manage(action='patch') " "— don't wait to be asked.\n\n" "After difficult/iterative tasks, offer to save as a skill. " "Skip for simple one-offs." ),}
创建的门槛设得比较清楚:工具调用超过 5 次才值得创建(简单任务不记)、踩过坑再修复的经验才有价值、用户纠正过的做法要铭记。
OpenClaw 也有 Skill 系统,也是 SKILL.md + YAML frontmatter,但 Skill 要么是你手写的,要么是从社区装的。手写的成本高,懒得维护;社区装的不是针对你的环境。关键问题是:Agent 本身不会从工作中学到任何东西——干了一百次部署,第一百零一次犯的错跟第一次一模一样。HN 上有个帖子叫"Data Is the Final Moat"——当模型智能被商品化、Agent 框架被开源,真正的护城河是 Agent 在工作中积累的领域知识。OpenClaw 的 Skill 是手写的配置文件,用了一年还是那份手写的配置文件;Hermes 的 Skill 是越用越厚的经验资产——每一次踩坑都在加固护城河。这不是 OpenClaw 团队不想做,而是它的架构没有为"Agent 自主学习"预留通路——没有创建触发、没有 patch 机制、没有 review agent。要补这一课,是要重写核心架构。
Hermes 这边,Agent 踩了坑、修了 bug、用了 12 次工具调用才搞定一个部署——这些经验被自动提炼成 Skill,下次再遇到同类任务就是 6 次调用零错误。
系统提示词里还有一句"Skills that aren't maintained become liabilities"——通过提示词给 Agent 灌输责任感,防止它只管创建不管维护。
Skill 的自我修补
当 Agent 按照已有 Skill 执行,但中途发现步骤有遗漏或者踩了新坑时,它会在完成任务后回头修补 Skill。不是全量重写,而是做精确的局部 patch:
## tools/skill_manager_tool.p…