anchor — agents that remember their own work
anchor = mm + ms. Memory management plus memory search for AI agents.
When a long-running agent hits its context limit, compaction summarizes the
history — and the summary silently drops the details: the tool the agent built
(p3c2), the file it wrote, the decision it made, the approach it tried and
rejected. The agent then rebuilds things it already built. anchor fixes this
in two halves:
- mm (memory management) — every raw session event lands in an append-only
archive before compaction can destroy it, and every entity (tool names,
file paths, decisions) is extracted into an index:
entity → where it's explained. - ms (memory search) — a dangling-reference trigger notices "the agent
sees
p3c2and doesn't know what it is" for the agent (agents are bad at noticing this themselves), then a search ladder recovers the answer with citations: index → workspace files → BM25 over raw history → LLM rewording → piece-by-piece reconstruction. Misses return a tried-log (the negative result), which the relay passes to the next searcher.
Pure stdlib Python — no pip dependencies to run, works offline, optional local-Ollama for one rung. Ships as an MCP server so Claude Code, OpenCode and any MCP client can use it in one config block.
install
pip install anchor-memory
That's the whole install. Verify with python -m anchor.selftest, then wire
it into your tool (next section). Source, if you'd rather: pip install git+https://github.com/zacharyol/anchor-memory.git
Website & full setup guide: https://zacharyol.github.io/anchor-memory/
quickstart
anchor-mcp # starts the MCP server (stdio)
python -m anchor.selftest # offline end-to-end test with numbers
python -m anchor.replay # ingest your own OpenCode session history
Wire it into your agent (one block, then restart the session):
{ "mcpServers": { "anchor": { "command": "anchor-mcp" } } }
Your agent gains: anchor_resolve (what was p3c2?), anchor_check (which
names in this summary are unexplained?), anchor_search (BM25 over raw
history), anchor_sessions, anchor_sync (incremental ingest from the live
session database), anchor_stats, and anchor_relay (shard-searchers with
negative-result merge — the last resort before "unfindable").
measured results (real session history, llama3.1:8B judge-free agent)
| version | change | vanilla → anchored recall | token overhead |
|---|---|---|---|
| v0.3 | bulk cards | 33% → 44% | +48% |
| v0.4 | selective card | 33% → 44% | +5% |
| v0.5 | junk filter, repeats (n=36) | 19% → 47% | +5% |
| v0.6 | best-explanation cards (n=72) | 19% → 42% | +5% |
| v0.7 | full rerun on shipped code (n=72) | 26% → 24% (wash) | +5% |
v0.7 honesty note: the card-thinning regression (docstrings replacing rich lines) ate the recall gap — root-caused and fixed in the current source (docstring prepends, rich lines kept). Verification rerun of the fixed code pending; coverage still favored anchored (+5 pts) and wobble stayed ±5–6%.
Trigger fire precision on labeled real data: 58% (firing is free — junk is filtered at the card layer). Sampling wobble ±5–6%: model randomness is small; question difficulty dominates. Full methodology: docs/BENCHMARK.md.
how it's made
- docs/HOW_IT_WORKS.md — the architecture walk-through: the two memory classes, the write path, the trigger rules, every ladder rung, the relay, the data formats.
- docs/BENCHMARK.md — how the numbers above are produced and how to reproduce them on your own session history.
- DESIGN.md — the original design doc, kept as written.
why open source
Memory loss after compaction is the defining production failure of long running agents ("context rot"). anchor's answer is deliberately simple: archive raw, index entities, detect the gap automatically, search in a cost ladder, and never trust a summary when the primary source still exists. MIT licensed — take it, wire it, fork it.
works with
Claude Code · OpenCode · any MCP client · local Ollama (optional, rung 2)
MIT License · repo: https://github.com/zacharyol/anchor-memory
Metadata
Release files for anchor-memory 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| anchor_memory-0.8.0.tar.gz | 30.0 kB | Without provenance | Details for anchor_memory-0.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| anchor_memory-0.8.0-py3-none-any.whl | Python 3 | none | any | Details for anchor_memory-0.8.0-py3-none-any.whl |
Total release size: 61.7 kB
Release files / anchor_memory-0.8.0.tar.gz
| Download URL | anchor_memory-0.8.0.tar.gz |
|---|---|
| Size | 30.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b4a7b066ce0299eb9f142ef1642a4bc759741ce667fc39da564aff2b9cd91b0
|
|
BLAKE2b-256 checksum How to use checksums |
22a37fd9e65b0e509681b64efd4ec3f7ea6368d5a3e1d6859dbd9b97be2bf84e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.5
|
Release files / anchor_memory-0.8.0-py3-none-any.whl
| Download URL | anchor_memory-0.8.0-py3-none-any.whl |
|---|---|
| Size | 31.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
126fc789c0e9f11e61ab469985f4d19a4bf08fc1e98037b6dd870ede1630b658
|
|
BLAKE2b-256 checksum How to use checksums |
eb4ce0ba8ece95df4f8bffc8fe03cdfa2ddb17bfc09071e4cac90bf67dd767a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.5
|
Security for anchor-memory 0.8.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.