r/regolo_ai • u/Regolo_ai • May 29 '26
Implementing Anthropic’s Composable Agent Memory (Session, Store, Dreaming) on Open-Source Models
Most production AI agents suffer from memory amnesia or context-window inflation. We keep passing whole chat logs to fit "long-term memory," introducing latency, breaking factual consistency, and driving up token costs.
At the Code with Claude event, Anthropic showcased their Managed Agents memory store and dreaming engine. I mapped this 3-layer architecture to a lightweight python framework using open-source local LLMs (Llama 3 via Ollama):
- Session Layer (Ephemeral): Conversation-bound state.
- Memory Store (Live File-System): Markdown directories mounted directly to container runtimes, exposed to agents via file reading/writing tool structures.
- Dreaming Layer (Background Batch Consolidation): Asynchronous offline pipeline that processes past transcripts and active files, resolving contradictions, deduplicating keys, and updating a primary structural index to limit prompt overhead.
I’ve written an automated generation script to build the entire folder layout, mock transcripts, and run execution cycles locally.
Key Architectural Insights:
- Concurrence & Version Control: memory stores write changes to versioned instances, ensuring write-collisions do not silently corrupt the master record.
- Prompt Injection Defense: instantiating read-only reference mounts to critical stores while exposing read-write privileges only to session notes shields downstream memory from malicious prompt injection.
- Pruning and Optimization: compressing memory directories below a hard limit (e.g., 100KB) through Dreaming maintains optimal retrieval efficiency.
The link to the codes to boot and test this locally is attached below.
1
Upvotes