OpenClaw Memory Upgrade
Turn your OpenClaw agent from a goldfish into an elephant. This skill implements 6 memory upgrades that give your agent persistent, searchable memory across sessions — so it actually remembers who you are, what you're working on, and what happened yesterday.
The Problem
By default, OpenClaw agents wake up blank every session. Conversations are isolated. Context is lost at compaction. Your agent forgets decisions, preferences, and project status the moment the session ends.
What This Fixes
After applying these upgrades, your agent will:
- - Extract and save 8 categories of important information before context is lost
- Search across all past sessions and memory files before answering
- Use hybrid keyword + semantic search with diversity and recency ranking
- Auto-capture and auto-recall memories via the Mem0 plugin
- Maintain curated long-term memory separately from raw daily logs
Prerequisites
- - OpenClaw 2026.2.26 or later
- Access to
openclaw.json config file - npm (for Mem0 plugin installation)
Upgrade 1: Enhanced memoryFlush Prompt
What it does: When a conversation nears compaction (context window filling up), this automatically scans for 8 categories of important information and writes them to daily memory files before context gets trimmed.
Why it matters: Without this, compaction silently discards conversation details. With it, decisions, preferences, technical details, and more survive compaction.
Add to openclaw.json under agents.defaults.compaction:
CODEBLOCK0
Config explained:
- -
mode: "safeguard" — compaction mode that preserves important context - INLINECODE4 — always keep at least 20K tokens available for the agent to work with
- INLINECODE5 — trigger memory flush when only 4K tokens remain before compaction
- INLINECODE6 — injected as a system message to signal urgency
- INLINECODE7 — the actual extraction instructions with 8 categories
Upgrade 2: Session Indexing
What it does: Makes past conversation sessions searchable. Without this, each session is a black box once it ends. With it, the agent can search across old conversations to find things discussed days or weeks ago.
Add to agents.defaults.memorySearch:
CODEBLOCK1
Config explained:
- -
sessionMemory: true — indexes past session transcripts for search - INLINECODE10 — searches both memory files AND past sessions
Upgrade 3: Manual Memory Management
What it does: Establishes a two-tier file-based memory system that the agent reads at the start of every session.
Structure:
CODEBLOCK2
How it works:
- -
MEMORY.md — distilled, organized knowledge. Sections for user profile, projects, decisions, preferences, contacts, workflows. Updated periodically. - INLINECODE12 — raw daily logs. Auto-written by memoryFlush, also written manually by the agent during conversations. One file per day.
Agent instructions (add to AGENTS.md):
CODEBLOCK3
Key principle: Text > Brain. The agent's memory files ARE its continuity. Without them, it wakes up blank.
Upgrade 4: QMD Backend (Hybrid Search)
What it does: Replaces basic memory search with QMD — a hybrid system combining keyword matching (BM25) and semantic understanding (vector embeddings), with diversity ranking and recency bias.
Add to openclaw.json at the top level:
CODEBLOCK4
Also add the query configuration under agents.defaults.memorySearch:
CODEBLOCK5
Config explained:
- -
hybrid search — combines keyword (BM25, weight 0.3) with semantic/vector (weight 0.7) for best of both worlds - INLINECODE16 — ensures search results are diverse, not 8 near-identical matches. Lambda 0.7 balances relevance vs diversity.
- INLINECODE17 — recent memories rank higher than old ones. 30-day half-life means a memory from today scores 2x higher than one from a month ago.
- INLINECODE18 — keeps 90 days of session history searchable
- INLINECODE19 — re-indexes memory files every 5 minutes with 15-second debounce
- INLINECODE20 — caches search results for speed
Upgrade 5: Mem0 Plugin (Auto-Capture & Auto-Recall)
What it does: Adds a separate memory layer that automatically captures important information from conversations and automatically recalls relevant memories before the agent responds.
Install:
CODEBLOCK6
Add to openclaw.json under plugins:
CODEBLOCK7
Config explained:
- -
mode: "open-source" — runs locally, no external API calls - INLINECODE24 — automatically saves important facts from conversations without being told
- INLINECODE25 — automatically searches memory before responding to questions
- INLINECODE26 — builds a knowledge graph of relationships between memories
- INLINECODE27 — returns up to 10 relevant memories per search
- INLINECODE28 — only returns memories above 50% relevance score
Note: Requires the Ollama npm module. If you see errors about missing ollama module, run:
cd ~/.openclaw/extensions/openclaw-mem0 && npm install ollama
Upgrade 6: Cognee (Optional — Requires Docker)
What it does: Graph-based memory system for advanced knowledge representation.
Status: Optional. Requires Docker to be running. Also flagged by OpenClaw security audit for environment variable harvesting patterns in its code. Recommended to skip unless you have Docker running AND have audited the plugin source code.
If you want to install it anyway:
CODEBLOCK9
Recommendation: Skip this one. Upgrades 1-5 provide comprehensive memory coverage. Cognee adds complexity without proportional benefit for most setups.
How It All Fits Together
CODEBLOCK10
Verification
After applying all upgrades, restart the gateway:
CODEBLOCK11
Then verify:
CODEBLOCK12
You should see:
- - Memory: INLINECODE30
- Memory backend: INLINECODE31
- Session indexing: active
Test by telling your agent something specific, ending the session, starting a new one, and asking about it. If the memory system is working, it should find it.
Estimated Token Overhead
The memory system adds minimal overhead:
- - memoryFlush: ~2,000-5,000 tokens per compaction event (only when needed)
- Mem0 auto-recall: ~500-1,000 tokens per query (injected relevant memories)
- QMD search: runs server-side, no token cost
- File reading (MEMORY.md + daily notes): depends on file size, typically 2,000-8,000 tokens at session start
OpenClaw 内存升级
将你的 OpenClaw 智能体从金鱼变成大象。该技能实现了 6 项内存升级,让你的智能体拥有跨会话的持久化、可搜索记忆——这样它就能真正记住你是谁、你在做什么以及昨天发生了什么。
问题
默认情况下,OpenClaw 智能体每次会话开始时都是一片空白。对话是孤立的。上下文在压缩时丢失。你的智能体会在会话结束的瞬间忘记决策、偏好和项目状态。
修复内容
应用这些升级后,你的智能体将能够:
- - 在上下文丢失前提取并保存 8 类重要信息
- 在回答前搜索所有历史会话和记忆文件
- 使用混合关键词 + 语义搜索,并具备多样性和时效性排序
- 通过 Mem0 插件自动捕获和自动回忆记忆
- 将精心维护的长期记忆与原始日常日志分开管理
前置条件
- - OpenClaw 2026.2.26 或更高版本
- 可访问 openclaw.json 配置文件
- npm(用于安装 Mem0 插件)
升级 1:增强版 memoryFlush 提示
功能: 当对话接近压缩(上下文窗口即将填满)时,自动扫描 8 类重要信息,在上下文被裁剪前将其写入日常记忆文件。
重要性: 没有此功能,压缩会静默丢弃对话细节。有了它,决策、偏好、技术细节等都能在压缩后保留。
添加到 openclaw.json 的 agents.defaults.compaction 下:
json
{
compaction: {
mode: safeguard,
reserveTokensFloor: 20000,
memoryFlush: {
enabled: true,
softThresholdTokens: 4000,
systemPrompt: 会话即将压缩。立即分析对话并提取持久化记忆,以免上下文丢失。,
prompt: 扫描当前对话,将以下任何内容写入 memory/YYYY-MM-DD.md(使用今天的日期):\n\n1. 做出的决策(附推理和上下文)\n2. 用户表达的偏好或纠正\n3. 技术细节(命令、配置、API 密钥、端点、文件路径)\n4. 项目状态变更或里程碑\n5. 提到的人员(姓名、角色、联系方式、关系)\n6. 描述的工作流程或过程\n7. 遇到的错误及其解决方案\n8. 用户给出的意见或反馈\n\n对于每项内容,包含时间戳和足够的上下文,以便未来的你能在不查看对话的情况下理解。如果没有有意义的事情发生,回复 NO_REPLY。
}
}
}
配置说明:
- - mode: safeguard — 保留重要上下文的压缩模式
- reserveTokensFloor: 20000 — 始终保留至少 20K 令牌供智能体使用
- softThresholdTokens: 4000 — 当压缩前仅剩 4K 令牌时触发内存刷新
- systemPrompt — 作为系统消息注入以提示紧迫性
- prompt — 包含 8 类内容的实际提取指令
升级 2:会话索引
功能: 使历史对话会话可搜索。没有此功能,每个会话结束后就是一个黑箱。有了它,智能体可以搜索旧对话以查找几天或几周前讨论的内容。
添加到 agents.defaults.memorySearch:
json
{
memorySearch: {
enabled: true,
experimental: {
sessionMemory: true
},
sources: [memory, sessions]
}
}
配置说明:
- - sessionMemory: true — 索引历史会话记录以供搜索
- sources: [memory, sessions] — 同时搜索记忆文件和历史会话
升级 3:手动记忆管理
功能: 建立基于文件的双层记忆系统,智能体在每次会话开始时读取。
结构:
workspace/
MEMORY.md ← 精心维护的长期记忆(智能体的大脑)
memory/
YYYY-MM-DD.md ← 日常日志(每天的原始笔记)
工作原理:
- - MEMORY.md — 提炼、组织化的知识。包含用户资料、项目、决策、偏好、联系人、工作流程等章节。定期更新。
- memory/YYYY-MM-DD.md — 原始日常日志。由 memoryFlush 自动写入,也可由智能体在对话期间手动写入。每天一个文件。
智能体指令(添加到 AGENTS.md):
markdown
每次会话
- 1. 读取 MEMORY.md — 这是你的长期大脑
- 读取 memory/YYYY-MM-DD.md(今天和昨天的)
- 如果发生重要事情,写入今天的日常文件
- 定期审查日常文件,将关键学习提炼到 MEMORY.md
- 永远不要依赖心理笔记——如果重要,就写入文件
关键原则: 文本 > 大脑。智能体的记忆文件就是它的连续性。没有它们,它醒来就是一片空白。
升级 4:QMD 后端(混合搜索)
功能: 用 QMD 替换基础记忆搜索——一个结合关键词匹配(BM25)和语义理解(向量嵌入)的混合系统,具备多样性排序和时效性偏好。
添加到 openclaw.json 的顶层:
json
{
memory: {
backend: qmd,
citations: auto,
qmd: {
includeDefaultMemory: true,
update: {
interval: 5m,
debounceMs: 15000
},
limits: {
maxResults: 8,
timeoutMs: 5000
},
sessions: {
enabled: true,
retentionDays: 90
}
}
}
}
同时在 agents.defaults.memorySearch 下添加查询配置:
json
{
memorySearch: {
query: {
hybrid: {
enabled: true,
vectorWeight: 0.7,
textWeight: 0.3,
candidateMultiplier: 4,
mmr: {
enabled: true,
lambda: 0.7
},
temporalDecay: {
enabled: true,
halfLifeDays: 30
}
}
},
cache: {
enabled: true,
maxEntries: 50000
}
}
}
配置说明:
- - hybrid search — 结合关键词(BM25,权重 0.3)和语义/向量(权重 0.7),兼具两者优势
- MMR(最大边际相关性) — 确保搜索结果多样化,而非 8 个近乎相同的匹配。Lambda 0.7 平衡相关性与多样性。
- temporalDecay — 近期记忆比旧记忆排名更高。30 天半衰期意味着今天的记忆得分是一个月前的 2 倍。
- retentionDays: 90 — 保留 90 天的会话历史可供搜索
- update interval: 5m — 每 5 分钟重新索引记忆文件,带 15 秒防抖
- cache: 50000 entries — 缓存搜索结果以提高速度
升级 5:Mem0 插件(自动捕获与自动回忆)
功能: 添加一个独立的记忆层,自动从对话中捕获重要信息,并在智能体响应前自动回忆相关记忆。
安装:
bash
openclaw plugin install @mem0/openclaw-mem0
添加到 openclaw.json 的 plugins 下:
json
{
plugins: {
slots: {
memory: openclaw-mem0
},
entries: {
openclaw-mem0: {
enabled: true,
config: {
mode: open-source,
autoCapture: true,
autoRecall: true,
enableGraph: true,
topK: 10,
searchThreshold: 0.5
}
}
}
}
}
配置说明:
- - mode: open-source — 本地运行,无需外部 API 调用
- autoCapture: true — 自动保存对话中的重要事实,无需告知
- autoRecall: true — 在回答问题前自动搜索记忆
- enableGraph: true — 构建记忆之间关系的知识图谱
- topK: 10 — 每次搜索返回最多 10 条相关记忆
- searchThreshold: 0.5 — 仅返回相关性得分超过 50% 的记忆
注意: 需要 Ollama npm 模块。如果看到关于缺少 ollama