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        # from PyPI (once published — see site for status)

or straight from this repo — works right now:

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%

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.7.0

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.7.0
File Size Uploaded Provenance Actions
anchor_memory-0.7.0.tar.gz 28.0 kB Without provenance Details for anchor_memory-0.7.0.tar.gz

Built distribution (wheel)

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

Total release size: 58.5 kB

Release files / anchor_memory-0.7.0.tar.gz

Download URL anchor_memory-0.7.0.tar.gz
Size 28.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cfb416a0f47ed173de733d9487d23fbf1dbbe38dad5076c185fa1bb590ed5a27
BLAKE2b-256 checksum
How to use checksums
af76ef1a15341fb5b2be92bd33c777f57ed2e94e6d75d620072b9137ae41ae11
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.7.0-py3-none-any.whl

Download URL anchor_memory-0.7.0-py3-none-any.whl
Size 30.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e372ac086383a502ee162528f14e833ebd78cc113ea4b04ef571aa06674a2ce4
BLAKE2b-256 checksum
How to use checksums
bb1157dfc6627740ee9d967907d30df15f044f98b589b7a2f71cf3821af21751
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.7.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.

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