Agent Memory Tiers
Stop your agents from forgetting everything between runs.
OpenClaw agents start every activation with zero memory of what they did last time. They waste hundreds or thousands of tokens re-reading old files, parsing chat history, and reconstructing context. This skill fixes that.
Agent Memory Tiers is a structured, self-updating memory system that gives agents instant context on startup. Two files, updated automatically at the end of every run, so the next activation starts warm.
Tested in production across a 20-agent swarm running daily for 3+ weeks.
How It Works
Two memory layers sit in each agent's workspace:
| Layer | Purpose | Size | Loaded |
|---|
| L0 | Instant state snapshot | 4 lines | Every activation |
| L1 |
7-day rolling context | ~20-40 lines | Every activation |
|
L2+ | Historical memory | Varies | Only when needed |
The agent reads L0 and L1 before doing anything else. Before finishing, it updates both files. Next activation picks up exactly where this one left off.
Token savings: 300-3700 tokens per activation depending on agent complexity. Over a week of daily runs, that adds up fast.
Setup
Step 1: Create L0.md in your agent's workspace
CODEBLOCK0
Example — a content agent:
CODEBLOCK1
Example — a monitoring agent:
CODEBLOCK2
Step 2: Create L1.md in your agent's workspace
CODEBLOCK3
Example — a lead generation agent:
CODEBLOCK4
Step 3: Add the Quick Context header to your SOUL.md
Paste this at the top of your agent's SOUL.md file, right after the role description:
CODEBLOCK5
Step 4: Add the End-of-Run footer to your SOUL.md
Paste this at the bottom of your agent's SOUL.md file:
CODEBLOCK6
Why This Structure
L0 is for speed. Four lines. The agent reads it in under 50 tokens and immediately knows: who am I, what should I focus on, what did I do last, and is anything broken. No digging through files.
L1 is for context. Seven days of history, three active tasks, key numbers, and blockers. Enough to make informed decisions without loading the full memory archive. Stays under 200 tokens for most agents.
L2+ is on-demand. Historical memory files in a memory/ folder. Only loaded when the task explicitly requires older context. This keeps routine activations fast and cheap.
Self-updating is critical. The agent writes its own L0/L1 before finishing. No external process needed. No sync scripts. The agent that did the work is the one that records what happened.
Multi-Agent Coordination
When running multiple agents, any orchestrator agent can read another agent's L0.md to get instant status without interrupting it or parsing logs.
CODEBLOCK7
This eliminates the "is this agent available?" guessing game and prevents task collisions in multi-agent setups.
Common Mistakes
| Mistake | Fix |
|---|
| L0 grows beyond 4 lines | Ruthlessly compress. If it does not fit in 4 lines, it belongs in L1. |
| L1 "Last 7 Days" keeps growing |
Hard cap at 7 entries. Drop the oldest every time you add a new one. |
| Agent skips the end-of-run update | Put "MANDATORY" in the SOUL.md footer. Bold it. Agents follow strong directives. |
| L1 blockers pile up | Remove blockers the moment they are resolved. Stale blockers cause confusion. |
| Storing detailed logs in L1 | L1 is summaries only. One line per day. Details go in dedicated log files. |
| Using relative dates ("yesterday") | Always use absolute dates (YYYY-MM-DD). The agent does not know when it last ran. |
Error Handling
Agent does not read L0/L1 on startup:
The "Quick Context" header in SOUL.md must be near the top. If it is buried below other instructions, the agent may skip it. Move it directly after the role description.
Agent overwrites L0/L1 with garbage:
This usually means the SOUL.md footer instructions are too vague. Use the exact template above with explicit line counts and section names. Agents follow precise structure better than general guidance.
L1 file grows too large (over 50 lines):
Your "Key State" section is probably accumulating instead of updating. Each run should replace old state values, not append. Restructure: state is current values, not a changelog.
Multiple agents writing to the same L0/L1:
Each agent must have its own L0.md and L1.md in its own workspace. Never share these files between agents. The orchestrator reads them, but only the owning agent writes them.
Permissions
This skill requires:
- - File read/write in the agent's workspace directory — to read and update L0.md and L1.md.
- No network access required.
- No external API access required.
- No sensitive data access required.
Credits
Built and battle-tested by the Megaport swarm team. Inspired by the OpenViking tiered memory architecture.
License
MIT — use it, modify it, share it.
智能体记忆层级
让您的智能体不再在每次运行之间遗忘一切。
OpenClaw智能体每次激活时,对上次所做之事毫无记忆。它们浪费数百甚至数千个token重新读取旧文件、解析聊天历史并重建上下文。本技能解决了这一问题。
智能体记忆层级是一个结构化的、自我更新的记忆系统,让智能体在启动时即刻获得上下文。两个文件在每次运行结束时自动更新,确保下一次激活从热启动开始。
已在生产环境中经过测试,一个由20个智能体组成的集群每日运行,持续超过3周。
工作原理
每个智能体的工作区中包含两个记忆层:
| 层级 | 用途 | 大小 | 加载方式 |
|---|
| L0 | 即时状态快照 | 4行 | 每次激活 |
| L1 |
7天滚动上下文 | 约20-40行 | 每次激活 |
|
L2+ | 历史记忆 | 不定 | 仅按需加载 |
智能体在执行任何其他操作前,先读取L0和L1。在结束前,它会更新这两个文件。下一次激活将精确地从本次结束处继续。
节省的token数: 每次激活可节省300-3700个token,具体取决于智能体的复杂度。一周的日常运行下来,节省量会迅速累积。
设置
步骤1:在智能体工作区中创建L0.md
markdown
L0 — [智能体名称] 快速状态
你是[智能体名称]。[一句话描述角色和目的。]
当前重点:[当前最高优先级——本周最重要的事项。]
上次运行:[日期和上次活动的一行摘要,或尚无运行记录。]
标志:[关键状态警告——cron状态、信用额度限制、阻塞项。若无则为无。]
示例——内容智能体:
markdown
L0 — WRITER 快速状态
你是WRITER。公司博客和社交媒体账号的内容引擎。
当前重点:起草3篇推广新定价页面的LinkedIn帖子。
上次运行:2026-03-15 — 生成了2篇博客预告和1篇思想领导力文章。
标志:发布队列已加载8篇帖子至3月22日。无阻塞项。
示例——监控智能体:
markdown
L0 — WATCHDOG 快速状态
你是WATCHDOG。生产环境的安全监控器。
当前重点:跟踪v2.4部署后的错误率。
上次运行:2026-03-16 — 扫描日志,无异常。告警阈值设为2%错误率。
标志:Grafana仪表板间歇性不可达。若持续存在,请调查。
步骤2:在智能体工作区中创建L1.md
markdown
L1 — [智能体名称] 滚动上下文
最近7天
- - YYYY-MM-DD: 活动或状态变更的一行摘要。
- YYYY-MM-DD: 另一条记录。
(仅保留最近7条。添加新记录时删除最旧的。)
活跃任务(前3项)
- 1. 任务描述 — 附加上下文,相关负责人(如有)。
- 第二优先级任务。
- 第三优先级任务。
关键状态
- - 重要文件路径、跟踪器数值、配置状态。
- 最近发生变化的任何内容。
- 智能体需要知道的数字(队列大小、截止日期等)。
阻塞项
- - 阻碍进展的因素。根本原因,而非表象。
- 移除已解决的阻塞项。添加新的阻塞项。
- 若无则为无。
示例——潜在客户生成智能体:
markdown
L1 — SCOUT 滚动上下文
最近7天
- - 2026-03-16: 在LinkedIn上扫描AI咨询潜在客户。发现4个有希望的潜在客户。
- 2026-03-15: 调研了3家发布AI招聘信息的公司。已添加到LEADS.md。
- 2026-03-14: 首次搜索运行。建立了搜索标准和基线。
活跃任务(前3项)
- 1. 每周寻找5个合格潜在客户 — 公开表示在AI应用方面遇到困难的企业。
- 根据预算信号(招聘、融资轮次、公开投诉)对潜在客户进行评分。
- 将顶级潜在客户传递给PITCH智能体进行提案起草。
关键状态
- - LEADS.md: 7个潜在客户,2个合格,0个已联系。
- 搜索渠道:LinkedIn、Twitter、Hacker News、行业论坛。
- 提供的服务:$2k-$6k设置费 + $500-$2k/月管理费。
阻塞项
步骤3:将快速上下文标题添加到您的SOUL.md中
将以下内容粘贴到智能体SOUL.md文件的顶部,紧跟在角色描述之后:
markdown
快速上下文(首先阅读这些内容,优先于其他一切)
- 1. 读取 L0.md — 您的当前状态,共4行。
- 读取 L1.md — 您的最近7天、活跃任务和阻塞项。
- 仅当当前任务需要更早的历史记录时,才读取 memory/ 中的文件。
- 在结束前:更新L0.md和L1.md(请参阅底部的运行结束部分)。
步骤4:将运行结束页脚添加到您的SOUL.md中
将以下内容粘贴到智能体SOUL.md文件的底部:
markdown
运行结束时的记忆更新(强制要求 — 在每次激活结束前必须执行)
- 1. 更新L0.md,精确包含4行:
- 第1行:一句话的身份提醒。
- 第2行:当前最高优先级(本次运行后,当前最重要的事项)。
- 第3行:您本次运行所做的工作(日期 + 一行摘要)。
- 第4行:状态标志(cron状态、信用警告、阻塞项,或无)。
- 2. 更新L1.md:
- 在最近7天中添加今天的日期 + 一行摘要(仅保留最近7条记录 — 删除最旧的)。
- 更新活跃任务,反映本次运行后的当前前3项。
- 更新关键状态中的任何已更改的数字、文件或日期。
- 更新阻塞项 — 移除已解决的,添加新的。
为何采用这种结构
L0追求速度。 四行内容。智能体在不到50个token内即可读取完毕,并立即知道:我是谁、我应该关注什么、我上次做了什么、是否有任何问题。无需翻阅文件。
L1提供上下文。 七天的历史记录、三个活跃任务、关键数字和阻塞项。足以做出明智决策,而无需加载完整的记忆档案。对大多数智能体而言,保持在200个token以下。
L2+按需加载。 历史记忆文件存放在memory/文件夹中。仅当任务明确需要更早的上下文时才加载。这使常规激活保持快速且低成本。
自我更新至关重要。 智能体在结束前自行写入其L0/L1。无需外部进程。无需同步脚本。完成工作的智能体就是记录所发生之事的智能体。
多智能体协调
当运行多个智能体时,任何编排智能体都可以读取另一个智能体的L0.md,以获取即时状态,而无需中断它或解析日志。
markdown
编排器模式
在向另一个智能体分配任务之前:
- 1. 读取其L0.md以检查当前重点和标志。
- 读取其L1.md的阻塞项部分,以确认其未被卡住。
- 如果被阻塞,则将任务路由到备用智能体或标记为人工审核。
这消除了这个智能体可用吗?的猜测游戏,并防止了多智能体设置中的任务冲突。
常见错误
| 错误 | 修复方法 |
|---|
| L0增长超过4行 | 无情地压缩。如果无法容纳在4行内,则属于L1。 |
| L1最近7天持续增长 |
硬性限制为7条。每次添加新记录时删除最旧的。 |
| 智能体跳过运行结束更新 | 在SOUL.md页脚中写上强制要求。加粗。智能体会遵循强指令。 |
| L1阻塞项堆积 | 阻塞项一旦解决立即移除。过时的阻塞项会造成混乱。 |
| 在L1中存储详细日志 | L1仅用于摘要。每天一行。详细信息存入专用日志文件。 |
| 使用相对日期(昨天) | 始终使用绝对日期(YYYY-MM-DD)。智能体不知道它上次运行的时间。 |
错误处理
智能体在启动时不读取L0/L1:
SOUL.md中的快速上下文标题必须靠近顶部。如果它被埋在其他指令之下,智能体可能会跳过它。将其直接移到角色描述之后。
智能体用垃圾内容覆盖L0/L1:
这