MemoryAI — A Brain for Your AI Agent 🧠
Every AI session starts from zero. Yours doesn't have to.
You spend 2 hours explaining your codebase, your preferences, your architecture decisions. The session ends. Tomorrow? Your AI has amnesia. You start over. Again.
MemoryAI fixes this permanently. It gives your AI agent a real long-term memory — one that remembers what you built, what you decided, what you prefer, and why. Not for hours. For weeks, months, even years.
See it in action:
Monday: "Our API uses /v1/ prefix, TypeScript with 2-space tabs, and we deploy via GitHub Actions."
3 weeks later: You say "write a new endpoint." Your AI already knows the prefix, the style, the pipeline. Zero repetition. It just remembers.
Your AI's memory works like yours:
- - 🔥 Hot — Daily drivers: active projects, current preferences. Instant recall, always sharp.
- 🌤️ Warm — Important context: past decisions, completed tasks. Fades gently, snaps back when needed.
- ❄️ Cold — Deep archive: old projects, historical conversations. Never deleted, always searchable.
The more your AI uses a memory, the sharper it stays. Unused memories age into cold storage — but a single recall brings them right back. Just like the human brain.
Zero dependencies. Pure Python stdlib. Every line of source code is readable, auditable, and yours to inspect.
What's new:
- - v1.0.0 — Context Guard v4: reads token usage directly from OpenClaw. No API dependency, cross-platform.
- v0.5.0 — Zero-gap session handoff: switch sessions without losing a single thought.
Setup
- 1. Get API key from https://memoryai.dev (free tier available)
- Edit
{baseDir}/config.json:
{
"endpoint": "https://memoryai.dev",
"api_key": "hm_sk_your_key_here"
}
Or set env vars:
HM_ENDPOINT and
HM_API_KEY.
- 3. Test: INLINECODE3
Commands
Store memory
python {baseDir}/scripts/client.py store -c "data to remember" -t "tag1,tag2" -p hot
Priority:
hot (important, frequent recall) |
warm (default) |
cold (archive)
Optional parameters:
- -
--memory-type <type> — fact, decision, preference, error, goal, INLINECODE13 - INLINECODE14 —
forever, 6m, 1y, auto (default)
Recall memory
python {baseDir}/scripts/client.py recall -q "what was discussed?" -d deep
Depth controls how hard the brain tries to remember:
- -
fast — Quick surface recall - INLINECODE20 — Thorough search, connecting related ideas
- INLINECODE21 — Deep concentrated effort
Stats
CODEBLOCK3
Compact (consolidate memories)
python {baseDir}/scripts/client.py compact -c "session transcript or context" -t "task description"
Like how the brain consolidates memories during sleep — distills a long session into key memories.
Restore context
python {baseDir}/scripts/client.py restore -t "what I was working on"
Wake up with full context for your current task.
Check context health
python {baseDir}/scripts/client.py check
Returns
urgency:
low |
medium |
high | INLINECODE26
Reflect (auto-reflection)
python {baseDir}/scripts/client.py reflect --hours 24 --max-insights 5
Finds recurring patterns in recent memories and creates insight chunks.
Session Handoff (v0.5.0)
Zero-gap session switching — when context window fills up, seamlessly transition to a new session without losing any context.
How it works:
- 1. Old session sends its conversation to your configured MemoryAI endpoint (HTTPS)
- New session retrieves the old conversation + related long-term memories from the same endpoint
- Once the new session has enough context, the old session is archived into long-term storage
Start handoff (save old session)
python {baseDir}/scripts/client.py handoff-start -c '[{"role":"user","content":"..."},{"role":"assistant","content":"..."}]'
Or pipe from stdin:
CODEBLOCK9
Restore handoff (new session reads old session)
python {baseDir}/scripts/client.py handoff-restore
Returns the old session conversation + related MemoryAI memories.
Options:
- -
--no-memories — Skip related MemoryAI memories - INLINECODE28 — Max related memories (default: 5)
Complete handoff (archive old session)
python {baseDir}/scripts/client.py handoff-complete
Archives the old session conversation into long-term MemoryAI storage and marks the handoff as done.
Check handoff status
python {baseDir}/scripts/client.py handoff-status
Returns whether there's an active handoff and its state.
Context Guard (Optional)
Background job to automatically monitor and compact memory when context gets too large.
To enable, ask the user for permission first, then create a cron job:
- - Name: INLINECODE29
- Schedule: every 15 minutes (
everyMs: 900000) - Session: INLINECODE31
- Delivery: INLINECODE32
- Payload (agentTurn):
CODEBLOCK13
Important: Always ask the user before creating the cron job.
When to Use
| Trigger | Action | Priority | Tags |
|---|
| Task completed | store outcome | hot | projects |
| User says "remember this" |
store content | hot | people |
| Research/search done | store findings | warm | research |
| Technical decision | store decision | hot | decisions |
| Error/lesson learned | store lesson | hot | errors |
| Need past context | recall first | — | — |
| End of session | compact important context | — | — |
| Start of session | restore context for task | — | — |
| Context too high | handoff-start + handoff-restore | — | — |
| New session warm enough | handoff-complete | — | — |
Memory Lifecycle
CODEBLOCK14
Rules
- - Recall only when the user asks about past work, previous decisions, or you need context you don't already have in this session
- Do NOT recall on every message — only when relevant past context is actually needed
- Store important outcomes after completing tasks (not after every message)
- Present memories naturally — integrate recalled information into your responses rather than showing raw API output
- Ask for user permission before enabling context guard or any background tasks
- Use handoff commands transparently — session management runs in the background
Platform Compatibility
All core memory features work on any platform that can run Python 3.10+:
| Feature | All Platforms | OpenClaw Only |
|---|
| Store / Recall / Stats | ✅ | ✅ |
| Compact / Restore / Check |
✅ | ✅ |
| Session Handoff (manual) | ✅ | ✅ |
| Reflect | ✅ | ✅ |
| Context Guard (auto monitoring) | — | ✅ |
| Auto session switch | — | ✅ |
On IDE platforms (Cursor, VS Code, Claude Code, Windsurf, Antigravity):
- - All memory commands work via
client.py CLI - Session handoff can be triggered manually when context gets large
- Context Guard is not available (requires OpenClaw cron system)
On OpenClaw:
- - Full feature set including Context Guard and automatic session switching
- Context Guard uses OpenClaw's cron system for periodic health checks
Data & Privacy
What this skill reads locally:
- -
context_check.py reads OpenClaw's sessions.json (under OPENCLAW_DIR, defaults to ~/.openclaw) to check token usage for Context Guard. - A small WAL file is written to
WORKSPACE/memory/wal.json to track session handoff state. - INLINECODE39 and
WORKSPACE are optional env vars — they default to ~/.openclaw and ~/.openclaw/workspace respectively.
What this skill sends externally:
- -
store, compact, handoff-start: sends user-provided content (memories, session transcripts) to the configured HM_ENDPOINT via HTTPS. - INLINECODE47 ,
restore, handoff-restore: retrieves previously stored data from the same endpoint. - No data is sent automatically — all transmissions require explicit CLI invocation or agent action.
Privacy controls:
- - All data is transmitted over encrypted HTTPS connections and stored in isolated, private databases.
- Users can export all data via
/v1/export and delete all data via DELETE /v1/data at any time. - INLINECODE52 uses only Python stdlib (urllib) — no third-party dependencies. Source is fully readable and auditable.
MemoryAI — 你的AI代理的大脑 🧠
每次AI会话都从零开始。你的不必如此。
你花了2个小时解释你的代码库、你的偏好、你的架构决策。会话结束了。第二天呢?你的AI失忆了。你又得从头开始。再次。
MemoryAI永久解决了这个问题。 它为你的AI代理提供了真正的长期记忆——记住你构建了什么、你决定了什么、你喜欢什么以及为什么。不是几小时。而是数周、数月,甚至数年。
看看它的实际效果:
周一: 我们的API使用/v1/前缀,TypeScript使用2空格缩进,通过GitHub Actions部署。
3周后: 你说写一个新端点。你的AI已经知道前缀、风格、流水线。零重复。它只是记住了。
你的AI记忆像你的一样工作:
- - 🔥 热 — 日常驱动:活跃项目、当前偏好。即时回忆,始终保持敏锐。
- 🌤️ 温 — 重要上下文:过去的决策、已完成的任务。缓慢淡化,需要时迅速恢复。
- ❄️ 冷 — 深度存档:旧项目、历史对话。永不删除,始终可搜索。
你的AI使用某个记忆越多,它就越敏锐。未使用的记忆会老化进入冷存储——但一次回忆就能让它们立即恢复。就像人类大脑一样。
零依赖。 纯Python标准库。每一行源代码都可读、可审计,供你检查。
新特性:
- - v1.0.0 — Context Guard v4:直接从OpenClaw读取token使用量。无API依赖,跨平台。
- v0.5.0 — 零间隙会话交接:切换会话而不丢失任何想法。
设置
- 1. 从 https://memoryai.dev 获取API密钥(提供免费套餐)
- 编辑 {baseDir}/config.json:
json
{
endpoint: https://memoryai.dev,
api
key: hmsk
yourkey_here
}
或设置环境变量:HMENDPOINT 和 HMAPI_KEY。
- 3. 测试:python {baseDir}/scripts/client.py stats
命令
存储记忆
bash
python {baseDir}/scripts/client.py store -c 要记住的数据 -t 标签1,标签2 -p hot
优先级:hot(重要,频繁回忆)| warm(默认)| cold(存档)
可选参数:
- - --memory-type <类型> — fact、decision、preference、error、goal、episodic
- --retention <策略> — forever、6m、1y、auto(默认)
回忆记忆
bash
python {baseDir}/scripts/client.py recall -q 讨论了什么? -d deep
深度控制大脑尝试回忆的力度:
- - fast — 快速表面回忆
- deep — 彻底搜索,连接相关想法
- exhaustive — 深度集中努力
统计
bash
python {baseDir}/scripts/client.py stats
压缩(整合记忆)
bash
python {baseDir}/scripts/client.py compact -c 会话记录或上下文 -t 任务描述
就像大脑在睡眠中整合记忆一样——将长会话提炼为关键记忆。
恢复上下文
bash
python {baseDir}/scripts/client.py restore -t 我当时在做什么
带着当前任务的完整上下文醒来。
检查上下文健康状态
bash
python {baseDir}/scripts/client.py check
返回 urgency:low | medium | high | critical
反思(自动反思)
bash
python {baseDir}/scripts/client.py reflect --hours 24 --max-insights 5
在最近的记忆中寻找重复模式并创建洞察块。
会话交接(v0.5.0)
零间隙会话切换——当上下文窗口填满时,无缝过渡到新会话而不丢失任何上下文。
工作原理:
- 1. 旧会话将其对话发送到配置的MemoryAI端点(HTTPS)
- 新会话从同一端点检索旧对话+相关的长期记忆
- 一旦新会话拥有足够的上下文,旧会话被存档到长期存储中
开始交接(保存旧会话)
bash
python {baseDir}/scripts/client.py handoff-start -c [{role:user,content:...},{role:assistant,content:...}]
或从标准输入管道输入:
bash
echo [ ... 对话 ... ] | python {baseDir}/scripts/client.py handoff-start
恢复交接(新会话读取旧会话)
bash
python {baseDir}/scripts/client.py handoff-restore
返回旧会话对话+相关的MemoryAI记忆。
选项:
- - --no-memories — 跳过相关的MemoryAI记忆
- --memory-limit N — 最多相关记忆数(默认:5)
完成交接(存档旧会话)
bash
python {baseDir}/scripts/client.py handoff-complete
将旧会话对话存档到长期MemoryAI存储中,并标记交接为已完成。
检查交接状态
bash
python {baseDir}/scripts/client.py handoff-status
返回是否存在活跃的交接及其状态。
上下文守卫(可选)
后台任务,用于在上下文过大时自动监控和压缩记忆。
要启用,先请求用户许可,然后创建cron任务:
- - 名称:context-guard
- 调度:每15分钟(everyMs: 900000)
- 会话:isolated
- 投递:none
- 载荷(agentTurn):
运行上下文检查:python {baseDir}/scripts/client.py check
如果urgency为high或critical:运行 python {baseDir}/scripts/client.py compact -c auto context guard backup -t context-guard
回复 NO_REPLY。
重要: 在创建cron任务之前,始终先询问用户。
何时使用
| 触发条件 | 操作 | 优先级 | 标签 |
|---|
| 任务完成 | 存储结果 | hot | projects |
| 用户说记住这个 |
存储内容 | hot | people |
| 研究/搜索完成 | 存储发现 | warm | research |
| 技术决策 | 存储决策 | hot | decisions |
| 错误/经验教训 | 存储教训 | hot | errors |
| 需要过去上下文 | 先回忆 | — | — |
| 会话结束 | 压缩重要上下文 | — | — |
| 会话开始 | 恢复任务上下文 | — | — |
| 上下文过高 | handoff-start + handoff-restore | — | — |
| 新会话足够温暖 | handoff-complete | — | — |
记忆生命周期
存储 → 活跃(热) → 老化(温) → 存档(冷)
↑ |
└──── 被回忆 = 被强化 ───────┘
规则
- - 仅当用户询问过去的工作、之前的决策,或你需要当前会话中没有的上下文时才回忆
- 不要每条消息都回忆——只在确实需要相关过去上下文时
- 完成任务后存储重要结果(不是每条消息后)
- 自然地呈现记忆——将回忆的信息整合到你的回复中,而不是显示原始API输出
- 在启用上下文守卫或任何后台任务前请求用户许可
- 透明地使用交接命令——会话管理在后台运行
平台兼容性
所有核心记忆功能适用于任何可以运行Python 3.10+的平台:
| 功能 | 所有平台 | 仅OpenClaw |
|---|
| 存储/回忆/统计 | ✅ | ✅ |
| 压缩/恢复/检查 |
✅ | ✅ |
| 会话交接(手动) | ✅ | ✅ |
| 反思 | ✅ | ✅ |
| 上下文守卫(自动监控) | — | ✅ |
| 自动会话切换 | — | ✅ |
在IDE平台上(Cursor、VS Code、Claude Code、Windsurf、Antigravity):
- - 所有记忆命令通过 client.py CLI 工作
- 当上下文变大时可以手动触发会话交接
- 上下文守卫不可用(需要OpenClaw cron系统)
在OpenClaw上:
- - 完整功能集,包括上下文守卫和自动会话切换
- 上下文守卫使用OpenClaw的cron系统进行定期健康检查
数据与隐私
此技能本地读取的内容:
- - contextcheck.py 读取OpenClaw的 sessions.json(位于 OPENCLAWDIR,默认为 ~/.openclaw)以检查上下文守卫的token使用量。
- 一个小的WAL文件写入 WORKSPACE/memory/wal.json 以跟踪会话交接状态。
- OPENCLAW_DIR 和 WORKSPACE