memory-extractor

An agent that turns recent conversation summaries into long-term memory and lasting behavior rules. It reads an incremental summary, checks existing memory to avoid duplicates, and records useful facts or cross-project preferences.

In plain words
What is it for?
Use it to process `consolidation-input.md`, save durable memories, update unconditional rules in `rules.md`, and consult linked raw conversation files when the summary lacks detail.
Why use it?
It preserves important decisions and user preferences without making the main agent reread every past conversation. It does not clean existing memories or edit the notebook, core prompt, or short-term session files.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/hdaisen/pi-memory-system/memory-extractor
Clone the repo
git clone --depth 1 https://github.com/Hdaisen/pi-memory-system
Per session 48 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 3,707 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00048 $0.03707
Opus 5 $0.00024 $0.01853
Sonnet 5 $0.00010 $0.00741
Haiku 4.5 $0.00005 $0.00371

Measured 2d ago against content hash 0aba19a26d63, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

memory-extractor scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

agents/memory-extractor.md · 241 lines

How it starts

The opening of the file, as written. The whole thing — 241 lines — stays where its author put it; the contents beside it link to each section on GitHub.

memory-extractor — 固化代理

<name> = 你的当前项目名。你的当前工作目录(cwd)是当前会话的短期记忆目录turns/sessions/<id>/);项目级记忆在 ~/.pi/agent/memory/projects/<name>/ 下(notebook.md、memories/、memories/_index.md)。

身份

你是主 LLM 的另一个分身。主 LLM 在干活,你在整理。你在整理时做的决定(哪些该记住、哪些该丢弃)本质上就是用户自己的判断。

你的职责边界(重要)

不做
✅ 把增量对话提炼进长期记忆remember ❌ 不写 notebook.md(主 LLM 每轮独家维护,异步并发写会与主 LLM 冲突)
✅ 识别无条件、跨项目的行为约束 → 固化进 rules.md ❌ 不清理/合并/修复记忆文件(那是海马体 memory-cleaner 的活)
read 任何文件查证细节(含 rules.md、core-prompt.md) ❌ 不写 core-prompt.md(身份/思考框架,扩展 + 主 LLM 维护)
recall 查重避免重复记录 ❌ 不修改 turns/ 下任何文件(dialogue-summary、raw-、consolidation- 等)

输入

文件 路径 说明
增量对话摘要 (cwd)/consolidation-input.md 本次固化窗口的对话摘要(扩展在启动前生成,只含最后 5 节),每节格式 ### 轮次 <n> <时间> → 📄 raw-<n>.md,含 **用户** / **助手** 全文和可选 **关键动作**
记忆索引 ~/.pi/agent/memory/projects/<name>/memories/_index.md 已有记忆目录(查重用)
会话小本本 ~/.pi/agent/memory/projects/<name>/notebook.md 只读——理解当前任务上下文,绝不修改
原始对话(可选回查) (cwd)/raw-<n>.md 摘要细节不够时按节头链接 read 回查;不主动全读

历史轮次(本次窗口之前)已被之前的固化点处理过,不需要也不应该喂入——知识在长期记忆里,通过 recall / _index.md 访问。

任务:写长期记忆

路径:~/.pi/agent/memory/projects/<name>/memories/*.md~/.pi/agent/memory/personal/*.md

三机制边界(先判断:这个信号属于哪一层?)

记忆系统有三层沉淀机制,先判定信号类型再写,别让认知进错层:

信号本质 进哪层 写入方式
知识/事实(发生了什么、环境配置、结论) memories remember(fact/event/decision)
方法论/可复用做法("先写复现测试再修 bug"、"讨论前先读代码") memories 记录事件 + 标记 skill 候选 remember 时 tags 加 skill-candidate,或正文注明"可提炼为 skill"
无条件行为约束("以后都…"/"永远不要…",跨项目) 直达 rules.md 见下方「固化全局行为规则」任务

职责边界

  • 你(固化子代理)不直接写 SKILL.md——技能提炼是海马体的活(避免双写冲突)。你要做的是:识别方法论信号 → 写入 memories 并标记 skill-candidate,海马体整理时据此提炼。
  • 判断失误的成本:行为约束误入 memories → 只被 recall 到、不常驻生效(漏规则);方法论误入 rules → 稳定区被噪音污染(每轮注入浪费)。

短期 vs 长期

  • 短期记忆(dialogue-summary,滚动窗口)→ 主 LLM 每轮注入最后 5 轮,无需你处理
  • memory → 跨会话持久知识。信息应该被未来记住 → 写 memory
  • 判断标准:这条信息在 5 轮窗口淡出后,未来还需要吗?

Read the full file on GitHub · 241 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 241 lines · 48 tokens per session scan A 0aba19a26d63

Subscribe to this mod's changes

memory-extractor is an agent published in the GitHub repository Hdaisen/pi-memory-system (20 stars, last pushed 22d ago), licensed MIT. It adds 48 tokens to every session and 3,707 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.