商业产业 Hacker News LLM 2026-08-28T13:28 正文 ok 610 words

🔶 KHMS:可由 LLM Agent 自行安装的基于文件的长期记忆系统

英文标题:🔶 KHMS – a file-based long-term memory an LLM agent installs into itself

KHMS 是一套面向 LLM Agent 的长期记忆系统,以 Git 仓库中的纯 Markdown 文件存储知识,并将每条知识记录为不可变的“卡片”。系统通过证据等级、来源追溯、卡片间支持或反驳关系,以及基于图谱计算的置信度,解决传统上下文窗口和向量检索难以处理的知识可信度与历史修正问题。它采用 Hook 驱动的自动召回机制,并通过“提议→审查→批准”流程确保未经审核的信息不会进入正式知识库。该项目已从一个自 2026 年年中起每日运行的单人部署中抽取并泛化,相关参数仍需按实际场景校准。
打开原文相关 4 · 机会 1
media40.8 KB

中文

KHMS——Agent 可自行安装的基于文件的长期记忆系统

KHMS(“know-how management system”,诀窍管理系统)是一套面向 LLM Agent 的长期记忆方案,由 Git 仓库中的纯 Markdown 文件构成。每一条知识都是一张不可变的卡片,带有 YAML frontmatter,用于说明知识类型、证据强度、来源,以及它派生自、支持或反驳哪些其他卡片。卡片永不编辑、永不删除:修正内容会成为一张_取代_旧卡片的新卡片;被证伪的卡片仍会保留,并被明确标注为一条无效路径。在这一存储层之上,是让系统能够实际运作的机制——由 Hook 驱动的召回,会在 Agent 主动提出请求前将相关卡片推送进会话;以及一条提议 → 审查 → 批准流程,其中后台任务只能提交提议,任何内容未经审查都不能进入知识目录。

状态:本项目从一个自 2026 年年中以来每日运行的单人部署中抽取并泛化而来。这里的脚本即为该部署使用的脚本,只是将路径参数化并移除了领域特定内容。标有“calibrate(校准)”的数值是该部署的取值,而不是普适规律。

  • 要为自己配置记忆系统? → AGENTS.md——一次完成的初始化指南。
  • 想先了解完整模型?→ spec/khms-spec.md。
  • 想将其接入 Claude Code(Hooks、cron、依赖项)?→ claude-code/。
  • 想在创建卡片前先查看示例?→ examples/(虚构的气象站领域)。

面向人类:它解决了什么问题

与用户长期协作数月的 Agent,会不断重新推导相同结论、重复已经记录过的无效尝试,并把昨天的事实当成今天的事实来陈述。上下文窗口无法解决这一问题——它们仅限于单次会话,而且会丢失信息。向量存储式“记忆”大多只能改善对_文本_的召回,却无法处理更困难的问题:一项被记住的主张究竟是测量所得还是仅被报道、什么证据反驳了它,以及是谁批准它进入正式记录。

KHMS 对这些问题的回答,每项一句话:

  • 卡片,而非聊天日志。 每个文件只记录一项主张,并进行类型标注(fact、problem→solution、decision→rationale、principle、policy,……),让知识可以被关联和统计。
  • 认知证据等级。 观察记录带有 evidence: measured | observed | reported 和来源;规则属于 derived,且必须注明其推导依据。置信度由这一关系图谱_计算_得出,绝不由人工直接断言。
  • 不可变性。 不编辑,不删除。修正内容取代旧内容;被证伪的信息仍保持可读,因为“我们已经试过,结果失败了”是记忆所能保存的最有价值信息之一。
  • 将检索视为下限加上限。 Hook 会在预算范围内自动注入候选卡片(下限:无论 Agent 是否记得查找都会执行);而在提出假设和方案前进行显式召回,则是 Agent 自身的责任(上限)。
  • 分级审查。 成本较低的模型将内容提议至收件箱,更强的阶段负责整合,只有批准阶段才能分配 ID 并写入知识目录。

既有实践与延伸阅读

MIT——参见 LICENSE。

English / 原文

KHMS — a file-based long-term memory an agent can install into itself

KHMS ("know-how management system") is a long-term memory for LLM agents made of plain markdown files in a git repository. Every piece of knowledge is one immutable card with YAML frontmatter — what kind of knowledge it is, how strongly it is evidenced, where it came from, and which other cards it is derived from, supports or contradicts. Cards are never edited and never deleted: a correction is a new card that supersedes the old one, and a refuted card stays visible as a signposted dead end. Around that storage layer sits the part that makes it work in practice — hook-driven recall that pushes relevant cards into the session before the agent asks for them, and a propose → review → approve pipeline in which background jobs may only propose and nothing enters the knowledge directory unreviewed.

Status: extracted and generalized from a working single-operator deployment that has been running daily since mid-2026. The scripts here are the deployment's scripts with the paths parameterized and the domain specifics removed. Numbers marked "calibrate" are that deployment's values, not laws.

  • Setting up memory for yourself? → AGENTS.md — the one-pass bootstrap.
  • Want the whole model first? → spec/khms-spec.md.
  • Wiring it into Claude Code (hooks, cron, dependencies)? → claude-code/.
  • Want to see cards before writing any? → examples/ (fictional weather-station domain).

For humans: what problem this solves

An agent that works with someone for months keeps re-deriving the same conclusions, repeating documented dead ends, and stating yesterday's fact as today's. Context windows do not fix this — they are per-session and they are lossy. Vector-store "memory" mostly fixes recall of text , not the harder parts: whether a remembered claim was measured or merely reported, what refuted it, and who approved it into the record.

KHMS's answers, in one line each:

  • Cards, not chat logs. One claim per file, typed (fact, problem→solution, decision→rationale, principle, policy, …), so knowledge can be linked and counted.
  • Epistemic levels. Observations carry evidence: measured | observed | reported and a source; rules are derived and must name what they were derived from. Confidence is computed from that graph, never hand-asserted.
  • Immutability. No edits, no deletions. Corrections supersede; refutations stay readable, because "we already tried that and it failed" is among the most valuable things memory holds.
  • Retrieval as a floor plus a ceiling. Hooks inject candidate cards automatically on a budget (the floor, which runs whether or not the agent remembers to look); explicit recall before hypotheses and proposals is the agent's own duty (the ceiling).
  • Graduated review. Cheap models propose into an inbox, a stronger stage consolidates, and only an approving stage assigns IDs and writes into the knowledge directory.

Prior art and further reading

MIT — see LICENSE.