真诚友善团结专业,共建你我引以为荣之社区。《常见问题解答》
1 / 44
2月 17 日

由 radishzz 发布于 4 天前

wave

我们已经有一段时间没有看到 radishzz 了 — 他/她上次发帖是 6 个月前。

春晚太难看了,我一边看春晚,一边和 antigravity、cursor 合作,花了四五个小时,设计出了这一套 OpenClaw 终极记忆系统。看着还不错,分享给大家,帮助大家解决 OpenClaw 的失忆问题,也顺便祝大家新年快乐!:red_envelope::red_envelope::red_envelope:

方案介绍

参考了哪些方案?

在设计这套记忆系统之前,我们调研了以下方案:

方案 来源 类型
calicastle 三层架构 X ( @calicastle ) 社区方案
openclaw-memory GitHub ( geq1fan ) 官方 Skill
openclaw-engram GitHub 社区插件
Supermemory / Mem0 官方插件 云服务方案

1.2 各方案的优缺点

方案 优点 缺点
calicastle 架构清晰,三层设计简单易懂 无去重机制,仅每天捕获一次,无验证逻辑
openclaw-memory 支持自动验证(过时/重复/冲突检测) 两个独立 Job 较复杂,Python 依赖
engram 功能最全(10种记忆分类、信心分数、实体档案) 复杂度高,需要 API Key
Supermemory / Mem0 零配置,即装即用 云端依赖,需要付费

1.3 我们的方案特点

经过三轮对比分析,我们设计出这套「终极记忆系统」:

核心优势:

特点 说明
:white_check_mark: 幂等性保护 Session ID 去重,避免重复记录
:white_check_mark: 硬性限制 MEMORY.md 上限 80 行 / 5KB,防止膨胀
:white_check_mark: 信号过滤 跳过不足 2 条消息的会话,减少噪音
:white_check_mark: 四维验证 进入长期记忆需满足四个条件
:white_check_mark: 自动备份 修改前自动备份,安全性
:white_check_mark: 精简架构 仅 2 个 Cron Job,易于维护

2. 如何配置

2.1 前置要求

  • OpenClaw 已安装并运行
  • 已配置 qmd 作为记忆后端
  • 工作目录 ~/.openclaw/workspace/

2.2 配置步骤

步骤 1:创建目录结构

mkdir -p ~/.openclaw/workspace/memory/weekly mkdir -p ~/.openclaw/workspace/memory/archive

步骤 2:创建 MEMORY.md 模板

# Long-Term Memory > Only write info here that you'd make mistakes without. Event logs stay in daily files. > Hard limit: 80 lines / 5KB. Must compress before adding when over limit. ## User Preferences ## Active Projects ## Key Decisions ## Important Contacts

步骤 3:更新 AGENTS.md

## Memory 部分添加:

### 🔍 Memory Retrieval (MANDATORY) When you need to recall past events, **search first — never read all files**: 1. `qmd query "<question>"` — hybrid search with reranking 2. `qmd get <file>:<line> -l 20` — pull only the snippet you need 3. Only fall back to reading files directly if qmd returns nothing ### ✍️ Memory Writing - Don't Wait for Cron When you make a decision, the user says "I prefer X", or a key task completes → **immediately append to `memory/YYYY-MM-DD.md`**. Cron captures sessions automatically every few hours, but it's just the safety net. Write it down in the moment.

步骤 4:添加 Cron Job

Job 1: memory-sync(记忆同步)

openclaw cron add \ --name "memory-sync" \ --cron "0 10,14,18,22 * * *" \ --tz "Asia/Shanghai" \ --session isolated \ --wake now \ --delivery none \ --message "MEMORY SYNC — You are the memory capture agent. Run silently, no notifications. 1. Use sessions_list to get sessions with activity in the last 4 hours 2. Skip isolated sessions 3. For each session, use sessions_history to read conversation content 4. Skip sessions with user_message_count < 2 5. If no valid sessions remain, do nothing — reply ANNOUNCE_SKIP and stop here. 6. Read today's memory/YYYY-MM-DD.md (create if it doesn't exist) 7. Idempotency check: if a session_id's first 8 characters already appear in the file, skip that session 8. For unrecorded sessions, extract: user's key requests, assistant's conclusions/decisions, important action results. Compress each session to 3-10 summary items. 9. Append to the daily file in this format: ## HH:MM session:FIRST8 | N messages 10. Run qmd update && qmd embed 11. Reply ANNOUNCE_SKIP when done."

Job 2: memory-tidy(记忆整理)

openclaw cron add \ --name "memory-tidy" \ --cron "0 3 * * *" \ --tz "Asia/Shanghai" \ --session isolated \ --wake now \ --deliver \ --message "MEMORY TIDY — You are the memory maintenance agent. You are explicitly authorized to read and modify MEMORY.md in this isolated session. [Phase 1: Compress] 1. List all date-named files (YYYY-MM-DD.md) in memory/ 2. Identify files older than 7 days. If none, skip this phase. 3. Group by natural week, generate memory/weekly/YYYY-MM-DD.md (named after Monday) 4. Extract [Decisions] [Discoveries] [Preferences] [Tasks], tag each with (src: YYYY-MM-DD) 5. Idempotent: if ### YYYY-MM-DD section already exists in weekly file, skip it [Phase 2: Distill] 6. Read daily files from the last 7 days + current MEMORY.md 7. Identify info worth keeping long-term. All four criteria must be met: (a) agent would make a concrete mistake without it (b) applies to many future conversations (c) self-contained and understandable (d) not duplicated in existing MEMORY.md 8. Reverse check: before writing, ask yourself — what specific error would occur without this? If you can't answer, don't write it. 9. Backup: mkdir -p memory/archive && cp MEMORY.md memory/archive/MEMORY.md.bak-\$(date +%F) 10. Update MEMORY.md. Hard limit: 80 lines. If over, compress/merge existing entries first. [Phase 3: Archive] 11. Move daily files that have been compressed into weekly summaries to memory/archive/YYYY/ [Wrap-up] 12. Run qmd update && qmd embed 13. If changes were made, send a brief summary. If no changes: reply 🧠 memory-tidy done, no changes."

2.3 文件结构

~/.openclaw/workspace/ ├── MEMORY.md # 长期记忆(80 行上限) ├── AGENTS.md # 已更新记忆规则 └── memory/ ├── YYYY-MM-DD.md # 每日日志 ├── weekly/ # 周度压缩摘要 └── archive/ # 归档旧日志

3. 工作流程

┌─────────────────────────────────────┐ memory-sync (10/14/18/22) 扫描过去 4 小时的会话 跳过 <2 条消息的会话 Session ID 去重 写入 memory/YYYY-MM-DD.md qmd update && qmd embed └─────────────────────────────────────┘ ┌─────────────────────────────────────┐ memory-tidy (每日 3 AM) Phase 1: 压缩 周度摘要 Phase 2: 蒸馏 更新 MEMORY.md Phase 3: 归档 移动旧文件 qmd update && qmd embed └─────────────────────────────────────┘

4. 验证

配置完成后:

  1. 运行 openclaw cron list 确认 Job 已注册
  2. 发起几轮对话,等待下一个 sync 窗口(10/14/18/22 点)
  3. 检查 memory/2026-02-16.md 是否生成
  4. 测试 qmd query "关键词" 搜索功能
  5. 一周后检查 memory/weekly/ 是否有压缩摘要
阅读时间 4 分钟

由 handsome 发布于 4 天前

由 CaptainVIX 发布于 4 天前

由 JIA_GUO 发布于 4 天前

由 Arturia169 发布于 4 天前

由 dakkk 发布于 4 天前

由 xiongjy 发布于 4 天前

由 linyz 发布于 4 天前

由 Jili 发布于 4 天前

由 Pandasama 发布于 4 天前

我敲,还能这样,马上学习。话说大佬们现在都用的啥模型,那个免费的opus没了现在不知道换啥了

由 fc5f42aa269c5ee3 发布于 4 天前

由 user21 发布于 4 天前

由 anchogin 发布于 4 天前

由 jolyne_kojo 发布于 4 天前

由 edom 发布于 4 天前

sessions_list 只列活跃的 session,只回扫 session 历史的话,感觉容易丢失 /new 之前的记忆诶

由 radishzz 发布于 4 天前

好像是的,我也还在测试。目前只能说是发出来存个档,顺便分享一下方案思路,还有不少地方可以完善

由 PositionZero 发布于 4 天前

没关注过这方面,不过 OpenClaw 内置的 memory 有什么缺点吗 :thinking:

查了下这些方案的关注度好像都不高的样子 :distorted_face:

由 dupaddy 发布于 4 天前

由 joegodwanggod 发布于 4 天前

由 Leonui 发布于 4 天前

上次访问

由 radishzz 发布于 4 天前

缺点就是,跟它讲了半天话,上下文满了触发 Compaction,或者换个模型,就啥都不记得了。打开 memory 文件一看,啥都没记,就很痛苦。

我也是搜了很久,确实是没有一个比较热门+简单的解决方案,所以只能手搓了,让 AI 一起来研究总结,目标是出一个靠谱+简约的方案

由 Adamllll 发布于 4 天前

由 layingfish 发布于 4 天前

由 hamood 发布于 4 天前

由 arkk 发布于 4 天前

由 user792 发布于 4 天前

由 willion 发布于 4 天前

由 continueC 发布于 3 天前

由 alex3 发布于 3 天前

由 Jack_anpunpf 发布于 3 天前

由 270110923 发布于 3 天前

由 One_Five_Three 发布于 3 天前

由 crazypeace 发布于 3 天前

由 user1587 发布于 3 天前

由 tienchiu 发布于 2 天前

由 Deadlock 发布于 2 天前

由 lalalalalacp 发布于 2 天前

由 Pandasama 发布于 2 天前

由 Deadlock 发布于 2 天前

由 Pandasama 发布于 2 天前

加载下方更多的帖子