Skip to content

memory: 研究 Project-scoped Durable Learning,并严格区分事实、经验与 Skill #167

Open

Description

@tt-a1i

结论

OMP 在跨 Session 学习上明显比 OpenPI 完整:可以 retain/recall/reflect/edit 长期记忆,也可以把可复用经验晋升为 managed Skill。

这确实是功能优势,但也是最容易制造第二套 source of truth、污染未来上下文和静默积累错误事实的能力。OpenPI 值得研究“用户可检查、project-scoped、带来源与失效语义的 durable learning”,但不应先造一个自动记忆数据库,也不应让模型默认改写 Pi Skills。

这是 #45 的具体拆分。

对比证据

固定审查点:

OMP retain 支持远程 Hindsight 与本地 SQLite backend,提供 global/per-project/per-project-tagged scope;持久数据可跨 Session,Subagent 复用 parent memory scope。OMP retain scope

但当前 receipt 并不严格:Hindsight 只报告 queued,后续 flush failure 不回到模型;Mnemopi 单项写失败也可能仍按请求数量报告 stored。OMP retain receipt gap

Recall 可跨 Session 搜索,但结果可能是截断 preview;完整更新前必须另读完整 row。OMP recall contract

Learn 可先写 lesson,再可选创建/更新 managed Skill;两步可能出现 partial outcome。Managed Skill 与 authored Skill 分离,后者优先。OMP learn

Manage Skill 可 create/update/delete,并做名称、大小与 symlink/hardlink 防护,但它仍是模型可调用的文件 mutation。OMP manage skill

OpenPI 当前沿用 Pi 的 Skills、Trust 与 Session,不建立跨 Session memory source;Tasks/Goal 是当前 Session 的意图与目标,不等同于长期知识。OpenPI stance

先区分四类对象

  1. 事实:外部世界或仓库状态,可能过期,必须有来源和验证时间。
  2. 偏好:用户明确表达的稳定选择,应可查看、修改、删除。
  3. 经验:某次任务得出的启发,尚未证明可普遍复用。
  4. Skill:经过用户或独立证据确认的可重复流程,仍由 Pi Skill discovery 持有。

不能把四类都塞进一个向量库,然后自动注入 system prompt。

研究问题

  • 最小价值是手动 recall,还是自动 recall/retain?
  • project identity 应使用 canonical git root + remote identity,如何处理 rename、fork、worktree?
  • 每条记忆是否必须带 source Session、evidence refs、created/verified/expires、scope 与 confidence?
  • stale/contradicted memory 如何 invalidate,而不是覆盖历史?
  • recall 是否默认只返回候选,需当前工具证据重新验证?
  • Subagent 应只读 parent-approved memory,还是完全不继承?
  • lesson 晋升 Skill 是否必须显式用户确认和独立 review?
  • 最终存储应由 Pi/独立 package 持有,OpenPI 只提供可选投影,还是完全不做?

建议验证

先做无自动写入的 dogfood ledger:

  • 用户显式保存 20 至 50 条 project-scoped 候选;
  • 新 Session 仅在明确询问时 recall;
  • 每次使用记录命中、过期、冲突、误导和节省的搜索/tool calls;
  • 分别测试 repo rename、worktree、fork、跨 branch 与外部状态变化;
  • 比较无 memory、manual recall、auto recall 三臂。

只有 manual recall 有稳定收益且低误导率,才研究自动 recall;auto retain 最后决定。

必须具备的 receipt

  • stored/queued/failed/partial 分开;
  • 每项有稳定 id 与 scope;
  • durable 只在持久层 readback 成功后返回;
  • update 前读取完整内容,不允许用截断 preview 覆盖;
  • invalidate/forget 区分;
  • Skill mutation 与 lesson persistence 是两个独立 outcome;
  • 任意自动注入有 token cap、来源标记与关闭开关。

验收标准

  • 明确事实/偏好/经验/Skill 的不同生命周期
  • fixed corpus 的 no-memory/manual/auto paired evidence
  • project/worktree/fork identity 不串线
  • receipt 不把 queued/failed 伪装 durable
  • stale/contradiction/invalidation 可审计
  • Skill 仍走 Pi source of truth 与显式确认
  • 默认不自动写、不自动注入、不增加普通 turn 静态税

明确不做

  • 不从向量数据库或远程 memory server 起步;
  • 不自动把每轮对话写成长期事实;
  • 不让 child 静默扩大或污染 parent memory;
  • 不让模型默认创建、覆盖或删除 authored Skills;
  • 不把 Tasks/Goal 当长期知识库。

2026-08-26 comparative addendum: memory is not one mechanism

This addendum records the broader fixed-source comparison requested after the original OMP audit. It does not create a second memory feature: #167 remains the single owner for project-scoped durable learning. Context compaction is covered by #190; Goal lifecycle by #192; Tasks/Goal conceptual separation by #43.

Fixed baselines:

  • OpenPI 2a69d3f32994da4123f1312b7fa84ef3d6119be1
  • Pi @earendil-works/[email protected] / earendil-works/[email protected]
  • Codex a9e447a69dee4f2789dd8d8c776e314772c1f049
  • Hermes cbd8de8ad64530be01efea23b7764d5c37c634ed
  • Grok Build c2ad97f87aea4303b6000a2c22128bc91ee76c9b
  • Gemini CLI 812f7a2bcf20b6e80e2e50c3c8fa8e26567bc1e8
  • OpenCode 8615731d46153dd29b89e205fb55b2cc16205cb0
  • Claude Code: rolling official documentation only; its implementation is proprietary.

1. Required taxonomy

These objects have different owners, authority, and lifecycles:

  1. Repository instructions (AGENTS.md, CLAUDE.md, GEMINI.md): human-authored behavioral context, not execution facts.
  2. Explicit durable memory: a user-authorized write to a persistent memory record or file; a model request alone is not authorization.
  3. Automatic memory: background/model-authored candidates or writes derived from prior sessions.
  4. Retrieval/index: a projection used to select records; it is not the canonical record and ranking does not grant authority.
  5. Session transcript/resume: canonical interaction and branch history, not cross-session learning.
  6. Compaction summary: a lossy context projection, not durable fact storage.
  7. Skill: a reusable procedure discovered and loaded through the host’s Skill lifecycle, not a remembered fact.
  8. Goal/Task: current objective or work intent, not knowledge and not completion evidence.
  9. Provider state/cache: execution configuration and provider-side reuse, not project memory.

The original four record classes remain mandatory:

  • fact: externally checkable and potentially stale;
  • preference: explicitly attributable to a user;
  • experience/lesson: a candidate generalization, not yet a rule;
  • Skill: a reviewed reusable procedure owned by Pi’s Skill system.

2. Fixed-source comparison

OpenPI / Pi

OpenPI currently adds no general durable-memory store, embedding index, or auto-recall layer. Pi remains source of truth for Sessions, branches, Skills, context loading, project Trust, and provider/model selection; OpenPI Goals and Tasks are branch-scoped typed state.

A critical security correction: Pi project Trust does not gate AGENTS.override.md, AGENTS.md, or CLAUDE.md. Those context files load regardless of project Trust unless context loading is disabled. Pi explicitly treats prompt injection from repository files and tool output as expected local-agent risk. Therefore a future memory writer must not promote repository/tool text into durable instructions merely because Pi loaded it; promotion needs separate explicit authority.

Pi Skill names/descriptions occupy discovery context, while full SKILL.md content is read on demand. OpenPI explicit capability mode avoids startup tool/context tax, but an activated capability group remains monotonic for that Session; it is not unloaded again.

Evidence:

Codex

At the fixed revision, memory is an explicit subsystem rather than a synonym for AGENTS.md or compaction:

  • ext/memories contributes model context/tools, memories/read owns reads/citations/usage, and memories/write owns extraction/consolidation persistence; this is not an explicit user memory-edit tool;
  • the read extension is enabled only when the MemoryTool feature and memories.use_memories are both enabled, while generate_memories, use_memories, dedicated tools, and external-context exclusion are separate controls;
  • threads that used external tool/web/MCP context can be marked polluted and excluded from later generation;
  • startup write processing skips ineligible/ephemeral sessions and can skip when rate-limit headroom is too low;
  • phase 1 claims idle prior threads, extracts structured rollout summary/raw memory, and redacts secrets before persistence;
  • phase 2 takes a global lock, builds a constrained local workspace, disables recursive memories/collaboration/apps/plugins, runs a consolidation agent without network access, validates artifacts, and only then resets its baseline;
  • app-server exposes experimental per-thread memory mode and global memory reset controls; model responses can carry file/line memory citations plus source thread IDs.

This is stronger lifecycle evidence than the original #167 comparison, but it still does not make generated memory authoritative. Redaction is defense in depth, not permission to persist secrets. The fixed source should be treated as experimental because key APIs are explicitly marked experimental.

Evidence:

Claude Code

Official documentation distinguishes human-authored CLAUDE.md from model-authored auto memory. Per-repository auto memory is stored as inspectable Markdown under ~/.claude/projects/<project>/memory/; all worktrees of the same repository share it. The first 200 lines or 25 KB of MEMORY.md load at startup, while topic files are read by the model on demand. Users can inspect, edit, delete, or disable it. Main-conversation auto memory is not loaded into ordinary subagents; a fork inherits the parent conversation/system prompt, and separately configured subagents can own their own memory directories.

This is progressive disclosure, not evidence of embeddings, semantic ranking, transactional writes, or automatic freshness validation. The docs also state that auto memory is on by default, so OpenPI should not copy that default without evidence from the manual-first experiment already required by #167.

Evidence: Claude Code memory documentation.

Hermes Agent

Hermes has built-in bounded MEMORY.md/USER.md, FTS Session search, optional external providers, and a real pluggable memory-provider seam at the fixed revision:

  • at most one external provider is active, preventing conflicting backends/tool-schema growth;
  • providers may inject static prompt text, prefetch recalled context before turns, asynchronously sync completed turns, expose tools, extract at session end, checkpoint before compression, and observe delegation;
  • initialization receives agent_context, profile/workspace identity, parent session ID, and user IDs; providers are told to skip writes for non-primary contexts;
  • the manager gates memory tools and matching prompt instructions together and visibly reports recalled-memory counts;
  • pre-compression has legacy best-effort and opt-in fail-closed checkpoint contracts;
  • built-in memory remains distinct from an optional external provider and has an explicit reset command;
  • memory and Skill writes can be automatic by default; only memory.write_approval and skills.write_approval turn the review path into a mandatory gate. Hermes must not be described as explicit-only.

This flexibility is useful but creates a larger provider/plugin authority surface than OpenPI currently needs. OpenPI should not copy the provider framework or Hermes' default automatic-write authority until one minimal project-learning contract proves value.

Evidence:

Grok Build

Grok Build has the broadest conventional retrieval stack in this comparison, behind an experimental off-by-default switch:

  • canonical Markdown lives in global, workspace, and per-session paths;
  • workspace identity uses normalized origin when available, so clones/worktrees share memory, otherwise the directory path;
  • an SQLite projection stores content hashes and provenance lines, FTS5 supports keyword search, and optional sqlite-vec supports vector KNN;
  • search supports source weights, temporal decay for session memory, and MMR diversity;
  • /remember requires a review/confirmation panel, while session-end metadata saves, /flush, pre-compaction flush, and Dream consolidation are distinct paths;
  • first-turn and post-compaction retrieval can automatically inject results;
  • clear operations distinguish workspace, global, and all scopes; “forget” through the model is only best-effort and direct file editing is the guaranteed path described by the docs.

This system demonstrates why #167 must keep the Markdown record and retrieval index separate. A canonical write may be committed while reindexing is failed or stale: durability is still committed, but retrieval availability is partial; a single boolean “saved” is insufficient.

Evidence:

Gemini CLI

At the fixed revision, Gemini separates three mechanisms:

  1. hierarchical GEMINI.md context, including global/workspace and just-in-time files found up to a trusted root;
  2. explicit durable memory, implemented by editing the appropriate Markdown file with ordinary write/replace operations;
  3. experimental auto memory, off by default, which scans local idle nontrivial non-subagent sessions and produces review-inbox patches or Skill drafts.

Auto-memory candidates cannot directly edit active memory, settings, credentials, or project GEMINI.md; memory patches are allowlisted and atomically applied only after approval. Applied changes reload current-session memory. Transcript excerpts are nevertheless sent to the configured model during extraction, so “local transcript source” does not mean “local-only processing.”

This approval-inbox design is the strongest match for #167’s existing manual-first and Skill-promotion requirements. OpenPI should reuse the idea of candidate versus promotion, not Gemini’s separate memory directory or runtime.

Evidence:

OpenCode

The fixed revision provides durable instructions, not a separate model-authored memory subsystem:

  • it selects global AGENTS.md with Claude compatibility fallback;
  • project instructions choose the first matching filename family and can include configured local globs or remote URLs;
  • nested instructions are discovered as files are read and attached once per assistant message;
  • /init can generate or improve AGENTS.md, but the result is still an inspectable project instruction file intended for Git.

No independent canonical memory/index lifecycle appears in the fixed tree. Session resume and compaction remain separate mechanisms. Remote instruction URLs and generated /init output reinforce the durable-injection rule: persistence into an instruction file is not automatically authorized merely because the model or a network source produced text.

Evidence:

3. Durable prompt-injection authority boundary

The main net-new requirement from this comparison is not a retrieval algorithm. It is a runtime authorization boundary:

untrusted repository/tool/web/model text
    ≠ permission to create durable memory
    ≠ permission to edit project instructions
    ≠ permission to promote a Skill

A future write path must identify the authorizing actor separately from the content source. Minimum fields:

  • record_id, record class, scope and revision;
  • authorizing user/host episode;
  • producer agent/model/provider;
  • source Session/branch/turn and evidence refs;
  • project identity and applicable path;
  • created/validated/expiry timestamps;
  • sensitivity/redaction result;
  • candidate | committed | stale | disputed | superseded | deleted;
  • conflicts/supersedes links.

Repository context can be evidence but cannot self-authorize persistence. Tool output can support a fact but cannot silently become an instruction. A child can propose a candidate with child provenance but cannot mutate shared project learning unless the parent grants a typed capability for that episode.

4. Receipt correction

Canonical persistence and retrieval projection are separate outcomes:

record_commit: committed | rejected | uncertain
index_update: available | stale | failed | not_applicable
prompt_projection: injected | filtered | truncated | failed | not_requested

If the canonical record commits and an optional index fails, the truthful outcome is durable record committed; retrieval partial/unavailable. It is not a failed save, and it is not “saved and searchable.” Update/invalidate/delete must likewise expose canonical, index, cache/projection, and child/fork visibility separately.

5. Updated acceptance criteria

In addition to the original criteria:

  • Documentation distinguishes all nine mechanisms above and preserves fact/preference/experience/Skill lifecycles.
  • Pi context-file loading outside Project Trust is documented as a prompt-injection input, not an authorization boundary.
  • Every durable mutation records both content provenance and a separate authorizing actor/episode.
  • Repository, tool, web, memory-retrieval, compaction, and child output cannot self-promote into durable instructions or Skills.
  • Candidate extraction and promotion are separate; automatic extraction may be opt-in, but automatic promotion is out of scope.
  • Canonical commit, retrieval-index update, and prompt projection have independent receipt states.
  • Retrieval is bounded, provenance-bearing, permission-filtered before injection, and adds no payload on empty results.
  • Child memory access is read-only and explicitly selected by default; child writes require parent-mediated promotion.
  • Disabling memory stops both automatic reads and new extraction/writes; existing data retention is separately visible.
  • OpenPI does not create a second Session store, Skills registry, provider stack, or generic memory-provider framework.
  • The initial dogfood remains manual-first; no vector database or automatic recall ships before paired evidence shows plain bounded retrieval is insufficient.

Activity

  1. added
    documentation
    on Aug 25, 2026
  2. 627150795 commented on Aug 29, 2026

    @627150795
    Contributor

    I am taking a focused manual-first design slice: define a project-scoped durable-learning ledger with explicit record classes, provenance, authorization, expiry/contradiction, readback, and Skill-promotion boundaries. This pass will not add automatic memory writes, vector retrieval, prompt injection, or Skill mutation.

  3. 627150795 commented on Aug 29, 2026

    @627150795
    Contributor

    I opened #267 (#267) for the focused manual-first design slice. It separates durable learning records from repository instructions, Session history, compaction, Skills, indexes, and caches, and defines project identity, authorization, expiry, recall, receipts, and child boundaries. The docs checks passed: git diff --check, bun run lint, and bun run typecheck. It does not add automatic memory or Skill mutation.

  4. tt-a1i commented on Sep 8, 2026

    @tt-a1i
    CollaboratorAuthor

    补充社区源码中的一个具体约束:未来如果验证值得做 Durable Learning,删除/纠正后的记忆必须可恢复,而且应立即退出旧注入快照。 2026-08-09 调研曾建议暂不引入持久 Agent Memory;本次只补充研究证据,不把旧调研建议当作已采纳的 Decision,也不据此授权实现。

    jayzeng/pi-memory@39e6b998 的 memory_forget 先保存 recovery payload,再修改源文件,并使注入 snapshot dirty;memory_restore 识别已经恢复和已存在条目。可借鉴 visible recovery ID、重复恢复结果、快照失效三者组成的回执;这不是并发原子性已经验证的声明。

    同时注意 pi-hermes-memory 的 policy-only 仍会注入 standing instructions,不能因为名字叫 policy-only 就当作零上下文成本。关键词纠正检测、模型 confidence 或自动抽取也都不是事实真实性证明。

    建议把以下情况加入 #167 的实验验收:删除后下一轮不再注入;恢复重试不重复;事实/经验/用户明确指令保留不同来源;快照显示新鲜度;自动生成的记忆可追溯原始 Session;不把陈旧偏好恢复成当前权限。现阶段只补研究约束,不安装整套 Memory 或默认增加后台模型调用。

    研究记录:Pi 社区能力研究与候选清单(2026-09-08)。源码证据、运行验证与采用决策分别记录。

  5. tt-a1i commented on Sep 8, 2026

    @tt-a1i
    CollaboratorAuthor

    2026-09-08 插件目录仍然 跳过全部 Memory 包,不新开 Discussion,也不把它们当成 #167 的实现候选。三例:

    • pi-hermes-memory(npm 0.9.8,2026-09-05)
    • pi-memory(jayzeng,npm 0.4.2,2026-08-11)
    • @amaster.ai/pi-memory-mem0(npm 0.1.14,2026-09-02)

    本轮未安装、未运行。#167 若继续研究 Durable Learning,仍是手工、可纠正、非自动 memory DB。

    目录记录:docs/research/PI_COMMUNITY_PLUGIN_SURVEY_2026-09-08.md。

  6. tt-a1i commented on Sep 9, 2026

    @tt-a1i
    CollaboratorAuthor

    2026-09-09 源码对照:仍跳过全部 Memory 包。不 Adopt、不 Wrap、不新开 Discussion,也不把它们当成 #167 的实现候选。本轮只读 /tmp clone 与 npm 元数据,未安装、未运行。不提议引入持久 Agent Memory。

    本地记录(未提交):docs/research/EXPERIMENT_MEMORY_SKIP_EVIDENCE_2026-09-09.md。不替换 08-09 审计,也不改写 09-08 目录分流。

    冻结身份

    包 npm git
    pi-hermes-memory 0.9.8 34c6fe49
    pi-memory(jayzeng) 0.4.2 39e6b998(与既有评论同一 SHA)
    @henryqw/pi-memory 6.0.5 HenryQW/pi-harness@6a5a445 — henryqw/pi-memory 独立仓 404
    @amaster.ai/pi-memory-mem0 0.1.14 TGYD-helige/pi@569b7bc(git package.json 仍写 0.1.2-beta.15)
    @amaster.ai/pi-memory 0.1.14 同 monorepo packages/pi-memory — 与 mem0 是两个包
    @remnic/plugin-pi npm 9.69.56 / git 9.69.68 joshuaswarren/remnic@962cdd2

    OpenPI 对照:a9b40f0。

    四条 skip 机制(源码指针)

    这些包在话术上像 Tasks / Goal / Context Pivot,机制上是平行 control plane。OpenPI 三件分别是:session-tasks 咨询性意图(cold-run 才投影,agent_settled 删除);session-goal 当前目标(完成禁止靠「记忆」);context_pivot 同 Session 切前缀(≥30k,无第二文件)。

    1. Second store — 权威不在 Pi Session。

    • hermes:~/.pi/agent/pi-hermes-memory/ + SQLite FTS + 自有 skills/(src/index.ts resources_discover)
    • jayzeng:~/.pi/agent/memory/ + 可选 qmd(README file layout)
    • henryqw:config/pi-memory/memory/{MEMORY,USER}.md,/dream 写 agent-global SYSTEM.md(extensions/memory.ts DREAM_INSTRUCTION);ADR 006 明确不加 store 权限层
    • mem0:Cloud / 嵌入 SQLite / 自建 REST;设置键 pi-memory-mem0,不是 /openpi-setup
    • remnic:daemon :4318 + installer 写 ~/.pi/agent/extensions/remnic/remnic.config.json(含 token);Pi remnic_state 只做 observe 去重

    2. Auto-consolidate — 默认或准默认的额外模型调用。

    • hermes:memoryOverflowStrategy: "auto-consolidate",每 10 turn / 15 tool-call review,flushOnCompact(src/config.ts DEFAULT_CONFIG;src/handlers/auto-consolidate.ts)
    • jayzeng:session_before_compact 自动写 HANDOFF 进 daily(index.ts L1586+)
    • henryqw:每个 add 走独立 pi-memory/reviewCandidate(不用当前 Session 模型);MEMORY CHECK 每 turn 要求再写
    • amaster memory:session_start 就 runDream,默认 gpt-4.1-mini(src/extension.ts、src/dream.ts)
    • mem0:默认 hybrid,turn_end 自动 provider.add() 抽取(src/index.ts)
    • remnic:默认 observe + compact 前 lcmCompactionFlush(src/index.ts L250+)

    3. Secret scan claims — 写路径/召回路径正则,不是 #507 egress,也不是真实性证明。

    • hermes content-scanner.ts:sk- / ghp_ 以及环境变量名(测试里 ANTHROPIC_API_KEY should be set in .env 也会 block)
    • jayzeng:无 scanner
    • mem0 privacy.ts:私钥块 / Bearer / api_key= 形状 redact;召回再走 threat 词表。platform 模式仍把 turn 送出本机
    • amaster memory:threat-patterns 主要是 injection / SSH 词表
    • remnic:不声称扫密钥;observe 会把 transcript 送进 daemon

    不要把 hermes 当 #507 扫描器。

    4. Inject-later — 现在写,以后普通 turn 自动回到模型眼前。

    • hermes:每个 before_agent_start 注入 policy(full ≈ 3942 字符)+ STANDING.md(≤2000,policy-only / style none 也注入)(src/prompt-context.ts)。policy-only ≠ 零税(与 09-08 评论一致)
    • jayzeng:每个 turn 最高 16K;forget 必须 snapshotDirty,否则「忘了还在注入」(index.ts L1539 / L2117)
    • henryqw:工具描述写明「Memory is injected every turn」;before_agent_start 拼冻结快照 + MEMORY CHECK
    • mem0:input prefetch,before_agent_start 用 user 通道 customType: 'mem0-recall' 注入
    • remnic:首 turn recall(),其后每 turn 把同一 cachedContext 拼进 systemPrompt(默认 12K)

    这直接打中 #167 正文「默认不自动写、不自动注入、不增加普通 turn 静态税」,以及「不从向量库或远程 memory server 起步 / 不让模型默认改 authored Skills」。

    #167 若继续,仍是手工、可纠正、非自动 memory DB。Tasks / Goal / Context Pivot 继续只做意图、当前目标、同 Session 换阶段,不当长期知识库。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions