Skip to main content

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 p3c2 and 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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anchor-memory 0.8.1
File Size Uploaded Provenance Actions
anchor_memory-0.8.1.tar.gz 30.2 kB Without provenance Details for anchor_memory-0.8.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for anchor-memory 0.8.1
File Interpreter ABI Platform Actions
anchor_memory-0.8.1-py3-none-any.whl Python 3 none any Details for anchor_memory-0.8.1-py3-none-any.whl

Total release size: 62.2 kB

Release files / anchor_memory-0.8.1.tar.gz

Download URL anchor_memory-0.8.1.tar.gz
Size 30.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4e0c3ee75642a91512c04d0118c1f69383dc25d13edcd791599d36e0b56d3b49
BLAKE2b-256 checksum
How to use checksums
b8f3c2e4f67fcdf6580a9fa500d5c3645e32bc0e6f87cece8fac53ad1fe5e1c1
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.1-py3-none-any.whl

Download URL anchor_memory-0.8.1-py3-none-any.whl
Size 32.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3bf81df7db1534788b331c068bdb7d0d0a2491666661457ff93b436e674fdb43
BLAKE2b-256 checksum
How to use checksums
06b5e4e91a5c6ffeebd7a693fd29c9086037fb80735fbb7c824f6a70a5ca2ad2
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.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page