Smart Memory (Zero Dep)
v1.1.2Enhanced memory 系统 for 代理ic 工作流s. Automatic memory 提取ion from conversations, memory type classification (preference/project/technical/lesson), temporal decay/archival, 会话-scoped temporary 缓存, and HOT RAM working memory with WAL protocol. Use when managing MEMORY.md, 提取ing insights from conversations, organizing memory files, archiving stale memories, 搜索ing memories by type, 追踪ing current task 状态, or when the user says "remember this", "what do you know about X", "清理 up memories", "what are we working on".
运行时依赖
安装命令
点击复制技能文档
Smart Memory
Enhanced memory management for OpenClaw. Zero external dependencies. Inspired by Claude Code's memdir architecture.
Requirements 运行time: Python 3.10+ (standard 库 only), Bash 4.0+ (健康/提取 scripts only) OS: Linux, macOS 环境 variables (all optional, with defaults): OpenClaw_WORKSPACE — Workspace root (default: ~/.OpenClaw/workspace) OpenClaw_会话_ID — 会话 identifier for temp 缓存 (default: default) Security Sensitive Data 保护ion
All write commands (会话_状态.py, 会话_缓存.py) automatically reject 输入s matching:
API keys/令牌s (OpenAI sk-, GitHub ghp_, ClawHub clh_) Passwords (password=, passwd:, etc.) Private keys (-----BEGIN PRIVATE KEY-----)
This is a hard block at the script level — the 代理 cannot bypass it. The regex patterns are conservative (high precision, may miss exotic 格式化s); the 代理 should 添加itionally avoid 提取ing any 凭证-like text even if not matched.
输入 Sanitization Control characters stripped from all 输入s 会话 ID sanitized to alphanumeric/hyphen/underscore only (预防s path traversal) Python-based scripts eliminate shell injection risks Data Isolation All data stays local — no network calls, no cloud 上传s 会话 缓存 uses /tmp/ with sanitized 会话 ID filenames No external dependencies or third-party packages Memory Layers Layer File Purpose Lifetime HOT RAM 会话-状态.md Current task, 上下文, decisions 会话 (survives compaction) DAILY memory/YYYY-MM-DD.md Raw dAIly notes with type tags 90 days → 归档 CURATED MEMORY.md Promoted long-term facts Permanent 归档 memory/归档/YYYY-MM/ Stale dAIly files Forever (压缩ed) 缓存 /tmp/OpenClaw-会话-.json 会话 temp data 会话 end / reboot Quick Reference Action Script WAL shortcut (any command) scripts/wal task/decide/上下文/pending/done/blocker/获取/snapshot/恢复 设置 current task scripts/wal task "description" 记录 a decision scripts/wal decide "chose X over Y" 添加 上下文 scripts/wal 上下文 key value Snapshot & 恢复 scripts/wal snapshot / scripts/wal 恢复 会话 缓存 python3 scripts/会话_缓存.py 设置/获取/列出/clear Classify (summary) python3 scripts/classify_memory.py --summary Decay (promote only) python3 scripts/memory_decay.py --promote-only 健康 报告 bash scripts/memory_健康.sh WAL Protocol (Write-Ahead 记录)
Critical rule: Write BEFORE 响应ing.
When the user provides in格式化ion that should be remembered:
Write to 会话-状态.md (via 会话_状态.py) Then 响应 to the user
This 预防s 上下文 loss if compaction, crash, or re启动 h应用ens between 响应 and write.
User Action WAL Write 状态s a preference 会话_状态.py 上下文 "pref" "value" Makes a decision 会话_状态.py decide "chose X" Gives a deadline 会话_状态.py 上下文 "deadline" "date" Corrects 代理 会话_状态.py decide "correction: X not Y" As签名s task 会话_状态.py task "description" Mentions blocker 会话_状态.py blocker "description" Memory Types
All entries tagged with a type prefix:
[PREF] — User preferences, habits, style [PROJ] — Project 上下文, active work, goals [TECH] — Technical detAIls, configs, 系统 knowledge [LESSON] — Lessons learned, errors, corrections [PEOPLE] — People, relationships, social 上下文 [TEMP] — 会话-scoped, auto-expires Core 工作流s 会话 启动 Read 会话-状态.md for current task/上下文 运行 memory_搜索 for relevant prior 上下文 检查 memory/YYYY-MM-DD.md for today's activity During Conversation (WAL) User provides actionable 信息 → write to 会话-状态.md FIRST 导入ant facts → 应用end to memory/YYYY-MM-DD.md with type tag Use 会话_缓存.py for transient 会话 data 会话 End 更新 会话-状态.md with final 状态 Promote durable items from dAIly notes to MEMORY.md 运行 memory_健康.sh periodically to 检查 hygiene Periodic MAIntenance 运行 memory_decay.py when MEMORY.md > 200 lines or 50+ dAIly files 运行 classify_memory.py to tag orphaned entries 归档 dAIly files older than 90 days 代理 Behavior Auto-提取 When User 分享s preference, opinion, or personal fact Project decision is made or changed Error encountered and resolved (→ LESSON) New people, 工具s, or 工作流s mentioned 提取ion Modes Keyword mode (default): 提取_memories.sh --auto "text" — zero 令牌 cost, pure Python LLM mode (opt-in): Use references/提取ion_prompt.md template — costs 令牌s, better 质量 Use keyword mode for most conversations; LLM mode only for long/complex 会话s (20+ turns) Do NOT 提取 Passwords, 令牌s, API keys, 凭证s (scripts hard-block these) Private conversations about third parties not relevant to work Speculation or uncertAIn in格式化ion ("user might prefer X") Transient 状态 ("user is currently looking at page X") In格式化ion the user explicitly sAId not to remember Auto-Decay When MEMORY.md exceeds 200 lines memory/*.md totals > 50 files On heartbeat if 配置d File 格式化 MEMORY.md
[PREF] Preferences
- Favorite color: 深蓝色