Files
16gagent/patterns/memory-system-architecture.md
2026-06-06 10:40:48 +08:00

95 lines
3.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 记忆系统架构模式
> 从小龙记忆系统演化中提取的可复用设计模式。
> 适用于需要长期维护知识库的 AI Agent 系统。
## Pattern 1: 三层写入架构
```
daily/ (raw) → Write Gate → registers/ (current state) + vault.md (timeline)
↘ SESSION_START.md (context load)
```
**来源**: total-recall 的 Write Gate + auto-dream 的分层结构
**适用范围**: 任何需要区分"原始日志"和"持久化事实"的 Agent 系统
**关键**:
- daily/ 无门槛写入(避免决策疲劳)
- Write Gate 仅 3 种条件触发寄存器写入
- SESSION_START.md 定义会话加载协议
## Pattern 2: Write Gate 三条件
只有满足任一条件才写入持久层:
1. ✅ 会影响未来对话行为(偏好、决策、规则)
2. ✅ 用户明确要求记住
3. ✅ 有"不记录就会重复犯错"的风险
**反模式**: 所有信息都提升到 registers → 噪音淹没信号
**反模式**: 什么都不提升 → 记忆系统形同虚设
## Pattern 3: 决策时间线 vs 当前状态分离
```
vault.md → 决策时间线 (WHEN)
registers/ → 当前配置/状态 (WHAT)
```
**关键**: 两者不互斥,互补。去重不是"删掉一个",而是确保它们记录不同维度。
- vault: "2026-06-02: 部署了远程记忆服务器"
- tool-env: "远程记忆服务器: 111.229.145.18, 当前在线, 21条记忆"
## Pattern 4: 缓存边界意识
```
MEMORY.md → 缓存线以上 → 尽量不动
vault.md → 缓存线以下 → 随便改
daily/ → 缓存线以下 → 高频写入
```
**关键**: 修改缓存线上文件 = DeepSeek KV Cache 全量重写 = 成本翻倍。
## Pattern 5: 演化目录体系
```
reflections/ → 任务后反思 (WHAT happened, WHAT learned)
patterns/ → 可复用设计模式 (HOW to do it)
playbooks/ → 操作手册 (STEP BY STEP)
skills/ → 能力定义 (WHAT I can do)
```
**关键**: 每次任务完成后至少产出 1 个 reflection,模式重复出现 2 次以上提取到 patterns/。
## Pattern 6: 三时区 cron 覆盖
```
04:00 — Dream Cycle (记忆 consolidation + 索引 + git push)
23:00 — Git Auto-Commit (每日备份)
每2h — Remote Health Monitor (服务器存活)
```
**关键**:
- 凌晨 consolidation(避开使用高峰)
- 深夜备份(一天结束)
- 高频监控(但沉默模式,只告警不出声)
## Pattern 7: [session-flush] 标记协议
```
[session-flush] 20:17 — 记忆搜索修复 + 4个GitHub项目同步完成
```
**用途**: Dream Cycle 的 Collect 阶段扫描此标记,提取上下文摘要推送到远程服务器。
**写入时机**:
- 每次会话结束
- 上下文压缩前(pre-compaction hook
- 重要里程碑达成时
## Pattern 8: 文件拆分阈值
| 指标 | 阈值 | 动作 |
|------|------|------|
| vault.md 行数 | > 200 | 拆分到 registers/ |
| MEMORY.md 字节 | > 10000 | 精简/归档 |
| daily/ 空缺 | > 1 天 | 紧急补写 |
| registers/ 文件数 | > 10 | 子目录分组 |