feat(memory): add Deep Dream module for daily memory distillation

- Add Deep Dream: nightly distill daily memories → refined MEMORY.md + dream diary
- Simplify flush prompt to daily-only, defer MEMORY.md maintenance to Deep Dream
- Remove dead code (_append_to_main_memory) and fix fallback summary logic
- Add shrinkage protection and input dedup for dream process
- Ensure flush threads complete before dream starts
- Update docs (zh/en/ja) with dream diary and distillation mechanism
This commit is contained in:
zhayujie
2026-04-13 21:32:52 +08:00
parent 7bc88c17e4
commit ea1a0c8b3d
5 changed files with 320 additions and 113 deletions

View File

@@ -15,12 +15,17 @@ description: CowAgent 的长期记忆系统 — 文件持久化、自动写入
存储在 `~/cow/memory/` 目录下,按日期命名(如 `2026-03-08.md`),记录每天的对话摘要和关键事件。仅在首次写入时创建,避免生成空文件。
### 梦境日记memory/dreams/YYYY-MM-DD.md
Deep Dream记忆蒸馏过程的副产物记录每次整理的发现、去重合并操作和新洞察。存储在 `~/cow/memory/dreams/` 目录下,按日期命名。
## 自动写入
Agent 通过以下机制自动将对话内容持久化为长期记忆:
- **上下文裁剪时** — 当对话轮次或 token 超出配置上限时,裁剪最早一半的上下文,使用 LLM 将被裁剪的内容总结为关键信息写入当天记忆文件,并将摘要异步注入到保留的上下文中,帮助模型保持对话连贯性
- **每日定时总结** — 每天 23:55 自动触发一次全量总结,防止低活跃日无记忆留存(内容无变化时自动跳过)
- **Deep Dream记忆蒸馏** — 每日总结完成后自动执行,读取近期日记和当前 MEMORY.md通过 LLM 进行去重、合并、修剪,生成精炼的新版 MEMORY.md 并输出梦境日记
- **API 上下文溢出时** — 当模型 API 返回上下文溢出错误时,紧急保存当前对话摘要
所有记忆写入均在后台异步执行LLM 总结 + 文件写入),不阻塞正常对话回复。
@@ -44,6 +49,7 @@ Agent 会在对话中根据需要自动触发记忆检索,将相关历史信
| `user.md` | 用户身份信息和偏好 |
| `MEMORY.md` | 核心记忆(长期) |
| `memory/YYYY-MM-DD.md` | 日级记忆(按需创建) |
| `memory/dreams/YYYY-MM-DD.md` | 梦境日记Deep Dream 自动生成) |
<Frame>
<img src="https://cdn.link-ai.tech/doc/20260203000455.png" width="800" />