Zifu Memory
<!-- mcp-name: io.github.tanbopiao/zifu-memory -->
# 紫府 · Zifu Memory
**Verifiable, replayable, scope-aware memory service for AI agents — via MCP.**
Most agent memory systems are *editable notebooks*: an LLM pipeline rewrites
memories (add / update / delete) and the previous state is gone. Zifu Memory is
an *auditable chronicle*: an append-only event stream with fingerprinted
snapshots, replay to any point in time, contract-governed facts, and
scope-based access control.
## Three pillars
1. **Persistent** — append-only event stream as the source of truth; nothing is
silently rewritten.
2. **Replayable** — rebuild the full state at any timestamp from snapshots plus
the event stream; every fact carries a source pointer and fingerprint.
3. **Cross-session, cross-node** — scoped memory (session / user / agent / org)
with session handoff and resume packs; sync-ready for federated nodes.
## Install
```bash
pip install zifu-memory
```
## Wire into your MCP client
```json
{
"mcpServers": {
"zifu": { "command": "zifu-mcp", "args": [] }
}
}
```
Data directory: set `ZIFU_HOME` (defaults to `~/.zifu`).
## Tools (17)
| Tool | What it does |
|------|--------------|
| `zifu_write` | Append a memory (passes the fail-closed gate: credentials / OTPs / phone / ID numbers are rejected) and return a source pointer |
| `zifu_search` | Keyword lookup (entity-level digest) |
| `zifu_semantic` | Semantic search (pluggable embedder; zero-dependency char-bigram core by default) |
| `zifu_hybrid` | Keyword + semantic merged search |
| `zifu_events` | Time-window event stream reader |
| `zifu_state` | Current state |
| `zifu_replay` | Rebuild state at any timestamp (verifiable) |
| `zifu_export` | Pack a cold backup |
| `zifu_retention` | Tiered retention report (7d fine / 90d hourly / older: ledger + fingerprints) |
| `zifu_assert` | Contract 1+2: register a fact with a source pointer; duplicate IDs are deterministic errors |
| `zifu_replace` | Contract 2: revise a fact, history preserved |
| `zifu_retire` | Retire a fact (mark only, never delete) |
| `zifu_facts` | List the fact ledger |
| `zifu_inject` | Contract 3: deterministic context packing under a hard budget |
| `zifu_view` | Contract 5: consistent view (state + active facts at a timestamp) |
| `zifu_handoff` | End-of-session handoff summary (session-boundary free) |
| `zifu_resume` | New-session resume pack (handoffs first, then facts, then recent events) |
## The five contracts
1. **Source pointer first** — every registered fact must point to a resolvable
event (file + timestamp + fingerprint).
2. **Duplicate IDs are errors** — revising goes through `replace`, history kept.
3. **Hard injection budget** — context assembly is deterministic and reproducible.
4. **Idempotent replay** — replaying the ledger any number of times yields the
same state.
5. **Consistent views** — fork a consistent snapshot of state + facts at any time.
## Scope model (fail-closed)
```
session < user < agent < org
```
Writers tag memories with a scope; readers declare their identity. Without an
identity you only see `org`-level memories. Legacy data defaults to `org`.
## Design notes
- Zero-dependency core (standard library only); the MCP shell needs `mcp>=1.0,<2`.
- The semantic layer is a pluggable slot: the default char-bigram TF-IDF core
works offline; swap in a real embedding model without changing the retrieval
logic.
- Forgetting is *tiered*, not deleted: fine-grained snapshots for 7 days,
hourly snapshots for 90 days, event ledger + fingerprints forever.
## License
Apache-2.0
TDQS
Scored across 17 tools
The retrieval trio (zifu_search / zifu_semantic / zifu_hybrid) is clearly delineated, and the fact-ledger ops (assert/replace/retire) are well separated. However zifu_write vs zifu_assert overlap (raw experience vs pointer-bearing fact), and zifu_state ("current memory state") is vague next to zifu_facts, zifu_events and zifu_view, making misselection plausible.
All 17 tools share the zifu_ prefix and snake_case, which is highly predictable. The only deviation is grammatical: some names are verbs (write, search, assert, replace, retire, inject, replay) while others are nouns (facts, events, state, retention, handoff) or adjectives (semantic, hybrid).
17 tools is on the heavy side but each maps to a concrete lifecycle stage of a memory system (ingest, three retrieval modes, ledger mutation, context assembly, session handoff/resume, maintenance). Nothing looks redundant enough to cut outright, though the three retrieval variants could arguably be collapsed into one parameterized tool.
Coverage is broad: ingest, retrieval, fact correction via replace/retire, budgeted context assembly (inject/resume), point-in-time reconstruction (view/replay), export and retention. The notable gap is that experience memories written by zifu_write have no update or correction path — only facts can be replaced — and there is no explicit delete/purge (deliberate append-only, but agents may hit that dead end).