Agent WAL (Write-Ahead Log)
Write important state to disk before responding. Prevents the #1 agent failure mode: losing corrections and context during compaction.
Core Rule
Write before you respond. If something is worth remembering, WAL it first.
When to WAL
| Trigger | Action Type | Example |
|---|
| User corrects you | INLINECODE0 | "No, use Podman not Docker" |
| You make a key decision |
decision | "Using CogVideoX-2B for text-to-video" |
| Important analysis/conclusion |
analysis | "WAL/VFM patterns should be core infra not skills" |
| State change |
state_change | "GPU server SSH key auth configured" |
| User says "remember this" |
correction | Whatever they said |
Commands
All commands via scripts/wal.py (relative to this skill directory):
CODEBLOCK0
Integration Points
On Session Start
- 1. Run
replay to get unapplied entries - Read the summary into your context
- Mark entries as applied after incorporating them
On User Correction
- 1. Run
append with action_type correction BEFORE responding - Then respond with the corrected behavior
On Pre-Compaction Flush
- 1. Run
flush-buffer to persist any buffered entries - Then write to daily memory files as usual
During Conversation
For less critical items, use
buffer-add to batch writes. Buffer is flushed to WAL on
flush-buffer (called during pre-compaction) or manually.
Storage
WAL files: ~/clawd/memory/wal/<agent_id>.wal.jsonl
Buffer files: INLINECODE13
Entries are append-only JSONL. Each entry:
CODEBLOCK1
Agent WAL(预写日志)
在响应之前将重要状态写入磁盘。防止排名第一的智能体故障模式:在压缩过程中丢失修正和上下文。
核心规则
在响应之前写入。 如果某件事值得记住,先写入WAL。
何时使用WAL
| 触发条件 | 操作类型 | 示例 |
|---|
| 用户纠正你 | correction | 不,使用Podman而非Docker |
| 你做出关键决策 |
decision | 使用CogVideoX-2B进行文生视频 |
| 重要分析/结论 | analysis | WAL/VFM模式应为核心基础设施而非技能 |
| 状态变更 | state_change | GPU服务器SSH密钥认证已配置 |
| 用户说记住这个 | correction | 他们所说的任何内容 |
命令
所有命令通过 scripts/wal.py(相对于此技能目录):
bash
在响应之前写入
python3 scripts/wal.py append agent1 correction 所有EvoClaw工具使用Podman而非Docker
python3 scripts/wal.py append agent1 decision 通过accelerate使用多GPU的CogVideoX-5B
python3 scripts/wal.py append agent1 analysis 签名约束防止基因组篡改
工作缓冲区(对话期间批量写入,压缩前刷新)
python3 scripts/wal.py buffer-add agent1 decision 某个决策
python3 scripts/wal.py flush-buffer agent1
会话开始:重放丢失的上下文
python3 scripts/wal.py replay agent1
应用重放条目后
python3 scripts/wal.py mark-applied agent1 <条目ID>
维护
python3 scripts/wal.py status agent1
python3 scripts/wal.py prune agent1 --keep 50
集成点
会话开始时
- 1. 运行 replay 获取未应用的条目
- 将摘要读入你的上下文
- 在整合条目后标记为已应用
用户纠正时
- 1. 在响应之前使用 action_type 为 correction 运行 append
- 然后以修正后的行为进行响应
压缩前刷新时
- 1. 运行 flush-buffer 持久化任何缓冲的条目
- 然后像往常一样写入每日记忆文件
对话期间
对于不太重要的内容,使用 buffer-add 进行批量写入。缓冲区在 flush-buffer(在压缩前调用)或手动操作时刷新到WAL。
存储
WAL文件:~/clawd/memory/wal/.wal.jsonl
缓冲区文件:~/clawd/memory/wal/.buffer.jsonl
条目是追加写入的JSONL格式。每个条目:
json
{id: abc123, timestamp: ISO8601, agentid: agent1, actiontype: correction, payload: 使用Podman而非Docker, applied: false}