Configure OpenClaw agent memory to survive compaction and session restarts. Use when: (1) setting up a new OpenClaw agent or workspace, (2) agents are forgetting instructions or context between sessions, (3) configuring the pre-compaction memory flush, (4) setting up the file archival pattern for memory/archive/, (5) diagnosing why an agent forgot something, or (6) tuning compaction headroom and context pruning. Covers Layer 1 (gateway compaction config) and Layer 3 (file architecture) of the th
涵盖 OpenClaw 智能体记忆持久性中影响最大的两个层级。
| 层级 | 内容 | 压缩后是否保留? |
|---|---|---|
| 引导文件(SOUL.md、AGENTS.md 等) | 每次会话启动时从磁盘注入 | 是——从磁盘重新加载 |
| 会话记录(磁盘上的 JSONL) |
核心规则: 如果未写入文件,压缩后即不存在。
诊断:忘记偏好? → 故障 A。忘记工具返回了什么? → 故障 C。忘记整个线程? → 故障 B。
通过 gateway config.patch 应用。这是全局默认设置——适用于所有智能体:
json
{
agents: {
defaults: {
compaction: {
mode: safeguard,
reserveTokensFloor: 40000,
memoryFlush: {
enabled: true,
softThresholdTokens: 4000,
systemPrompt: 会话即将压缩。请立即存储持久化记忆。,
prompt: 将任何需要保留的笔记写入 memory/YYYY-MM-DD.md;若无内容需存储,回复 NO_REPLY。
}
},
contextPruning: {
mode: cache-ttl,
ttl: 1h
}
}
}
}
每个值的设置原因请参见 references/config-explained.md。
完整模式请参见 references/file-architecture.md——包括引导文件、每日笔记、归档和 QMD 索引。
添加到每个智能体的 SOUL.md 中。这将为您提供上下文填充和压缩次数的实时可见性——这是在进入不良压缩路径前采取行动的最快方式。
markdown
为何重要以及如何调整阈值,请参见 references/context-footer.md。
在任何 OpenClaw 会话中运行 /context list 可查看:
如果文件显示 TRUNCATED:减小文件大小或在配置中提高 bootstrapMaxChars。
如果文件完全缺失:检查智能体配置中的工作空间路径。
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 openclaw-memory-resilience-1776196495 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 openclaw-memory-resilience-1776196495 技能
skillhub install openclaw-memory-resilience-1776196495
文件大小: 7.37 KB | 发布时间: 2026-4-15 10:25