memory-manager
Upgrade your agent's memory from basic notes to a 3-layer production system with nightly consolidation. Based on patterns from running 7 AI bots in production for 30+ days.
Overview
Every AI agent has the same problem: it wakes up fresh every session with no memory of what happened before. The naive fix is a single MEMORY.md file — but that doesn't scale. After a few weeks, it's either a wall of text the agent ignores, or so curated it's missing operational context.
This skill installs a 3-layer memory architecture that mirrors how humans actually store knowledge:
| Layer | File | What goes here |
|---|
| 1 — Long-term | INLINECODE1 | Curated wisdom, architecture decisions, hard-won lessons |
| 2 — Operational |
memory/YYYY-MM-DD.md | What happened today, active project state, raw context |
| 3 — Tacit |
USER.md | How your human works, preferences, frustrations, patterns |
Plus a nightly consolidation cron that reviews recent sessions and promotes important context up the layers automatically.
When to Use This Skill
Activate this skill when the user asks you to:
- - Set up memory for their agent
- Upgrade from a basic
MEMORY.md system - Add nightly consolidation or memory cron
- Improve agent continuity between sessions
- Track active projects across agent restarts
- Set up the memory-manager skill
Setup Instructions
Step 1: Run the Setup Script
CODEBLOCK0
This creates the memory/ directory, copies templates into place, and prints next steps.
Step 2: Customize the Templates
After setup, edit these files in your agent's workspace:
- 1.
MEMORY.md — Add your agent's existing long-term context USER.md — Fill in who the human is, how they work, what frustrates themAGENTS.md — Review the startup sequence (already wired for 3-layer loading)HEARTBEAT.md — Configure which projects to monitor
Step 3: Configure the Startup Sequence
Your agent's AGENTS.md must include this memory loading sequence at the top of "Every Session":
CODEBLOCK1
Why read yesterday too? Sessions started after midnight won't have today's file yet. Yesterday bridges the gap. This prevented context loss in our production fleet during late-night sessions.
Step 4: Set Up Nightly Consolidation
Add a cron job to consolidate memory each night at 2 AM:
CODEBLOCK2
The consolidation prompt to configure in OpenClaw cron:
CODEBLOCK3
Why 2 AM? Low activity period. The consolidation model has full context of the day's events. Running nightly (not weekly) means no single consolidation is overwhelming.
Memory Loading Rules
In Main Session (direct human chat)
Load all three layers:
CODEBLOCK4
In Group Chats / Shared Channels
Load only layers 2 and 3 (no MEMORY.md):
CODEBLOCK5
Why skip MEMORY.md in group chats? Long-term memory often contains personal context — private preferences, health info, financial details — that shouldn't leak into conversations with strangers. Daily operational notes are usually safe.
In Subagent / Worker Sessions
Load only today's notes:
CODEBLOCK6
Subagents are ephemeral. Don't load full memory — it wastes tokens and context.
Daily Notes Format
Each memory/YYYY-MM-DD.md file follows this structure:
CODEBLOCK7
The "Context for Next Session" section is the most important. Agents often end sessions mid-task. Without this section, the next session has to reconstruct state from scratch. Write it as if briefing a colleague who just joined the project.
Active Project Tracking
Projects move through these states in daily notes:
CODEBLOCK8
The heartbeat integration (see HEARTBEAT.md) checks active projects and surfaces blockers automatically.
MEMORY.md Curation Rules
Long-term memory should be:
- - Curated, not comprehensive — the distilled essence, not raw logs
- Actionable — things that change future decisions
- Evergreen — not "what I did Tuesday" but "lesson learned from the Tuesday incident"
- Organized by topic — architecture, lessons, human preferences, recurring patterns
Things that belong in MEMORY.md:
- - Architecture decisions and the reasoning behind them
- Lessons learned from failures
- Patterns in how the human works / thinks
- Important context about key projects
- Things you've been told to always/never do
Things that do NOT belong in MEMORY.md:
- - One-off task completions
- Information that will be stale in a week
- Raw conversation transcripts
- Things already captured in USER.md
Heartbeat Integration
Add to your HEARTBEAT.md to enable project monitoring:
CODEBLOCK9
File Reference
| File | Location | Purpose |
|---|
| SKILL.md | INLINECODE14 | This file |
| setup.sh |
scripts/setup.sh | One-command installer |
| templates/MEMORY.md |
templates/ | Long-term memory template |
| templates/AGENTS.md |
templates/ | Startup sequence template |
| templates/USER.md |
templates/ | User profile template |
| templates/HEARTBEAT.md |
templates/ | Heartbeat config template |
memory-manager
将智能体的记忆从基础笔记升级为三层生产系统,并支持夜间整合。基于7个AI机器人在生产环境中运行30天以上的经验总结。
概述
每个AI智能体都面临同样的问题:每次会话都从零开始,对之前发生的事情毫无记忆。简单的解决方案是使用单个MEMORY.md文件——但这无法扩展。几周后,它要么变成智能体忽略的长篇大论,要么经过精心整理却缺少操作上下文。
本技能安装了一套三层记忆架构,模拟人类实际存储知识的方式:
| 层级 | 文件 | 内容说明 |
|---|
| 1 — 长期记忆 | MEMORY.md | 精炼的智慧、架构决策、来之不易的经验 |
| 2 — 操作记忆 |
memory/YYYY-MM-DD.md | 今天发生的事情、活跃项目状态、原始上下文 |
| 3 — 隐性记忆 | USER.md | 用户的工作方式、偏好、痛点、行为模式 |
外加一个夜间整合定时任务,用于回顾近期会话并自动将重要上下文提升到更高层级。
何时使用本技能
当用户要求你执行以下操作时,激活本技能:
- - 为智能体设置记忆系统
- 从基础MEMORY.md系统升级
- 添加夜间整合或记忆定时任务
- 改善智能体在会话间的连续性
- 跨智能体重启跟踪活跃项目
- 设置memory-manager技能
设置说明
步骤1:运行设置脚本
bash
bash ~/.openclaw/skills/memory-manager/scripts/setup.sh
这将创建memory/目录,复制模板文件,并打印后续步骤。
步骤2:自定义模板
设置完成后,在智能体的工作空间中编辑以下文件:
- 1. MEMORY.md — 添加智能体现有的长期上下文
- USER.md — 填写用户信息、工作方式、痛点
- AGENTS.md — 审查启动序列(已配置为三层加载)
- HEARTBEAT.md — 配置需要监控的项目
步骤3:配置启动序列
智能体的AGENTS.md必须在每次会话顶部包含以下记忆加载序列:
markdown
每次会话
在执行任何操作之前:
- 1. 读取SOUL.md — 身份和角色设定
- 读取USER.md — 你帮助的对象及其工作方式
- 读取memory/YYYY-MM-DD.md(今天) — 今天发生的事情
- 读取memory/YYYY-MM-DD.md(昨天) — 近期上下文桥接
- 如果是主会话(与用户直接聊天):同时读取MEMORY.md
为什么要读取昨天的文件? 午夜后开始的会话可能还没有今天的文件。昨天的文件可以填补这个空白。这在我们生产环境的深夜会话中防止了上下文丢失。
步骤4:设置夜间整合
添加定时任务,每天凌晨2点整合记忆:
0 2 * openclaw cron run memory-consolidation --model anthropic/claude-opus-4-5 --channel <你的主频道ID>
在OpenClaw定时任务中配置的整合提示:
你正在为此智能体执行夜间记忆整合。
任务:
- 1. 读取最近7天的memory/YYYY-MM-DD.md文件
- 读取当前的MEMORY.md
- 识别:重要决策、经验教训、架构变更、已解决问题、演变中的模式
- 用提炼的见解更新MEMORY.md(添加新内容、更新过时内容、删除无效内容)
- 检查USER.md — 更新你观察到的任何新偏好或模式
- 将整合摘要写入memory/consolidation-log.md
要有选择性。MEMORY.md应保持在500行以内。质量优先于数量。
完成信号:完成后在频道中回复CONSOLIDATION_COMPLETE。
为什么选择凌晨2点? 低活动时段。整合模型拥有当天事件的完整上下文。夜间运行(而非每周)意味着每次整合不会过于繁重。
记忆加载规则
主会话(与用户直接聊天)
加载所有三个层级:
SOUL.md → USER.md → memory/today.md → memory/yesterday.md → MEMORY.md
群聊/共享频道
仅加载层级2和3(不加载MEMORY.md):
SOUL.md → USER.md → memory/today.md → memory/yesterday.md
为什么在群聊中跳过MEMORY.md? 长期记忆通常包含个人上下文——私人偏好、健康信息、财务细节——这些不应泄露到与陌生人的对话中。日常操作记录通常是安全的。
子智能体/工作会话
仅加载今天的记录:
memory/today.md(如果与任务相关)
子智能体是临时的。不要加载完整记忆——这会浪费令牌和上下文。
每日记录格式
每个memory/YYYY-MM-DD.md文件遵循以下结构:
markdown
YYYY-MM-DD
会话
[时间] — 会话摘要
活跃项目
项目名称
- - 状态: 进行中 / 受阻 / 已完成
- 上次操作: 上次完成的工作
- 下一步: 需要进行的下一步
- 阻塞项: 任何阻碍进展的事项
下次会话上下文
未来的我需要知道的关键信息,以便无需重新解释就能继续:
原始日志
(较少整理——将可能重要的事项转储到这里)
下次会话上下文部分是最重要的。 智能体经常在任务中途结束会话。没有这个部分,下次会话必须从头重建状态。请像向刚加入项目的同事做简报一样编写。
活跃项目跟踪
项目在每日记录中经历以下状态:
规划中 → 进行中 → 受阻 → 审查中 → 已完成
心跳集成(参见HEARTBEAT.md)检查活跃项目并自动呈现阻塞项。
MEMORY.md 整理规则
长期记忆应:
- - 精炼而非全面 — 提炼的精华,而非原始日志
- 可操作 — 能改变未来决策的内容
- 常青 — 不是我周二做了什么而是从周二事件中学到的教训
- 按主题组织 — 架构、经验、用户偏好、重复模式
属于MEMORY.md的内容:
- - 架构决策及其背后的理由
- 从失败中吸取的教训
- 用户工作/思考的模式
- 关键项目的重要上下文
- 被告知要始终/从不做的事情
不属于MEMORY.md的内容:
- - 一次性任务完成记录
- 一周内就会过时的信息
- 原始对话记录
- 已在USER.md中捕获的内容
心跳集成
添加到你的HEARTBEAT.md以启用项目监控:
markdown
活跃项目检查
对于active_projects.json中的每个项目(如果存在):
- 1. 检查最后更新时间戳
- 如果项目超过48小时未更新,标记出来:⚠️ [项目] 已有X天未更新
- 如果状态为受阻,向用户呈现阻塞项
- 如果状态为已完成但未归档,提示归档
记忆健康检查(每周,周日)
- 1. 检查MEMORY.md行数 — 如果超过500行,标记需要修剪
- 检查memory/文件夹 — 如果存在超过30天的每日文件,标记需要归档
- 报告:X个每日文件,MEMORY.md为X行,上次整合日期:[日期]
文件参考
| 文件 | 位置 | 用途 |
|---|
| SKILL.md | ~/.openclaw/skills/memory-manager/ | 本文件 |
| setup.sh |
scripts/setup.sh | 一键安装程序 |
| templates/MEMORY.md | templates/ | 长期记忆模板 |
| templates/AGENTS.md | templates/ | 启动序列模板 |
| templates/USER.md | templates/ | 用户档案模板 |
| templates/HEARTBEAT.md | templates/ | 心跳配置模板 |