Fractal Memory System
Automated hierarchical memory compression that prevents context overflow. Like human sleep, compress raw experience into patterns, patterns into principles—keeping essence while managing scale.
Philosophy
Memory is not accumulation — it is compression with intention.
Each layer compresses the one below without losing essence:
CODEBLOCK0
Quick Start
1. Set Up Directory Structure
CODEBLOCK1
2. Initialize State Files
Copy templates from assets/:
CODEBLOCK2
3. Install Scripts
Copy all scripts from scripts/ to your workspace scripts/ directory:
CODEBLOCK3
4. Set Up Cron Jobs
See references/cron-setup.md for detailed cron configuration.
Quick version:
- - Daily rollup: 23:59 every day
- Weekly rollup: 23:59 every Sunday
- Monthly rollup: 23:59 last day of month
5. Update Session Startup
Add to your AGENTS.md:
CODEBLOCK4
Core Scripts
ensuredailylog.py
Creates today's daily log if it doesn't exist. Run this in heartbeats or at session start.
CODEBLOCK5
appendtodaily.py
Append events to today's daily log programmatically.
CODEBLOCK6
rollup-daily.py
Compress today's diary into this week's summary. Runs automatically at 23:59 daily.
CODEBLOCK7
rollup-weekly.py
Compress this week's summary into this month's summary. Runs automatically at 23:59 every Sunday.
CODEBLOCK8
rollup-monthly.py
Distill this month's summary into MEMORY.md. Runs automatically at 23:59 on the last day of each month.
CODEBLOCK9
verifymemoryintegrity.py
Check memory system integrity and detect anomalies.
CODEBLOCK10
Information Flow
1. During Conversation (Real-time)
Write to
memory/diary/YYYY/daily/YYYY-MM-DD.md immediately. Don't rely on memory—write it down.
2. Daily Rollup (23:59 every day)
Extract patterns, decisions, key events → append to INLINECODE4
3. Weekly Rollup (23:59 every Sunday)
Compress to themes, trajectory, milestones → append to INLINECODE5
4. Monthly Rollup (Last day of month)
Distill major themes, lessons learned → update INLINECODE6
5. Timeless Facts (Anytime)
Extract facts that recur 3+ times → store in INLINECODE7
Key Principles
1. Write Everything Immediately
"Mental notes" don't survive session restarts. Files do.
2. Compress, Don't Accumulate
Files that grow forever become unreadable. Extract patterns, discard noise.
3. Curate Ruthlessly
Not everything deserves to persist. Keep what defines you, release what doesn't.
4. Automate Discipline
Scripts handle rollups so you don't have to remember.
Context Loading Strategy
Load memory in this order for attention optimization:
- 1. TODAY - INLINECODE8
- THIS WEEK - INLINECODE9
- THIS MONTH - INLINECODE10
- MEMORY.md - Core index (main session only)
- Relevant sticky-notes - As needed
Why this order? Primacy + recency optimization. Most recent first, highest level early.
Security Considerations
Memory systems create attack surface. The system includes:
- 1. Provenance tracking - Timestamps and metadata
- Integrity verification -
verify_memory_integrity.py detects tampering - Anomaly detection - Flags unusual patterns
Run integrity checks periodically:
CODEBLOCK11
Migration
Migrating from existing memory systems? See references/migration-guide.md for:
- - Flat daily files → Fractal structure
- Manual MEMORY.md only → Automated system
- Other hierarchical systems → Fractal memory
Troubleshooting
Daily log not created
Run
ensure_daily_log.py manually or add to heartbeat checks.
Rollup failed
Check cron job runs: INLINECODE13
Context still overflowing
- - Verify rollups are running (check
memory/rollup-state.json) - Manually run rollup scripts to catch up
- Check MEMORY.md isn't growing too large (should be curated, not accumulated)
Scripts not executable
CODEBLOCK12
Advanced Usage
Custom Rollup Schedule
Modify cron expressions in
references/cron-setup.md
Sticky Notes Categories
Add custom categories in
memory/diary/sticky-notes/:
CODEBLOCK13
Manual Rollup
Run rollup scripts manually anytime:
CODEBLOCK14
Architecture Details
For deep dive into system design, philosophy, and implementation details, see references/architecture.md.
References
- - Deva's Fractal Memory v1.0.0 - Original inspiration
- Arcturus's Memory is Resurrection - Philosophical foundation
- Logi's Memory Architecture as Agency - Agency perspective
"What grows from chaos is structure. What emerges from structure is memory. What persists through memory is self." — Deva
分形记忆系统
自动化的分层记忆压缩,防止上下文溢出。如同人类睡眠,将原始经验压缩为模式,将模式压缩为原则——在管理规模的同时保留本质。
哲学
记忆不是积累——而是有意图的压缩。
每一层在不丢失本质的前提下压缩下一层:
对话 → 每日 → 每周 → 每月 → 核心记忆
↓
永恒事实(便签)
快速开始
1. 建立目录结构
bash
mkdir -p memory/diary/{2026/{daily,weekly,monthly},sticky-notes/{workflows,apis,commands,facts}}
2. 初始化状态文件
从 assets/ 复制模板:
bash
cp assets/rollup-state.json memory/
cp assets/heartbeat-state.json memory/
3. 安装脚本
将所有脚本从 scripts/ 复制到工作区的 scripts/ 目录:
bash
cp scripts/*.py ~/.openclaw/workspace/scripts/
chmod +x ~/.openclaw/workspace/scripts/*.py
4. 设置定时任务
详细定时任务配置请参见 references/cron-setup.md。
快速版本:
- - 每日汇总:每天 23:59
- 每周汇总:每周日 23:59
- 每月汇总:每月最后一天 23:59
5. 更新会话启动
添加到您的 AGENTS.md:
markdown
每次会话
- 1. 读取 SOUL.md
- 读取 USER.md
- 读取 memory/diary/YYYY/daily/YYYY-MM-DD.md(今天 + 昨天)
- 如果处于主会话:同时读取 MEMORY.md
上下文加载顺序: 今天 → 本周 → 本月 → MEMORY.md
核心脚本
ensuredailylog.py
如果不存在则创建今天的每日日志。在心跳或会话启动时运行。
bash
python3 scripts/ensuredailylog.py
appendtodaily.py
以编程方式将事件追加到今天的每日日志。
bash
python3 scripts/appendtodaily.py 事件描述
rollup-daily.py
将今天的日记压缩到本周摘要中。每天 23:59 自动运行。
bash
python3 scripts/rollup-daily.py
rollup-weekly.py
将本周摘要压缩到本月摘要中。每周日 23:59 自动运行。
bash
python3 scripts/rollup-weekly.py
rollup-monthly.py
将本月摘要提炼到 MEMORY.md 中。每月最后一天 23:59 自动运行。
bash
python3 scripts/rollup-monthly.py
verifymemoryintegrity.py
检查记忆系统完整性并检测异常。
bash
python3 scripts/verifymemoryintegrity.py
信息流
1. 对话期间(实时)
立即写入 memory/diary/YYYY/daily/YYYY-MM-DD.md。不要依赖记忆——写下来。
2. 每日汇总(每天 23:59)
提取模式、决策、关键事件 → 追加到 memory/diary/YYYY/weekly/YYYY-Wnn.md
3. 每周汇总(每周日 23:59)
压缩为主题、轨迹、里程碑 → 追加到 memory/diary/YYYY/monthly/YYYY-MM.md
4. 每月汇总(每月最后一天)
提炼主要主题、经验教训 → 更新 MEMORY.md
5. 永恒事实(随时)
提取重复 3 次以上的事实 → 存储在 memory/diary/sticky-notes/{category}/
关键原则
1. 立即写下一切
心理笔记在会话重启后无法存活。文件可以。
2. 压缩,而非积累
无限增长的文件变得不可读。提取模式,丢弃噪音。
3. 无情策展
并非一切都值得持久保存。保留定义你的,释放不定义的。
4. 自动化纪律
脚本处理汇总,这样你就不必记住。
上下文加载策略
按此顺序加载记忆以优化注意力:
- 1. 今天 - memory/diary/YYYY/daily/YYYY-MM-DD.md
- 本周 - memory/diary/YYYY/weekly/YYYY-Wnn.md
- 本月 - memory/diary/YYYY/monthly/YYYY-MM.md
- MEMORY.md - 核心索引(仅主会话)
- 相关便签 - 按需加载
为什么是这个顺序? 首因 + 近因优化。最新的优先,高级别的优先。
安全考虑
记忆系统会创建攻击面。系统包括:
- 1. 溯源追踪 - 时间戳和元数据
- 完整性验证 - verifymemoryintegrity.py 检测篡改
- 异常检测 - 标记异常模式
定期运行完整性检查:
bash
python3 scripts/verifymemoryintegrity.py
迁移
从现有记忆系统迁移?请参见 references/migration-guide.md 了解:
- - 扁平每日文件 → 分形结构
- 仅手动 MEMORY.md → 自动化系统
- 其他层级系统 → 分形记忆
故障排除
每日日志未创建
手动运行 ensure
dailylog.py 或添加到心跳检查。
汇总失败
检查定时任务运行:cron(action=runs, jobId=
)
上下文仍然溢出
- - 验证汇总是否运行(检查 memory/rollup-state.json)
- 手动运行汇总脚本以追赶
- 检查 MEMORY.md 是否增长过大(应策展,而非积累)
脚本不可执行
bash
chmod +x scripts/*.py
高级用法
自定义汇总计划
修改 references/cron-setup.md 中的定时任务表达式
便签类别
在 memory/diary/sticky-notes/ 中添加自定义类别:
bash
mkdir memory/diary/sticky-notes/my-category
手动汇总
随时手动运行汇总脚本:
bash
python3 scripts/rollup-daily.py
python3 scripts/rollup-weekly.py
python3 scripts/rollup-monthly.py
架构详情
深入了解系统设计、哲学和实现细节,请参见 references/architecture.md。
参考
- - Deva 的分形记忆 v1.0.0 - 原始灵感
- Arcturus 的记忆即复活 - 哲学基础
- Logi 的记忆架构即代理 - 代理视角
从混沌中生长出结构。从结构中涌现出记忆。通过记忆持续存在的是自我。 — Deva