Skip to content

Commit 68c30b2

Browse files
committed
Add AutoDream durable memory to builtin _memory plugin
Implement AutoDream in the builtin `_memory` plugin as a background durable-memory pass that runs after top-level chats, inspired by https://github.com/dp-web4/snarc. It gathers recent saved sessions from `usr/chats`, recent non-knowledge vector memories, semantically related older vector memories, and existing durable memory files, then uses the utility model to consolidate, update, or prune durable markdown memories. The feature writes scoped durable notes under the AutoDream folder, regenerates a compact Claude-compatible `MEMORY.md` index, records a lightweight `.dream-log.md` changelog, and reloads durable memories back into vector recall. It also adds soft memory-scope and rename/orphan hints, improves AutoDream file import so frontmatter metadata is preserved without embedding raw YAML headers, and clears the relevant import cache so updated durable memories are reindexed correctly. This also wires AutoDream into preload/import paths, adds the background trigger extension and prompt contract, exposes settings in the Memory UI, adds default config values, updates documentation. AutoDream remains off by default and can be enabled in Memory settings.
1 parent b391d98 commit 68c30b2

12 files changed

Lines changed: 1817 additions & 13 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ docker run -p 50001:80 agent0ai/agent-zero
7373

7474
- Agent Zero is not pre-programmed for specific tasks (but can be). It is meant to be a general-purpose personal assistant. Give it a task, and it will gather information, execute commands and code, cooperate with other agent instances, and do its best to accomplish it.
7575
- It has a persistent memory, allowing it to memorize previous solutions, code, facts, instructions, etc., to solve tasks faster and more reliably in the future.
76+
- Its AutoDream layer also maintains a Claude Code-style `MEMORY.md` index for each memory scope or project, backed by durable markdown memories and synchronized with the vector database so symbolic navigation and semantic recall stay aligned.
7677

7778
![Agent 0 Working](/docs/res/ui_screen2.png)
7879

plugins/_memory/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@ This plugin stores memories and knowledge embeddings in a FAISS-backed vector da
1919
- Exposes search, delete, bulk delete, update, and subdirectory listing endpoints for the memory dashboard.
2020
- **Scoped storage**
2121
- Supports different memory subdirectories so memory can be separated by context or agent scope.
22+
- **AutoDream durable memory**
23+
- Periodically performs a reflective background pass over recent sessions and recent memory fragments.
24+
- Maintains a compact `MEMORY.md` index plus durable markdown memory files under each memory subdirectory.
25+
- Feeds the dream with both fresh vector memories and semantically related older vector memories so consolidation has better historical context.
26+
- Writes a lightweight `.dream-log.md` changelog for fast auditing of what each run created, updated, pruned, or flagged.
27+
- Re-imports durable memory files into vector memory with frontmatter metadata preserved, so recall benefits from the consolidated output without embedding raw YAML headers.
28+
29+
## Claude Code `MEMORY.md` Integration
30+
31+
Agent Zero's AutoDream intentionally follows the same broad pattern as Claude Code's `MEMORY.md`, but it does so per memory scope instead of assuming one global file.
32+
33+
- **Scoped index, not a dump**
34+
- Each memory scope gets its own `autodream/MEMORY.md`.
35+
- That file is a compact index of durable memories, not the memories themselves.
36+
- **Durable files hold the actual content**
37+
- The detailed memories live in `autodream/memories/*.md`.
38+
- `MEMORY.md` links to those files with one-line descriptions.
39+
- **Vector DB stays in sync**
40+
- Those durable markdown files are re-imported into the FAISS-backed vector store.
41+
- This means Agent Zero's semantic recall and the Claude-style `MEMORY.md` index are two synchronized views over the same durable memory set.
42+
- **Compatibility model**
43+
- If you already use Claude Code, the generated `MEMORY.md` should feel familiar.
44+
- The main difference is placement: Agent Zero manages `MEMORY.md` inside each memory scope or project metadata folder rather than at a single repository root.
45+
- If another tool expects a root-level `MEMORY.md`, you can mirror or sync the generated index there, but Agent Zero's native source of truth remains the scoped AutoDream folder.
2246

2347
## Key Files
2448

@@ -28,6 +52,8 @@ This plugin stores memories and knowledge embeddings in a FAISS-backed vector da
2852
- `helpers/knowledge_import.py` imports external knowledge into memory storage.
2953
- **Consolidation**
3054
- `helpers/memory_consolidation.py` contains memory consolidation logic.
55+
- **AutoDream**
56+
- `helpers/auto_dream.py` contains session gathering, durable file generation, and background scheduling logic.
3157
- **Tools**
3258
- `tools/memory_save.py`
3359
- `tools/memory_load.py`
@@ -37,6 +63,8 @@ This plugin stores memories and knowledge embeddings in a FAISS-backed vector da
3763
- **API**
3864
- `api/memory_dashboard.py` powers the memory management dashboard.
3965
- `api/import_knowledge.py` and `api/knowledge_reindex.py` handle knowledge import and reindexing.
66+
- **Lifecycle**
67+
- `extensions/python/process_chain_end/_60_auto_dream.py` schedules periodic AutoDream runs after top-level chats complete.
4068

4169
## Configuration Scope
4270

plugins/_memory/default_config.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ memory_recall_post_filter: false
1313
memory_memorize_enabled: true
1414
memory_memorize_consolidation: true
1515
memory_memorize_replace_threshold: 0.9
16-
agent_memory_subdir: default
16+
memory_auto_dream_enabled: false
17+
memory_auto_dream_min_hours: 8
18+
memory_auto_dream_min_sessions: 3
19+
memory_auto_dream_line_limit: 120
20+
agent_memory_subdir: default
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from agent import AgentContextType
2+
from helpers import persist_chat, plugins
3+
from helpers.extension import Extension
4+
5+
from plugins._memory.helpers.auto_dream import schedule_auto_dream
6+
from plugins._memory.helpers.memory import get_agent_memory_subdir
7+
8+
9+
class AutoDream(Extension):
10+
11+
async def execute(self, **kwargs):
12+
if not self.agent:
13+
return
14+
if self.agent.number != 0:
15+
return
16+
if self.agent.context.type == AgentContextType.BACKGROUND:
17+
return
18+
19+
config = plugins.get_plugin_config("_memory", self.agent) or {}
20+
if not config.get("memory_memorize_enabled"):
21+
return
22+
if not config.get("memory_auto_dream_enabled"):
23+
return
24+
25+
if self.agent.config.profile:
26+
self.agent.context.set_data("agent_profile", self.agent.config.profile)
27+
28+
persist_chat.save_tmp_chat(self.agent.context)
29+
30+
schedule_auto_dream(
31+
context_id=self.agent.context.id,
32+
project_name=self.agent.context.get_data("project"),
33+
agent_profile=self.agent.config.profile,
34+
memory_subdir=get_agent_memory_subdir(self.agent),
35+
)

0 commit comments

Comments
 (0)