Skip to main content

deep-memory-agent

License: MIT Version Python

Factory for building LangChain deepagents equipped with episodic, semantic, and procedural memory.

Memory is a small wiki of plain markdown files — readable, diffable, versionable with git — that the agent maintains itself: it records what happened, supersedes what is no longer true, and consolidates recurring patterns into durable knowledge.

The tree lives at the virtual path /memory/, served by a deepagents backend. No tool in this package touches the host filesystem directly, so the same agent runs unchanged against a directory on disk, ephemeral thread state, or a remote store.

📖 Documentation: https://giurlanda.github.io/deep-memory-agent/

Installation

pip install deep-memory-agent

Quickstart

Two factories, one tree. The manager writes; the search agent cannot.

from deep_memory_agent import create_memory_manager_agent, create_memory_search_agent

manager = create_memory_manager_agent("claude-sonnet-5", memory_dir="./memory")
manager.invoke(
    {
        "messages": [
            {
                "role": "user",
                "content": "Remember that I manage Python projects with uv.",
            }
        ]
    }
)

recall = create_memory_search_agent("claude-sonnet-5", memory_dir="./memory")
recall.invoke(
    {"messages": [{"role": "user", "content": "Which package manager do I use?"}]}
)

Each factory takes either memory_dir — the default on-disk wiring — or a ready-made backend. Exactly one of the two is required; passing both raises.

The memory tree

/memory/
├── index.md                      router for the whole tree
├── preferences.md                how the user wants the agent to behave
├── episodic_memory/              what happened
│   ├── index.md
│   ├── events/YYYY-MM.md         sharded by month
│   ├── feedbacks/YYYY-MM.md
│   └── errors/YYYY-MM.md
├── semantic_memory/              what is true
│   ├── index.md
│   ├── facts.md
│   └── rules.md
└── procedural_memory/            how things are done
    ├── index.md
    └── <slug>.md                 one file per procedure

Every entry carries YAML frontmatter, so provenance travels with the content and a newer statement can explicitly retire an older one:

---
id: mem_2026-08-24_9f3a1c
created: 2026-08-24T10:15:00+00:00
type: semantic
category: facts
source: user_message
confidence: high
tags: [pricing, acme]
supersedes: mem_2026-06-01_4b2e77
summary: ACME moved to the Enterprise plan
---

ACME switched from the Team plan to Enterprise on 2026-08-24.

Three rules keep the tree from degenerating into an append-only log:

  • Indexes are routers, never content — one line per file, so the agent can decide what to load without loading everything.
  • Semantic memory is superseded, not appended — a changed fact produces a new entry that retires the old one, which stays on disk as history.
  • Episodic memory is sharded by month — no single file outgrows the context window.

Consolidation

Episodic memory on its own is a log. consolidate_memory reads recent episodes and promotes what has hardened into facts, rules or procedures. It is a plain function, so it can be scheduled from ordinary code; the manager agent also exposes it as the memory_consolidate tool.

from deep_memory_agent import build_memory_backend, consolidate_memory

backend = build_memory_backend("./memory", for_deep_agent=False)
result = consolidate_memory(backend, "claude-sonnet-5")

for_deep_agent=False is what makes the backend usable outside an agent: the default wiring parks non-memory paths in LangGraph thread state, which is only reachable from inside a graph execution.

Episodes are never deleted: consolidation only adds durable knowledge and supersedes what it contradicts.

See examples/ for runnable scripts, or the docs.

Benchmark

benchmark/ holds a LongMemEval-style benchmark for the two agents. Unlike LongMemEval, which scores a retriever over a frozen chat log, it replays episodes through the real manager agent one session at a time, so extraction, supersession and consolidation are all part of what is measured — and failures are decomposed across those three stages rather than two.

uv sync --group benchmark
uv run --group benchmark jupyter lab benchmark/run_benchmark.ipynb

Scope of this version

Memory is file-based and retrieval is lexical (case-insensitive substring over summary, body and tags). The structured frontmatter is what makes a stronger index — BM25, embeddings — addable later without changing the files themselves. Automatic decay, locking between concurrent writers and vector retrieval are out of scope; keeping a single writer over the tree is the manager agent's job.

Development

This project uses uv for dependency management.

uv sync --all-extras
uv run pytest
uv run ruff check .
uv run ruff format .

License

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deep_memory_agent-0.1.3.tar.gz (272.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deep_memory_agent-0.1.3-py3-none-any.whl (33.8 kB view details)

Uploaded Python 3

File details

Details for the file deep_memory_agent-0.1.3.tar.gz.

File metadata

  • Download URL: deep_memory_agent-0.1.3.tar.gz
  • Upload date:
  • Size: 272.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for deep_memory_agent-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e2f38157721130461f36d25b81b74954b4a72ce4135c95a52e0f34cc456e2ece
MD5 72911247b5c66b6dd6845803e021bcd1
BLAKE2b-256 349200f48301a2d5685429a68dcdf01f1868d25dff992e9248304603120e0b27

See more details on using hashes here.

Provenance

The following attestation bundles were made for deep_memory_agent-0.1.3.tar.gz:

Publisher: publish.yml on giurlanda/deep-memory-agent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deep_memory_agent-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for deep_memory_agent-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d6c3eb1f784977f6ac038ea6bbf3cf05472635cff9a7600eaf0491e53f6c17d6
MD5 21189ff4c26fdf57e1a08bf4cd3bf05a
BLAKE2b-256 01db73b2d3bbfd55b046ed1c0cee1721a1f06e95a47f5eb45d030c771173a04d

See more details on using hashes here.

Provenance

The following attestation bundles were made for deep_memory_agent-0.1.3-py3-none-any.whl:

Publisher: publish.yml on giurlanda/deep-memory-agent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.4

2 files

This release

0.1.3 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

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