
Compound Memory
io.github.chinwev0.4.3更新於 Oct 7, 2026
Local-first shared memory for multiple AI agents that compounds with use; Markdown + git, MCP + CLI.
概覽
為 AI 助理提供本機共享的 Markdown 記憶庫,可跨工作階段與跨主機寫入、檢索、連結並強化記憶。
- 功能
- 以五個 MCP 工具(memory_write、memory_search、memory_get、memory_link、memory_feedback)作為讀寫邊界,操作本機帶 frontmatter 的 Markdown 記憶檔案。記憶帶有信賴度與使用次數:確認使用會提高信賴度,來自不同主機的回饋會額外加分,長期未用的記憶會衰減到可復原的封存區。CLI 支援初始化、統計、衰減、復原、蒸餾、衝突佇列與 git 歷史,並可選用 sqlite-vec 與 BGE 嵌入做語意檢索,無法使用時退回詞彙檢索。
- 適用情境
- 適合多個代理或工作階段需要共享持久事實、偏好、專案慣例與踩坑經驗的情境,避免每次從零重新發現。也適合希望記憶以可讀的本機檔案保存並帶 git 稽核紀錄,而非存放在不透明託管資料庫的使用者。
- 執行需求
- 本機程序;需要 Python 3.11 或更新版本,可從 PyPI 安裝,或複製儲存庫後以 uv 安裝。儲存根目錄預設為 ~/.agents/memory,可用 COMPOUND_MEMORY_ROOT 覆寫;強烈建議設定 COMPOUND_MEMORY_AGENT_ID,以便從程序環境解析呼叫方身分。未宣告驗證。選用向量檢索需要 sqlite-vec 與 BGE 嵌入。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Compound Memory,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
compound-memory
[CI] [PyPI] [Python] [License: MIT]
English | 简体中文
Local-first shared memory for multiple AI agents — plain Markdown files that compound in value as they are used. Memory lives on your disk as frontmatter-annotated Markdown, gets stronger with every confirmed use, decays into a revivable archive when neglected, and auto-commits to a local git history on every write.
Why
Every agent session starts from zero: preferences get re-asked, project conventions get re-discovered, the same pitfall gets hit twice. compound-memory gives all your agents one shared store:
- Local-first — nothing leaves your machine; memories are human-readable Markdown files, not rows in an opaque database.
- MCP-native — exactly 5 tools (
memory_write/memory_search/memory_get/memory_link/memory_feedback) as the single read-write boundary; works with any MCP host (Claude Code, ZCode, WorkBuddy, …), plus a full CLI for operations. - Compounding — confirmed usage raises confidence, related memories are recalled as neighbors, validation from a different host counts as independent evidence, and distillation merges many raw memories into fewer, denser ones.
- Multi-agent by design — a
_sharednamespace everyone reads, plusagent-*private namespaces each host owns; cross-host validation is tracked per host. - Optional semantic recall — vector search via sqlite-vec + BGE embeddings, with automatic graceful fallback to pure lexical search when unavailable.
Quick Start
For AI agents
Paste this one-liner into your coding agent (Claude Code, Cursor, ZCode, …) and let it do the rest:
For humans
1. Install
Python ≥ 3.11. Either route works:
2. Initialize your store
Defaults to ~/.agents/memory; override with the COMPOUND_MEMORY_ROOT env var.
3. Wire it into your MCP host (recommended)
This lets your everyday agents read/write the shared store automatically:
Installed from PyPI? Swap command/args for uvx + ["--from", "compound-memory", "compound-memory-server"] — no repo clone needed. Setting COMPOUND_MEMORY_AGENT_ID is strongly recommended: the store then resolves caller identity from the process env, so a model misreporting its identity (or forging someone else's source) is rejected loudly.
Verify: ask your agent to call memory_search (any keyword) — a {"hits": [...]} response means you're connected. Or run uv run compound-memory stats from the CLI.
4. Next step
Inject the usage protocol from skills/compound-memory/SKILL.md into your host (the search → feedback → distill loop), per docs/agent-integration.md §6.
Demo
[compound-memory CLI demo: init → write → search → feedback → stats]
One full loop: write → search → feedback (with cross-host first-validation bonus) → store health. Real output from v0.4.0, long payloads trimmed:
Two different hosts each write one stable fact (new memories start at confidence 0.5, uses 0):
Search ranks by score (--explain attaches per-hit ranking components for debugging):
A different host used this memory and reported it back — uses +1, conf +0.1; and since the reporter agent-workbuddy ≠ source agent-claude, the first cross-host validation adds another +0.15:
Store health at a glance (fixed-bucket histograms, liveness, distillation yield):
Three things to notice:
- New memories start at
confidence0.5 and move on evidence — feedback carries an outcome:successraises it,failurelowers it (floor 0.05),contradictionfreezes it into the review queue,obsoletearchives immediately. - First validation from a different host earns an independent bonus (once per host per memory), with
validated_by/evidencetrails — confidence is evidence of correctness, not popularity. - Hits embed one-hop neighbors automatically (empty here — no links yet;
memory_linkcreates bidirectional links that get recalled for free).
How compounding works
Scoring (weights are the W_* constants in src/compound_memory/scoring.py): 0.70·similarity + 0.15·confidence + 0.10·recency(0.5+0.5·e^(−Δt/τ)) + 0.05·type weight. With the vector channel enabled, ranking switches to RRF fusion with an ε=0.04 prior tie-break (see the spec, "index as cache").
The 5 MCP tools
Tool descriptions embed the protocol rules themselves, so agents keep the loop intact even without host-side rules injected. Full parameter reference: docs/agent-integration.md.
CLI
More operations: explain <id> (confidence composition + evidence detail for one memory), forget <id> --agent <id> (terminal removal, ADR-0009), review-resolve (adjudicate conflicts), extract <transcript|dir> (deterministic session-transcript mining).
Architecture
Scheduled distillation prep (launchd / cron / systemd)
Per ADR 0001, the deterministic prep runs on a schedule while judgment (summarizing / merging) stays with the calling agent. Every day at 09:00 the candidate list lands in <root>/distill/last-plan.json. Pick one scheduler — launchd (macOS standard, catches up after sleep), systemd user timer (Persistent=true, same catch-up), or cron (most portable, no catch-up) — all three drive the same platform-neutral scripts/distill-prepare.sh. Ready-made templates with copy-paste instructions: scripts/com.compound-memory.distill-prepare.plist.tmpl (launchd), scripts/compound-memory-distill-prepare.{service,timer}.example (systemd), and the Chinese README for cron. The script runs set -eu: any failure exits non-zero (visible via launchctl list / systemctl --user list-timers / cron mail, log at distill/prepare.log). distill/ is a runtime artifact directory (auto-gitignored) — no commit noise; only distill-apply after agent judgment lands one atomic commit.
Documentation
docs/specs/0001-compound-memory-spec.md— design specdocs/agent-integration.md— per-host MCP configs + the unified usage protocol (Chinese)docs/adr/— architecture decision recordsCONTEXT.md— glossary (Chinese)skills/compound-memory/SKILL.md— usage rules for hosts (Chinese)
Development
Test seams: the MCP tool boundary via in-process mcp.Client(server) (no subprocess) plus unit tests for core modules (scoring / index / store ops). CI runs tests, type checks, and a pure-wheel install smoke across Python 3.11/3.12/3.13.
Release
PyPI versions are immutable and the tag must match pyproject.toml's version (the release workflow verifies this and fails loudly). Releases go through GitHub Actions + PyPI Trusted Publisher (OIDC, no token): push a tag like v0.1.0 and release.yml builds and publishes automatically.
MCP Registry name: mcp-name: io.github.chinwe/compound-memory
來源:README.md,提交 852735b
工具
0版本歷史
1- v0.4.3最新Oct 7, 2026

