Back to all work

Agentic AI engineering

Persistent Memory

Persistent memory for AI agents, installable from PyPI, with versioned evidence, withdrawal checks, an MCP server and an optional policy registry.

Summary

Persistent Memory gives AI agents a memory that stays true over time. It stores what an agent learns, records the exact source versions behind every summary, rule or lesson, and stops serving anything built on a source that was corrected or withdrawn. Every session that was shown such an entry is told once. Python code imports the library; other tools and frameworks connect to its MCP server.

Version 0.4.0a4 is published on PyPI as persistent-memory-mcp, under the MIT license, for Linux, macOS and Windows. The base install depends only on the Python standard library and SQLite. The server flags near-duplicate entries, and options add a review mode and search by meaning with a local model. A separate policy registry is available alongside.

Public results

  1. Keep the thread across sessions

    Retrieve useful information when a task resumes, taking account of corrections and changes since the previous session.

    Across eight synthetic histories, memory achieves 77 successes out of 96, compared with 29/96 for a lexical baseline with validity checks.

    Read the cross-session continuity study
  2. Reuse experience from another task

    A task is performed, its result is checked and a lesson is extracted. Memory stores that experience with its sources for retrieval during a different task in a fresh session.

    In the synthetic study, Luna succeeds on 22 of 24 tasks with the lesson, compared with 13/24 with the complete trace and feedback, and 7/24 without experience.

    Read the learning-between-tasks study
  3. Keep memory consistent after a correction or failure

    Trace information to its sources and versions, exclude withdrawn evidence and check an old backup before reusing it.

    Across 100 lifecycle scenarios, all 751 valid reads are preserved and all 389 forbidden reads are blocked. Detailed measurements include recovery after process termination.

    Read the corrections and recovery study
Explore detailed measurements and integration observations

Version 0.4.0a2, the first PyPI release, was published on 15 November 2026 and 0.4.0a4 followed on 17 November, both through GitHub trusted publishing, with an attestation for each file and published checksums. After the first release, installation was checked from PyPI with pip and uvx, and on Windows 10 Claude Desktop started the memory server from the configuration written by setup and found a stored entry again.

Eight agent frameworks loaded the ten tools through their own MCP integration: LangChain and LangGraph, OpenAI Agents SDK, Pydantic AI, CrewAI, LlamaIndex, AutoGen, smolagents and the official MCP SDK. Each ran the same sequence: remember a fact, find it, withdraw it, search again. The withdrawn entry was no longer returned. Each study publishes its code, synthetic data, protocol and offline calculations.

Across 100 fixed lifecycle scenarios, all 751 valid reads were preserved and all 389 forbidden reads were blocked, matching a SQLite reference with retained current authority. After the core change, four SIGKILL interruption scenarios passed on each Linux host, with observed recovery times of 0.227 to 0.383 seconds.

Across eight synthetic development histories retained between sessions, memory achieves 77 successes out of 96, compared with 29 for a lexical baseline with validity checks. The campaign used 192 generations without retries; two Codex readers assessed the answers blind to the configuration.

Targeted core optimizations reduced instrumented workload time by 28.01% and 27.68% on two hosts at 1,000 sources and 50 searches, then by a median 6.79%, with CPU time down 6.77%, at 1,500 sources, with the same checked outcomes and storage sizes.

In a learning study, a model completed task A, received feedback on its actual output and extracted a lesson before a different task B in a fresh session. Across 48 episodes, Luna succeeded in 22 of 24 B tasks with a lesson, 13 with the complete trace and seven without experience; Sol scored 24 of 24 with either, and 12 without. The files produced by all 192 B tasks were reopened and checked independently.

Two sessions of a real agent each passed seven tests on the same thirteen scenarios, with stored lessons delivered automatically. A second agent retrieved that experience and produced code that passed the same tests unchanged, in one task.

Role and scope

I design and develop the storage, retrieval and recovery mechanisms, the Python interfaces, the MCP server and the setup command for client tools. I also maintain the packages for Linux, macOS and Windows, the PyPI release workflow, bilingual documentation, standalone examples and tests for failures, concurrent access and evidence withdrawal.

Problem and constraints

Agents build on what they remember: facts, summaries, procedures and lessons from earlier tasks. When a source turns out to be wrong and is corrected, everything derived from it keeps being served, and nothing tells the agent. A search index or a restored backup can even bring back evidence that was already withdrawn. Memory has to know which versions are still valid before it returns any context.

Architecture

Exact provenance. Every entry is an immutable version. A summary, procedure, lesson or index entry names the exact parent versions it was made from, and explain shows that chain. Corrections are compare-and-swap on the expected version, so two agents cannot silently overwrite each other’s work.

Cascade. Withdrawing or correcting a source makes everything derived from it unreadable, through every level of derivation. A withdrawal plan lists what would be blocked before anything is applied. A citation keeps a link without propagating, and nothing is physically erased.

Notices to sessions. A ledger records which versions each session was shown. When one of them stops being valid, that session receives a notice once, with its next tool result, so an agent learns that what it read earlier no longer holds.

Authority apart from content. A separate authority database and a freshness witness decide what is still valid. The full-text index, local vectors and the Qdrant projection only propose candidates; each one is read again through the authority, so a stale index cannot bring back a withdrawn entry. A restored backup starts in quarantine and is reconciled with the current authority.

Lessons with their sources. learn stores a task trace and its feedback as sources and derives the lesson from both. Only the lesson is searchable, and withdrawing the trace or the feedback blocks the lesson too.

One operations surface gives every entry point the same memory. The MCP server exposes it as ten tools over stdio or Streamable HTTP. The setup command writes the configuration of Claude Code, Claude Desktop, Cursor, VS Code, Windsurf and Codex, and all of them share one store by default.

The server also keeps memory clean. A new entry that nearly repeats an existing one comes back with a warning naming the close entries. An optional review mode holds an agent’s writes until a person approves them. Optional search by meaning runs a multilingual model on the CPU, in the server process; its vectors hold references, never text, and every candidate is checked again by the authority like a keyword result.

Typed records distinguish documents, observations, hypotheses, procedures, tasks and feedback. An optional renderer turns reviewed facts into French text that keeps its source versions and passages, and an admission module checks the final output and reports unknown, conflicting or withdrawn evidence.

Decisions and trade-offs

The authority validates evidence; the index supplies retrieval candidates. Writes use compare-and-swap, and recovery checks old content snapshots against retained current authority, starting in quarantine. The optional registry separates policy proposal, evidence, admission and rollback. The host controls policy activation and permissions.

Testing and verification

Version 0.4.0a4 has 404 public test methods; the separate policy registry, version 0.2.0a2, has 51. Continuous integration runs them from the installed package on Linux, macOS and Windows, with Python 3.11 to 3.15. The release workflow builds the archives once, tests them on the three systems, publishes them to TestPyPI, reinstalls them from there on Linux and Windows, then waits for my approval before PyPI. Separate synthetic studies cover corrections, withdrawals, process failures, execution time and learning between tasks.

Resources and links

Usage and integration

Install with pip install persistent-memory-mcp, then run persistent-memory setup with the name of the client. The command keeps the other entries of each configuration file, saves a backup first and changes nothing when run twice. Python code imports persistent_memory directly.

Agent frameworks connect through their own MCP integration, without an adapter to maintain. Over Streamable HTTP with a token, agents on several machines can share one store.

Search by meaning is turned on with --semantic: the model runs in the server process, or an OpenAI-compatible embeddings endpoint such as Ollama provides the vectors. Review mode is turned on with --review.

Next case study

Bifrost

View case study