Persistent memory for agentic systems — a faithful transposition of human memory architecture.
Project description
memory-molecule
Persistent memory for agentic systems — a faithful transposition of human memory architecture into code.
Installation
pip install memory-molecule
Quickstart
from memory_molecule import MemoryMolecule, MemoryConfig
# Initialize with a vault directory
config = MemoryConfig(vault_path="./my-vault", project="my-project")
mm = MemoryMolecule(config)
# Store a memory
mm.store("Decided to use PostgreSQL for persistence",
memory_type="decision", importance="foundational")
# Recall memories by concept
results = mm.recall("database persistence")
for r in results:
print(f"[{r['importance']}] {r['content'][:100]}")
# Apply memory decay (memories fade if not accessed)
report = mm.decay()
print(f"Archived {report.archived_count} stale memories")
# Session lifecycle
bundle = mm.on_session_start() # Load relevant context
# ... do work ...
mm.on_session_end(commits=["abc123 feat: add auth"], decisions=["Use JWT tokens"])
Tiered Memory Loading
memory-molecule loads context in three tiers to respect token budgets:
from memory_molecule import MemoryLoader, MemoryConfig
loader = MemoryLoader(MemoryConfig(vault_path="./vault"))
result = loader.load(query="authentication", max_tokens=100000)
print(f"Tier 1: {result['tier1']['tokens']} tokens (always loaded)")
print(f"Tier 2: {result['tier2']['tokens']} tokens (recent context)")
print(f"Tier 3: {result['tier3']['tokens']} tokens (on-demand)")
| Tier | Target | Contents | Trigger |
|---|---|---|---|
| 1 | 5K tokens | Invariants, latest context, git state | Always |
| 2 | 50K tokens | Recent sessions, decisions, phase docs | If budget allows |
| 3 | 150K tokens | Full journals, expertise, knowledge graph | Explicit query |
Memory Types
| Type | Description | Importance Levels |
|---|---|---|
| session | Session journals | context (default) |
| decision | Architectural decisions | foundational, hard_constraint |
| expertise | Learned patterns | foundational |
| knowledge | Domain knowledge | varies |
Decay Model
Memories decay exponentially if not accessed:
- Base decay:
0.95^days(half-life ~14 days) - Importance modifiers: hard_constraint decays 2x slower, tactical decays 1.5x faster
- Access reinforcement: each access boosts relevance by 0.05 (max 0.3)
- Archive threshold: memories below 0.1 relevance are archived (not deleted)
Observation Events
When configured, memory-molecule emits events to an observation server:
MemoryStore— content written to vaultMemoryRecall— search performedMemoryDecay— decay pass appliedMemorySessionStart— session initializedMemorySessionEnd— session closed
Configure with MemoryConfig(observation_url="http://localhost:4000/events").
API Reference
MemoryMolecule
| Method | Returns | Description |
|---|---|---|
store(content, memory_type, importance) |
str (path) |
Write to vault |
recall(query, top_k) |
list[dict] |
Search by concept |
decay() |
DecayReport |
Apply relevance decay |
diff(session_a, session_b) |
SessionDiff |
Compare sessions |
on_session_start() |
RecallBundle |
Load session context |
on_session_end(commits, decisions) |
None |
Close session |
consolidate(session_id) |
str |
Summarize recent sessions |
MemoryLoader
| Method | Returns | Description |
|---|---|---|
load_tier1() |
dict |
Always-load context |
load_tier2(days) |
dict |
Recent relevant context |
load_tier3(query) |
dict |
On-demand deep context |
load(query, max_tokens) |
dict |
Fill tiers to budget |
Vision
This package is a community-extractable component of the Oracle agentic engineering system. It implements a faithful transposition of human memory architecture:
| Human Memory | Agentic Equivalent | Status |
|---|---|---|
| Working memory | Context window | Built-in |
| Episodic memory | Session journals | Implemented |
| Semantic memory | Knowledge database | Implemented |
| Procedural memory | Expertise patterns | Implemented |
| Consolidation | Compression pass | Implemented |
| Forgetting curve | Exponential decay | Implemented |
| Associative recall | Importance-weighted search | Implemented |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file memory_molecule-0.1.0.tar.gz.
File metadata
- Download URL: memory_molecule-0.1.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b77eff091700f1c30665103ed0f6c20c23200786b81e80726d576778d2fc62f4
|
|
| MD5 |
506c061978561983477225a75951ba8f
|
|
| BLAKE2b-256 |
b279395d7880d575904c97fa6c171e0e59d3a70e8461a01726af8fb7b6120dda
|
File details
Details for the file memory_molecule-0.1.0-py3-none-any.whl.
File metadata
- Download URL: memory_molecule-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd796d351a646de0b9a23e5851c27bb7b6f72bb341f426ca07919b2f51eb0cc2
|
|
| MD5 |
295eea220e5735e4700092bfbf8a052e
|
|
| BLAKE2b-256 |
8252b497f66b999f284bc872222373a0b7e3a4805aad1ecf5f9d8664a5864864
|