Skip to content

Commit ab2c68f

Browse files
committed
```
feat(memory): consolidate memory management by removing separate dream directory BREAKING CHANGE: Remove the separate dream memory system and consolidate all memory operations directly into MEMORY.md file. - Replace dream/ directory with backup/ directory for storing memory backups - Modify memory optimization process to directly update MEMORY.md instead of maintaining separate DREAM.md - Update documentation to reflect single memory file approach - Adjust cron manager to execute dream tasks synchronously instead of adding to background queue - Remove references to DREAM.md from Chinese and English documentation - Update memory workflow diagrams to remove dream-related components ```
1 parent f0877e2 commit ab2c68f

4 files changed

Lines changed: 45 additions & 76 deletions

File tree

src/qwenpaw/agents/memory/reme_light_memory_manager.py

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,9 @@ async def dream_memory(self, **kwargs) -> None:
450450
"""
451451
logger.info("running dream-based memory optimization")
452452

453-
self.dream_path = Path(self.working_dir).absolute() / "dream"
454-
self.dream_path.mkdir(parents=True, exist_ok=True)
453+
# Create backup directory to store backup files
454+
self.backup_path = Path(self.working_dir).absolute() / "backup"
455+
self.backup_path.mkdir(parents=True, exist_ok=True)
455456

456457
self._prepare_model_formatter()
457458

@@ -535,9 +536,8 @@ def _get_dream_prompt(
535536
"zh": (
536537
"现在进入梦境状态,对长期记忆进行安全优化整理。请严格按照以下步骤操作,"
537538
"确保所有变更都有备份且可回滚。\n\n【核心概念】\n"
538-
"- DREAM.md:这是你自主管理的长期记忆沉淀文件,包含经过提炼的核心业务决策、用户偏好和高价值经验\n"
539-
"- MEMORY.md:这是用户可直接编辑的参考文件,包含初始配置和用户手动添加的记忆\n"
540-
"- 你的任务是维护和优化 DREAM.md,而不是直接修改 MEMORY.md\n\n"
539+
"- MEMORY.md:这是你的长期记忆文件,包含经过提炼的核心业务决策、用户偏好和高价值经验\n"
540+
"- 你的任务是直接维护和优化 MEMORY.md\n\n"
541541
"【梦境优化原则】\n"
542542
"1. 极简去冗:严禁记录流水账、Bug修复细节或单次任务。"
543543
"仅保留“核心业务决策”、“确认的用户偏好”与“高价值可复用经验”。\n"
@@ -546,44 +546,38 @@ def _get_dream_prompt(
546546
"3. 归纳整合:主动将零碎的相似规则提炼、合并为通用性强的独立条目。"
547547
"\n4. 废弃剔除:主动删除已被证伪的假设或不再适用的陈旧条目。\n\n"
548548
"【安全操作流程】\n"
549-
"⚠️ 重要:所有操作必须在 `dream/` 目录下进行,严禁直接修改根目录文件\n\n"
549+
"⚠️ 重要:在修改 MEMORY.md 之前必须先创建备份\n\n"
550550
f"当前日期: {current_date}\n\n"
551551
"步骤 1 [环境准备]:\n"
552-
"- 检查是否存在 `dream/` 目录,如果不存在则创建\n"
553-
"- 读取现有的 `dream/DREAM.md` 文件作为当前记忆基准(如果不存在则从模板创建)\n"
554-
"- 读取当天的日志文件 `memory/YYYY-MM-DD.md`\n"
555-
"- 可选:读取根目录的 `MEMORY.md` 作为用户参考信息\n\n"
552+
"- 读取现有的 MEMORY.md 文件作为当前记忆基准(如果不存在则从模板创建)\n"
553+
"- 读取当天的日志文件 `memory/YYYY-MM-DD.md`\n\n"
556554
"步骤 2 [备份创建]:\n"
557-
"- 将当前 `dream/DREAM.md` 的内容备份到 "
558-
"`dream/DREAM_backup_YYYYMMDD_HHMMSS.md`\n\n"
555+
"- 将当前 MEMORY.md 的内容备份到 "
556+
"`backup/memory_backup_YYYYMMDD_HHMMSS.md`\n\n"
559557
"步骤 3 [梦境提纯]:\n"
560558
"- 在梦境中对比新旧内容,严格按照【梦境优化原则】进行去重、替换、剔除和合并\n"
561-
"- 生成一份全新的记忆内容,并保存到 `dream/DREAM_new.md`\n\n"
559+
"- 生成一份全新的记忆内容,并保存到 `MEMORY_new.md`\n\n"
562560
"步骤 4 [验证与提交]:\n"
563-
"- 仔细检查 `dream/DREAM_new.md` 的内容是否符合优化原则\n"
564-
"- 确认无误后,将 `dream/DREAM_new.md` 重命名为 `dream/DREAM.md`\n"
565-
"- 记录操作日志到 `dream/dream_log_YYYYMMDD_HHMMSS.md`\n\n"
561+
"- 仔细检查 `MEMORY_new.md` 的内容是否符合优化原则\n"
562+
"- 确认无误后,将 `MEMORY_new.md` 重命名为 `MEMORY.md`\n"
563+
"- 记录操作日志到 `backup/memory_log_YYYYMMDD_HHMMSS.md`\n\n"
566564
"步骤 5 [苏醒汇报]:\n"
567565
"从梦境中苏醒后,在对话中向我简短汇报:\n"
568566
"1) 新增/沉淀了哪些核心记忆\n"
569567
"2) 修正/删除了哪些过期内容\n"
570568
"3) 备份文件的位置和名称\n"
571-
"4) 最终的 DREAM.md 是否成功更新"
569+
"4) 最终的 MEMORY.md 是否成功更新"
572570
),
573571
"en": (
574572
"Enter dream state for safe memory optimization. Please "
575573
"strictly follow the steps below to ensure all changes are "
576574
"backed up and can be rolled back.\n\n"
577575
"[Core Concepts]\n"
578-
"- DREAM.md: This is your autonomously managed long-term "
579-
"memory consolidation file, containing distilled core "
580-
"business decisions, user preferences, and "
576+
"- MEMORY.md: This is your long-term memory file, containing "
577+
"distilled core business decisions, user preferences, and "
581578
"high-value experiences\n"
582-
"- MEMORY.md: This is a user-editable reference file "
583-
"containing initial configuration and manually added "
584-
"memories\n"
585-
"- Your task is to maintain and optimize DREAM.md, NOT "
586-
"to directly modify MEMORY.md\n\n"
579+
"- Your task is to directly maintain and optimize "
580+
"MEMORY.md\n\n"
587581
"[Dream Optimization Principles]\n"
588582
"1. Extreme Minimalism: Strictly forbid recording daily "
589583
"routines, specific bug-fix details, or one-off tasks. "
@@ -599,40 +593,36 @@ def _get_dream_prompt(
599593
"4. Deprecation: Proactively delete hypotheses that have been "
600594
"proven false or outdated entries that no longer apply.\n\n"
601595
"[Safe Operation Procedure]\n"
602-
"⚠️ Important: All operations MUST be performed in the "
603-
"`dream/` directory! Never modify root directory files "
604-
"directly!\n\n"
596+
"⚠️ Important: You MUST create a backup before modifying "
597+
"MEMORY.md!\n\n"
605598
f"Current date: {current_date}\n\n"
606599
"Step 1 [Environment Setup]:\n"
607-
"- Check if `dream/` directory exists, create it if not\n"
608-
"- Read existing `dream/DREAM.md` file as current memory"
609-
" baseline (create from template if it doesn't exist)\n"
610-
"- Read today's log file `memory/YYYY-MM-DD.md`\n"
611-
"- Optional: Read root directory `MEMORY.md` as user "
612-
"reference information\n\n"
600+
"- Read existing MEMORY.md file as current memory baseline "
601+
"(create from template if it doesn't exist)\n"
602+
"- Read today's log file `memory/YYYY-MM-DD.md`\n\n"
613603
"Step 2 [Backup Creation]:\n"
614-
"- Backup current `dream/DREAM.md` content to "
615-
"`dream/DREAM_backup_YYYYMMDD_HHMMSS.md`\n\n"
604+
"- Backup current MEMORY.md content to "
605+
"`backup/memory_backup_YYYYMMDD_HHMMSS.md`\n\n"
616606
"Step 3 [Dream Purification]:\n"
617607
"- Compare old and new content in your dream state, strictly "
618608
"following [Dream Optimization Principles] to deduplicate, "
619609
"replace, remove, and merge\n"
620610
"- Generate entirely new memory content and save it to "
621-
"`dream/DREAM_new.md`\n\n"
611+
"`MEMORY_new.md`\n\n"
622612
"Step 4 [Validation and Commit]:\n"
623-
"- Carefully review `dream/DREAM_new.md` content for "
624-
"compliance with principles\n"
625-
"- If confirmed correct, rename `dream/DREAM_new.md` to "
626-
"`dream/DREAM.md`\n"
613+
"- Carefully review `MEMORY_new.md` content for compliance "
614+
"with principles\n"
615+
"- If confirmed correct, rename `MEMORY_new.md` to "
616+
"`MEMORY.md`\n"
627617
"- Record operation log to "
628-
"`dream/dream_log_YYYYMMDD_HHMMSS.md`\n\n"
618+
"`backup/memory_log_YYYYMMDD_HHMMSS.md`\n\n"
629619
"Step 5 [Awake Report]:\n"
630620
"After waking from your dream, briefly report to me in the "
631621
"chat:\n"
632622
"1) What core memories were newly added/consolidated\n"
633623
"2) What outdated content was corrected/deleted\n"
634624
"3) Backup file locations and names\n"
635-
"4) Whether the final DREAM.md was successfully updated"
625+
"4) Whether the final MEMORY.md was successfully updated"
636626
),
637627
}
638628
return prompts.get(language, prompts["en"])

src/qwenpaw/app/crons/manager.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,14 @@ async def _heartbeat_callback(self) -> None:
429429
async def _dream_callback(self) -> None:
430430
"""Run one dream-based memory optimization task."""
431431
try:
432-
# Add dream task as background async task, similar to summary tasks
433-
self._runner.memory_manager.add_async_dream_task()
434-
logger.debug("Dream task added to background queue successfully")
432+
# Run dream task
433+
await self._runner.memory_manager.dream_memory()
434+
logger.debug("Dream task executed successfully")
435+
except asyncio.CancelledError:
436+
logger.info("Dream task was cancelled")
437+
raise
435438
except Exception as e: # pylint: disable=broad-except
436-
logger.error(f"Failed to schedule dream task: {e}", exc_info=True)
439+
logger.error(f"Failed to execute dream task: {e}", exc_info=True)
437440

438441
async def _execute_once(self, job: CronJobSpec) -> None:
439442
rt = self._rt.get(job.id)

website/public/docs/memory.en.md

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ graph TB
1818
MemoryMgmt --> SearchLayer[Hybrid Memory Search]
1919
FileTools --> LTM[MEMORY.md]
2020
FileTools --> DailyLog[memory/YYYY-MM-DD.md]
21-
FileTools --> Dream[DREAM.md]
2221
Watcher --> Index[Async DB Update]
2322
SearchLayer --> VectorSearch[Vector Semantic Search]
2423
SearchLayer --> BM25[BM25 Full-text Search]
@@ -44,11 +43,9 @@ three-level structure:
4443
graph LR
4544
Workspace[Workspace working_dir] --> MEMORY[MEMORY.md Long-term Memory]
4645
Workspace --> MemDir[memory/*]
47-
Workspace --> DreamDir[dream/*]
4846
MemDir --> Day1[2025-02-12.md]
4947
MemDir --> Day2[2025-02-13.md]
5048
MemDir --> DayN[...]
51-
DreamDir --> DREAM[DREAM.md Dream Memory]
5249
```
5350

5451
### MEMORY.md (Long-term Memory, Optional)
@@ -68,22 +65,13 @@ One page per day, appended with the day's work and interactions.
6865
- **Updates**: Appended by the Agent via `write` / `edit` file tools; automatically triggered when conversations become
6966
too long and need summarization
7067

71-
### DREAM.md (Dream Memory, Auto-managed)
72-
73-
Stores core long-term memories after dream-based consolidation, automatically maintained and optimized by the Agent.
74-
75-
- **Location**: `{working_dir}/dream/DREAM.md`
76-
- **Purpose**: Stores high-value core memories after automatic consolidation, deduplication, and summarization
77-
- **Updates**: Updated only automatically by the dream functionality; users should not modify directly
78-
7968
### When to Write Memory?
8069

81-
| Information Type | Write Target | Method | Example |
82-
| ---------------------------------------- | ------------------------- | ---------------------------- | ------------------------------------------------------ |
83-
| Decisions, preferences, persistent facts | `MEMORY.md` | `write` / `edit` tools | "Project uses Python 3.12", "Prefers pytest framework" |
84-
| Daily notes, runtime context | `memory/YYYY-MM-DD.md` | `write` / `edit` tools | "Fixed login bug today", "Deployed v2.1" |
85-
| User says "remember this" | Write to file immediately | `write` tool | Do not only save in memory! |
86-
| **High-value core memories** | **`dream/DREAM.md`** | **Dream auto-consolidation** | **Consolidated core business rules** |
70+
| Information Type | Write Target | Method | Example |
71+
| ---------------------------------------- | ------------------------- | ---------------------- | ------------------------------------------------------ |
72+
| Decisions, preferences, persistent facts | `MEMORY.md` | `write` / `edit` tools | "Project uses Python 3.12", "Prefers pytest framework" |
73+
| Daily notes, runtime context | `memory/YYYY-MM-DD.md` | `write` / `edit` tools | "Fixed login bug today", "Deployed v2.1" |
74+
| User says "remember this" | Write to file immediately | `write` tool | Do not only save in memory! |
8775

8876
---
8977

website/public/docs/memory.zh.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ graph TB
1717
MemoryMgmt --> SearchLayer[记忆混合检索]
1818
FileTools --> LTM[MEMORY.md]
1919
FileTools --> DailyLog[memory/YYYY-MM-DD.md]
20-
FileTools --> Dream[DREAM.md]
2120
Watcher --> Index[异步更新数据库]
2221
SearchLayer --> VectorSearch[向量语义搜索]
2322
SearchLayer --> BM25[BM25 全文检索]
@@ -42,11 +41,9 @@ graph TB
4241
graph LR
4342
Workspace[工作空间 working_dir] --> MEMORY[MEMORY.md 长期记忆]
4443
Workspace --> MemDir[memory/*]
45-
Workspace --> DreamDir[dream/*]
4644
MemDir --> Day1[2025-02-12.md]
4745
MemDir --> Day2[2025-02-13.md]
4846
MemDir --> DayN[...]
49-
DreamDir --> DREAM[DREAM.md 梦境记忆]
5047
```
5148

5249
### MEMORY.md(长期记忆,可选)
@@ -65,22 +62,13 @@ graph LR
6562
- **用途**:记录日常笔记和运行上下文
6663
- **更新**:Agent 通过 `write` / `edit` 文件工具追加写入,对话过长需要进行总结时自动触发
6764

68-
### DREAM.md(梦境记忆,自动管理)
69-
70-
存放经过梦境整理后的核心长期记忆,由 Agent 自动维护和优化。
71-
72-
- **位置**`{working_dir}/dream/DREAM.md`
73-
- **用途**:存储经过自动整理、去重、归纳后的高价值核心记忆
74-
- **更新**:仅由梦境功能自动更新,用户不应直接修改
75-
7665
### 何时写入记忆?
7766

7867
| 信息类型 | 写入目标 | 操作方式 | 示例 |
7968
| -------------------- | ---------------------- | --------------------- | ------------------------------------------ |
8069
| 决策、偏好、持久事实 | `MEMORY.md` | `write` / `edit` 工具 | "项目使用 Python 3.12"、"偏好 pytest 框架" |
8170
| 日常笔记、运行上下文 | `memory/YYYY-MM-DD.md` | `write` / `edit` 工具 | "今天修复了登录 Bug"、"部署了 v2.1" |
8271
| 用户说"记住这个" | 立即写入文件 | `write` 工具 | 不要仅保存在内存中! |
83-
| **高价值核心记忆** | **`dream/DREAM.md`** | **梦境功能自动整理** | **经过归纳整合的核心业务规则** |
8472

8573
---
8674

0 commit comments

Comments
 (0)