Unified memory management + context compression for OpenClaw. Zero external dependencies.
⚠️ Conflict Warning: This skill replaces both
smart-memoryandcontext-compactor. Do NOT install alongside either of those skills — they share the same files (SESSION-STATE.md,memory/,MEMORY.md) and will cause write conflicts.
Runtime: Python 3.10+ (standard library only), Bash 4.0+ (health/extract scripts only)
OS: Linux, macOS
Environment variables (all optional, with defaults):
OPENCLAW_WORKSPACE — Workspace root (default: ~/.openclaw/workspace)OPENCLAW_SESSION_ID — Session identifier for temp cache (default: default)The agent MUST use the provided scripts for ALL writes. Direct file writes are FORBIDDEN.
FileRequired ScriptForbiddenSESSION-STATE.md``session_state.py (WAL protocol)Direct write/overwritememory/compacts/*.md``compact_session.py --writeDirect write/overwritememory/*.md (daily notes)extract_memories.sh --auto or append via scriptDirect overwriteMEMORY.md``memory_decay.py --promote-onlyDirect overwrite/tmp/openclaw-session-*.json``session_cache.pyDirect write
Critical: Never use the agent's file-write tool directly on memory files. Always pipe through scripts — they enforce sanitization, deduplication, and append-only behavior.
The agent MUST NOT write to:
.* dotfile or dotdir in workspace rootAll write commands automatically reject inputs matching:
sk-*, GitHub ghp_*, ClawHub clh_*)password=, passwd:, etc.)-----BEGIN PRIVATE KEY-----)This is a hard block at the script level — the agent cannot bypass it.
<REDACTED_PATH>, <REDACTED_URL>, <INTERNAL_URL>LayerFilePurposeLifetimeHOT RAMSESSION-STATE.mdCurrent task, context, decisionsSession (survives compaction)DAILYmemory/YYYY-MM-DD.mdRaw daily notes with type tags90 days → archiveCURATEDMEMORY.mdPromoted long-term factsPermanentCOMPACTmemory/compacts/YYYY-MM-DD-HHMM.mdSession digests30 max, auto-cleanupGRAPHmemory/.index/graph.dbEntity-relation knowledge graphRebuild from sourceARCHIVEmemory/archive/YYYY-MM/Stale daily filesForever (compressed)CACHE/tmp/openclaw-session-*.jsonSession temp dataSession end / reboot
ActionScriptWAL shortcutscripts/wal task/decide/context/pending/done/blocker/get/snapshot/restoreSet current taskscripts/wal task "description"Log a decisionscripts/wal decide "chose X over Y"Add contextscripts/wal context key valueSession cachepython3 scripts/session_cache.py set/get/list/clearClassify memoriespython3 scripts/classify_memory.py --summary/--applyDecay & archivepython3 scripts/memory_decay.py --dry-run/--promote-onlyHealth reportbash scripts/memory_health.sh
ActionScriptFull index rebuildpython3 scripts/memory_search_bm25.py buildIncremental updatepython3 scripts/memory_search_bm25.py updateSearch memories (BM25)python3 scripts/memory_search_bm25.py search "query" [--top N]Index statuspython3 scripts/memory_search_bm25.py statusFind related entriespython3 scripts/classify_memory.py --related "query" [--top N]Build knowledge graphpython3 scripts/memory_graph.py buildGraph relationspython3 scripts/memory_graph.py related "entity" [--depth N]Graph statspython3 scripts/memory_graph.py statsRaw graph querypython3 scripts/memory_graph.py query "SELECT ..."
ActionScriptExtract compact (stdin)python3 scripts/compact_session.py --extractWrite compact (stdin)python3 scripts/compact_session.py --writeList compactspython3 scripts/compact_session.py --listRead latest compactpython3 scripts/compact_session.py --latestCompact statspython3 scripts/compact_session.py --stats
Critical rule: Write BEFORE responding.
When the user provides information that should be remembered:
session_state.py)This prevents context loss if compaction, crash, or restart happens between response and write.
User ActionWAL WriteStates a preferencesession_state.py context "pref" "value"Makes a decisionsession_state.py decide "chose X"Gives a deadlinesession_state.py context "deadline" "date"Corrects agentsession_state.py decide "correction: X not Y"Assigns tasksession_state.py task "description"Mentions blockersession_state.py blocker "description"
All entries tagged with a type prefix:
[PREF] — User preferences, habits, style[PROJ] — Project context, active work, goals[TECH] — Technical details, configs, system knowledge[LESSON] — Lessons learned, errors, corrections[PEOPLE] — People, relationships, social context[TEMP] — Session-scoped, auto-expiresSESSION-STATE.md for current task/contextpython3 scripts/memory_search_bm25.py build (if index is stale or missing)python3 scripts/memory_search_bm25.py search "current topic" (semantic search)memory_search (OpenClaw built-in tool) as complementary searchpython3 scripts/compact_session.py --latest
memory/YYYY-MM-DD.md for today's activitymemory/YYYY-MM-DD.md with type tagsession_cache.py for transient session dataSESSION-STATE.md with final stateecho "content" | python3 scripts/compact_session.py --write[TYPE] tags per smart-memory classificationMEMORY.mdmemory_decay.py when MEMORY.md > 200 lines or 50+ daily filesclassify_memory.py to tag orphaned entriesmemory_search_bm25.py update to refresh search index after editsmemory_graph.py build to refresh knowledge graphextract_memories.sh --auto "text" — keyword matching, zero token cost, fully localcompact_session.py --extract — regex-based extraction, zero token cost, fully localScriptLanguagePurposeSecuritysession_state.pyPythonHOT RAM working memory (WAL)Sensitive data filter + sanitizationsession_cache.pyPythonSession-scoped temp cacheSensitive data filter + path-safe IDscompact_session.pyPythonContext compression & digestsPath containment + sensitive filterextract_memories.shBashMemory extraction guide & auto-extractRead-only + sensitive filter (Python)classify_memory.pyPythonKeyword + n-gram type classification, related searchDry-run mode, duplicate checkmemory_decay.pyPythonTemporal decay & LESSON promotionDry-run modememory_health.shBashHealth report (stats, orphans, tokens)Read-onlymemory_search_bm25.pyPythonBM25 semantic search over memoriesLocal-only, zero networkmemory_graph.pyPythonSQLite knowledge graph (entities + relations)Local-only, SELECT-only queries
references/extraction_prompt.md — Extraction prompt template (for agent-internal use)references/compaction_prompt.md — Compaction prompt template (for agent-internal use)references/decay_rules.md — Decay/archival rule setreferences/memory_schema.md — Full schema and format spec