Agent Memory Setup
Set up a complete 3-tier memory system for any OpenClaw agent. Includes directory structure, memory files, semantic search, and context compaction.
Quick Start
CODEBLOCK0
For full details, read the sections below.
When NOT to Use This Skill
- - Backing up or exporting memory — this skill sets up memory, it doesn't handle backup/migration
- Memory is already set up — run the verification checklist in Step 4 instead of re-running setup
- Debugging a specific memory issue — check the Troubleshooting section directly
- Changing memory tier content — that's the agent's job during normal operation, not a setup task
Prerequisites
Before running setup, ensure:
- - OpenClaw CLI is installed and on your PATH (
openclaw --version). If not installed, the setup script will still create directories and memory files, but plugin installation and config changes must be done manually. - Python 3.8+ (for QMD only — optional). Check with
python3 --version. QMD provides semantic search (memory_search) over memory files. The core memory system (tiers, daily logs, Lossless Claw) works fully without it. If you can't install QMD (no Python, restricted server), you lose semantic search but keep everything else. - Node.js 18+ (for OpenClaw and Lossless Claw plugin).
Platform Notes
- - Linux: Fully supported. No special considerations.
- macOS: Fully supported. Config lives at
~/.openclaw/openclaw.json (same as Linux). The setup script uses POSIX-compatible date and mkdir — no GNU-specific flags. - Windows (WSL2): Supported via WSL2 with Ubuntu or similar. Run everything inside WSL, not from Windows CMD/PowerShell. Gotcha: If your workspace is on a Windows-mounted drive (
/mnt/c/...), file permissions may behave unexpectedly — prefer using a path inside the WSL filesystem (~/workspace) for reliable permission handling. The script's set -euo pipefail and mkdir -p work fine under WSL2. - Windows (native): Not supported. OpenClaw requires a Unix shell.
Setup Steps
Step 1: Run the setup script
CODEBLOCK1
This creates:
- -
memory/, memory/hot/, memory/warm/ directories - INLINECODE13 (active session state)
- INLINECODE14 (stable config & preferences)
- INLINECODE15 (long-term archive)
- INLINECODE16 (today's daily log)
- INLINECODE17 (heartbeat tracking)
It also checks for QMD and Lossless Claw, installing them if possible.
Step 2: Copy the AGENTS.md template
Read references/AGENTS_TEMPLATE.md and write it to the agent's workspace as AGENTS.md.
What to customize:
- - Heartbeat section — adapt checks to the agent's domain (e.g., a CFO agent checks costs, a marketing agent checks social metrics, a DevOps agent checks CI pipelines)
- HEARTBEAT.md — create a small checklist of periodic tasks specific to the agent's role
- Memory tier descriptions — keep as-is unless the agent has unusual memory patterns
What to keep as-is:
- - The session startup sequence (read SOUL.md, USER.md, memory files)
- Memory tiering instructions (HOT/WARM/COLD flow)
- The "Write It Down" and "No Mental Notes" sections
- MEMORY.md security rules (main session only)
Step 3: Configure openclaw.json
Add to agents.defaults (or the specific agent config):
CODEBLOCK2
What each setting does:
| Setting | Purpose | Customization |
|---|
| INLINECODE21 | Enables QMD semantic search over memory files | INLINECODE22 is the only current provider |
| INLINECODE23 |
Lossless Claw compacts old messages into expandable summaries instead of dropping them. "Safeguard" mode triggers compaction before context overflows, preserving everything via
lcm_expand | Change mode only if you understand Lossless Claw internals |
|
contextPruning: cache-ttl | Evicts stale context from the active window after the TTL expires. Works WITH Lossless Claw: content is compacted first, then pruned, so nothing is truly lost | Adjust
ttl to match your use case:
"5m" for fast-cycling agents,
"2h" for long research sessions |
|
heartbeat | Triggers periodic check-ins where the agent reads HEARTBEAT.md and performs maintenance tasks (email checks, memory review, etc.) | Adjust
"every" interval:
"5m" for monitoring agents,
"1h" for general use,
"4h" for low-activity agents |
Enable these plugins for the agent:
CODEBLOCK3
What each plugin does:
| Plugin | Role |
|---|
| INLINECODE34 | Persists and loads memory context across sessions. Ensures the agent reads memory files (HOT/WARM/COLD) on startup |
| INLINECODE35 |
Loads additional workspace files (AGENTS.md, SOUL.md, USER.md, TOOLS.md) into the agent's context at session start |
|
lossless-claw | Compacts old conversation into summaries that can be expanded back on demand via
lcm_expand,
lcm_grep, and
lcm_expand_query. Prevents amnesia in long conversations |
Manual plugin install (if the setup script didn't install them):
CODEBLOCK4
Step 4: Restart and verify
CODEBLOCK5
Verification checklist — run each and confirm:
CODEBLOCK6
If any check fails, see the Troubleshooting section below.
Migrating Existing Memory
If you already have MEMORY.md or daily logs from before this system:
- 1. Run the setup script normally — it checks
if [ ! -f ] before creating each file, so your existing files are preserved untouched. - Reorganize existing content into tiers:
- Move active/temporary context from MEMORY.md →
memory/hot/HOT_MEMORY.md
- Move stable preferences, API refs, recurring config →
memory/warm/WARM_MEMORY.md
- Keep long-term decisions, milestones, lessons learned in
MEMORY.md (COLD tier)
- 3. Existing daily logs stay in
memory/ as-is — the system reads them from there already.
Recovery
Corrupted memory file: Delete the corrupted file and re-run bash scripts/setup_memory.sh /path/to/workspace. The script only creates files that don't exist, so other memory files are safe. Alternatively, manually recreate the file with the template header from the setup script.
Lost or deleted AGENTS.md: Re-copy from references/AGENTS_TEMPLATE.md and customize.
Broken openclaw.json: Restore from backup (the setup script doesn't modify openclaw.json — config changes are manual). If no backup exists, re-add the config from Step 3 above.
General principle: The setup script is always safe to re-run. It never overwrites existing files.
Using Lossless Claw After Setup
Once installed, Lossless Claw works automatically:
- 1. Compaction is automatic — as conversations grow long, old messages are compacted into summaries behind the scenes.
- The agent retrieves context on demand using these tools:
-
lcm_expand — expand a compacted summary back into its original messages
-
lcm_grep — search across all compacted history by regex or text
-
lcm_expand_query — ask a question and get answers from compacted context
- 3. No agent code changes needed — if the agent has access to lcm* tools (standard in OpenClaw), it can retrieve anything that was compacted.
- AGENTS.md instructs the agent to update HOTMEMORY before compaction flushes, so critical working state survives even when context is pruned.
How the Tiers Work
| Tier | File | Purpose | Update Frequency |
|---|
| 🔥 HOT | INLINECODE51 | Current task, pending actions | Every few turns |
| 🌡️ WARM |
memory/warm/WARM_MEMORY.md | Stable preferences, API refs, gotchas | When things change |
| ❄️ COLD |
MEMORY.md | Milestones, decisions, distilled lessons | Weekly/monthly |
Concrete examples per tier
🔥 HOT — "Currently debugging auth flow for client X. Waiting on API key from Bob. Next step: test endpoint once key arrives."
🌡️ WARM — "User prefers bullet lists over paragraphs. Slack workspace is #eng-team. API rate limit is 100 req/min. Always use UTC timestamps."
❄️ COLD — "2025-03-15: Migrated from v1 to v2 API. Key lesson: always pin dependency versions. Decision: adopted trunk-based development."
Daily logs (memory/YYYY-MM-DD.md) capture raw session events. Periodically, the agent reviews daily logs and promotes important items up to COLD.
Multi-Agent & Multi-Context Workspaces
Shared workspaces (multiple agents, one directory)
- - HOTMEMORY is shared — all agents read it. Never put agent-specific debugging context here (e.g., "Current task: fix auth bug"). Other agents (including voice/avatar) will pick it up and fixate on it.
- Keep HOTMEMORY generic — use it for general state like "User is in a meeting until 3pm" or "Deploy freeze until Friday."
- Daily logs are shared too — agents writing to the same
memory/YYYY-MM-DD.md should prefix entries with their name to avoid confusion. - WARM and COLD are typically safe — preferences and long-term memory apply across agents.
Separate contexts (one agent, multiple domains)
Each OpenClaw agent maps to one workspace. If you need separate memory contexts (e.g., work vs. personal):
- - Option A: Two separate agents — each with its own workspace and memory system. Cleanest separation.
- Option B: Use WARM memory for context switching — track multiple contexts in WARM_MEMORY (sections for "Work" and "Personal"), switching focus based on conversation.
- Option C: Separate memory subdirectories — create
memory/work/ and memory/personal/ with separate HOT files, and instruct the agent (via AGENTS.md) which to use based on context. Advanced; requires custom AGENTS.md logic.
Long-Term Maintenance
Daily logs grow over time. Each day creates a new memory/YYYY-MM-DD.md file. Over a year, this accumulates ~365 small files. This is generally fine (each file is small — typically 1–10 KB), but for long-running agents:
- - Archive old logs: Move logs older than 90 days to
memory/archive/ to keep the main memory/ directory fast to scan. QMD can still index the archive if configured. - The agent handles promotion: During heartbeats, the agent reviews daily logs and promotes important items to COLD (MEMORY.md). Once promoted, daily logs become reference-only.
- Disk usage is modest: Even with years of logs, expect tens of MB at most. Lossless Claw summaries are stored separately by the plugin and managed automatically.
Troubleshooting
| Symptom | Likely Cause | Fix |
|---|
| Agent doesn't read memory files on startup | AGENTS.md missing or doesn't include memory instructions | Copy references/AGENTS_TEMPLATE.md → INLINECODE62 |
| INLINECODE63 not working |
QMD not installed or memorySearch not configured | Run
qmd --version; add
"memorySearch": { "provider": "local" } to config |
| Old conversations vanish (no summaries) | Lossless Claw not enabled | Check
openclaw plugins list for lossless-claw; enable in plugins config |
| Config changes have no effect | Gateway not restarted | Run
openclaw gateway restart |
| Plugin install fails | openclaw CLI not in PATH or npm issue | Verify
openclaw --version; try
npm install -g openclaw |
| Agent overwrites existing memory files | Script bug (shouldn't happen) | Script checks
if [ ! -f ] before creating — report if override occurs |
智能体记忆系统设置
为任何OpenClaw智能体建立完整的3层记忆系统。包括目录结构、记忆文件、语义搜索和上下文压缩。
快速开始
bash
1. 运行设置脚本
bash scripts/setup_memory.sh /path/to/workspace
2. 将AGENTS.md模板复制到工作区
(阅读 references/AGENTS_TEMPLATE.md,适配后写入 workspace/AGENTS.md)
3. 在 openclaw.json 中添加配置(具体JSON见下方步骤3)
4. 重启
openclaw gateway restart
完整详情请阅读以下章节。
何时不应使用此技能
- - 备份或导出记忆 — 此技能用于设置记忆系统,不处理备份/迁移
- 记忆系统已设置完成 — 运行步骤4中的验证清单,而非重新运行设置
- 调试特定记忆问题 — 直接查看故障排除章节
- 更改记忆层级内容 — 这是智能体在正常运行中的任务,而非设置任务
前置条件
运行设置前,请确保:
- - OpenClaw CLI 已安装并位于PATH路径中(openclaw --version)。如果未安装,设置脚本仍会创建目录和记忆文件,但插件安装和配置更改需手动完成。
- Python 3.8+ (仅QMD需要——可选)。使用 python3 --version 检查。QMD提供对记忆文件的语义搜索(memory_search)。核心记忆系统(层级、每日日志、无损爪)无需QMD即可完整运行。如果无法安装QMD(无Python环境、受限服务器),将失去语义搜索功能,但其他功能保持不变。
- Node.js 18+ (OpenClaw和无损爪插件需要)。
平台说明
- - Linux:完全支持。无需特殊考虑。
- macOS:完全支持。配置文件位于 ~/.openclaw/openclaw.json(与Linux相同)。设置脚本使用POSIX兼容的 date 和 mkdir — 无需GNU特定标志。
- Windows(WSL2):通过WSL2使用Ubuntu或类似系统支持。所有操作在WSL内执行,而非Windows CMD/PowerShell。注意:如果工作区位于Windows挂载的驱动器(/mnt/c/...),文件权限可能异常 — 建议使用WSL文件系统内的路径(~/workspace)以确保权限处理可靠。脚本的 set -euo pipefail 和 mkdir -p 在WSL2下运行正常。
- Windows(原生):不支持。OpenClaw需要Unix shell环境。
设置步骤
步骤1:运行设置脚本
bash
bash scripts/setup_memory.sh /path/to/agent/workspace
这将创建:
- - memory/、memory/hot/、memory/warm/ 目录
- memory/hot/HOTMEMORY.md(活跃会话状态)
- memory/warm/WARMMEMORY.md(稳定配置和偏好)
- MEMORY.md(长期存档)
- memory/YYYY-MM-DD.md(今日日志)
- memory/heartbeat-state.json(心跳跟踪)
同时检查QMD和无损爪,并在可能时进行安装。
步骤2:复制AGENTS.md模板
阅读 references/AGENTS_TEMPLATE.md 并将其写入智能体工作区,命名为 AGENTS.md。
需要自定义的内容:
- - 心跳部分 — 根据智能体领域调整检查项(例如,CFO智能体检查成本,营销智能体检查社交指标,DevOps智能体检查CI流水线)
- HEARTBEAT.md — 创建针对智能体角色的定期任务清单
- 记忆层级描述 — 除非智能体有特殊记忆模式,否则保持原样
保持原样的内容:
- - 会话启动序列(读取SOUL.md、USER.md、记忆文件)
- 记忆层级指令(HOT/WARM/COLD流程)
- 写下来和无脑记部分
- MEMORY.md安全规则(仅主会话)
步骤3:配置openclaw.json
添加到 agents.defaults(或特定智能体配置):
json
memorySearch: { provider: local },
compaction: { mode: safeguard },
contextPruning: { mode: cache-ttl, ttl: 1h },
heartbeat: { every: 1h }
各设置的作用:
| 设置 | 用途 | 自定义 |
|---|
| memorySearch | 启用对记忆文件的QMD语义搜索 | local 是当前唯一提供商 |
| compaction: safeguard |
无损爪将旧消息压缩为可展开的摘要而非丢弃。保护模式在上下文溢出前触发压缩,通过 lcm_expand 保留所有内容 | 仅当理解无损爪内部机制时才更改模式 |
| contextPruning: cache-ttl | TTL过期后从活动窗口驱逐过时上下文。与无损爪配合使用:内容先压缩再修剪,因此不会真正丢失任何内容 | 根据用例调整 ttl:快速循环智能体用 5m,长时间研究会话用 2h |
| heartbeat | 触发定期签到,智能体读取HEARTBEAT.md并执行维护任务(邮件检查、记忆审查等) | 调整 every 间隔:监控智能体用 5m,一般用途用 1h,低活动智能体用 4h |
为智能体启用以下插件:
json
session-memory: { enabled: true },
bootstrap-extra-files: { enabled: true },
lossless-claw: { enabled: true }
各插件的作用:
| 插件 | 角色 |
|---|
| session-memory | 跨会话持久化和加载记忆上下文。确保智能体在启动时读取记忆文件(HOT/WARM/COLD) |
| bootstrap-extra-files |
在会话启动时将额外工作区文件(AGENTS.md、SOUL.md、USER.md、TOOLS.md)加载到智能体上下文中 |
| lossless-claw | 将旧对话压缩为可按需通过 lcm
expand、lcmgrep 和 lcm
expandquery 展开的摘要。防止长对话中的遗忘 |
手动安装插件(如果设置脚本未安装):
bash
pip install qmd # 或:pipx install qmd / brew install qmd
openclaw plugins install @martian-engineering/lossless-claw
步骤4:重启并验证
bash
openclaw gateway restart
验证清单 — 运行每项并确认:
bash
1. 记忆目录存在
ls -d memory/ memory/hot/ memory/warm/
2. 记忆文件存在
ls memory/hot/HOT
MEMORY.md memory/warm/WARMMEMORY.md MEMORY.md memory/heartbeat-state.json
3. 今日日志存在
ls memory/$(date +%Y-%m-%d).md
4. QMD已安装
qmd --version
5. 无损爪插件已激活
openclaw plugins list | grep lossless-claw
6. AGENTS.md已就位
head -5 AGENTS.md
7. 配置已应用(检查openclaw.json)
grep -c memorySearch\|compaction\|contextPruning\|lossless-claw ~/.openclaw/openclaw.json
如果任何检查失败,请参阅下方故障排除章节。
迁移现有记忆
如果您已有此系统之前的 MEMORY.md 或每日日志:
- 1. 正常运行设置脚本 — 脚本在创建每个文件前检查 if [ ! -f ],因此现有文件将原样保留。
- 将现有内容重新组织到层级中:
- 将活跃/临时上下文从 MEMORY.md 移至 memory/hot/HOT_MEMORY.md
- 将稳定偏好、API参考、重复配置移至 memory/warm/WARM_MEMORY.md
- 将长期决策、里程碑、经验教训保留在 MEMORY.md(COLD层级)
- 3. 现有每日日志 保持原样在 memory/ 中 — 系统已从该位置读取它们。
恢复
记忆文件损坏:删除损坏的文件并重新运行 bash scripts/setup_memory.sh /path/to/workspace。脚本仅创建不存在的文件,因此其他记忆文件安全。或者,使用设置脚本中的模板头部手动重新创建文件。
AGENTS.md丢失或删除:从 references/AGENTS_TEMPLATE.md