smart-memory-plus

Complete memory system for OpenClaw agents. Combines enhanced memory management (WAL protocol, type classification, temporal decay, session cache) with context compression (conversation digests, auto-injection). Zero external dependencies. Use when: managing MEMORY.md, extracting insights from conversations, compressing long sessions, searching memories, tracking task state, or when user says "remember this", "compact", "what do you know about X", "clean up memories".

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "smart-memory-plus" with this command: npx skills add zgjq/smart-memory-plus

Smart Memory Plus

Unified memory management + context compression for OpenClaw. Zero external dependencies.

⚠️ Conflict Warning: This skill replaces both smart-memory and context-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.

Requirements

  • 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)

Security

Write Restrictions (Hard Rules)

The agent MUST use the provided scripts for ALL writes. Direct file writes are FORBIDDEN.

FileRequired ScriptForbidden
SESSION-STATE.mdsession_state.py (WAL protocol)Direct write/overwrite
memory/compacts/*.mdcompact_session.py --writeDirect write/overwrite
memory/*.md (daily notes)extract_memories.sh --auto or append via scriptDirect overwrite
MEMORY.mdmemory_decay.py --promote-onlyDirect overwrite
/tmp/openclaw-session-*.jsonsession_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:

  • Any directory outside the workspace
  • System directories (/etc, /usr, /var, /tmp except session cache)
  • User home directory root (~/.ssh, ~/.config, ~/.aws, etc.)
  • Any .* dotfile or dotdir in workspace root

Sensitive Data Protection

All write commands automatically reject inputs matching:

  • API keys/tokens (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 agent cannot bypass it.

Privacy Boundaries

  • Compacts must NOT contain: file paths, internal URLs, IPs, passwords, tokens
  • Use placeholders: <REDACTED_PATH>, <REDACTED_URL>, <INTERNAL_URL>
  • All data stays local — all scripts make zero network calls, no LLM usage

Memory Layers

LayerFilePurposeLifetime
HOT RAMSESSION-STATE.mdCurrent task, context, decisionsSession (survives compaction)
DAILYmemory/YYYY-MM-DD.mdRaw daily notes with type tags90 days → archive
CURATEDMEMORY.mdPromoted long-term factsPermanent
COMPACTmemory/compacts/YYYY-MM-DD-HHMM.mdSession digests30 max, auto-cleanup
GRAPHmemory/.index/graph.dbEntity-relation knowledge graphRebuild from source
ARCHIVEmemory/archive/YYYY-MM/Stale daily filesForever (compressed)
CACHE/tmp/openclaw-session-*.jsonSession temp dataSession end / reboot

Quick Reference

Memory Management

ActionScript
WAL shortcutscripts/wal task/decide/context/pending/done/blocker/get/snapshot/restore
Set current taskscripts/wal task "description"
Log a decisionscripts/wal decide "chose X over Y"
Add contextscripts/wal context key value
Session cachepython3 scripts/session_cache.py set/get/list/clear
Classify memoriespython3 scripts/classify_memory.py --summary/--apply
Decay & archivepython3 scripts/memory_decay.py --dry-run/--promote-only
Health reportbash scripts/memory_health.sh

Search & Relations

ActionScript
Full index rebuildpython3 scripts/memory_search_bm25.py build
Incremental updatepython3 scripts/memory_search_bm25.py update
Search memories (BM25)python3 scripts/memory_search_bm25.py search "query" [--top N]
Index statuspython3 scripts/memory_search_bm25.py status
Find related entriespython3 scripts/classify_memory.py --related "query" [--top N]
Build knowledge graphpython3 scripts/memory_graph.py build
Graph relationspython3 scripts/memory_graph.py related "entity" [--depth N]
Graph statspython3 scripts/memory_graph.py stats
Raw graph querypython3 scripts/memory_graph.py query "SELECT ..."

Context Compression

ActionScript
Extract compact (stdin)python3 scripts/compact_session.py --extract
Write compact (stdin)python3 scripts/compact_session.py --write
List compactspython3 scripts/compact_session.py --list
Read latest compactpython3 scripts/compact_session.py --latest
Compact statspython3 scripts/compact_session.py --stats

WAL Protocol (Write-Ahead Log)

Critical rule: Write BEFORE responding.

When the user provides information that should be remembered:

  1. Write to SESSION-STATE.md (via session_state.py)
  2. Then respond to the user

This prevents context loss if compaction, crash, or restart happens between response and write.

User ActionWAL Write
States 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"

Memory Types

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-expires

Core Workflows

Session Start

  1. Read SESSION-STATE.md for current task/context
  2. Search for relevant context:
    • python3 scripts/memory_search_bm25.py build (if index is stale or missing)
    • python3 scripts/memory_search_bm25.py search "current topic" (semantic search)
    • Also use memory_search (OpenClaw built-in tool) as complementary search
  3. Check for recent compacts: python3 scripts/compact_session.py --latest
    • If output exists, read it and use relevant parts as context for the session
    • This is a manual agent step — the skill does not auto-inject
  4. Check memory/YYYY-MM-DD.md for today's activity

During Conversation (WAL)

  1. User provides actionable info → write to SESSION-STATE.md FIRST
  2. Important facts → append to memory/YYYY-MM-DD.md with type tag
  3. Use session_cache.py for transient session data

Session End (Compaction)

  1. Update SESSION-STATE.md with final state
  2. If conversation > 50 turns or user says "compact":
    • Draft compact content (decisions, facts, pending, blockers)
    • Pipe through security checks: echo "content" | python3 scripts/compact_session.py --write
    • Include [TYPE] tags per smart-memory classification
  3. Promote durable items from daily notes to MEMORY.md

Periodic Maintenance

  • Run memory_decay.py when MEMORY.md > 200 lines or 50+ daily files
  • Run classify_memory.py to tag orphaned entries
  • Run memory_search_bm25.py update to refresh search index after edits
  • Run memory_graph.py build to refresh knowledge graph
  • Archive daily files older than 90 days
  • Compact auto-cleanup keeps only last 30

Agent Behavior

Auto-Extract When

  • User shares preference, opinion, or personal fact
  • Project decision is made or changed
  • Error encountered and resolved (→ LESSON)
  • New people, tools, or workflows mentioned

Extraction Mode

  • extract_memories.sh --auto "text" — keyword matching, zero token cost, fully local

Compaction Mode

  • compact_session.py --extract — regex-based extraction, zero token cost, fully local

Do NOT Extract/Compact

  • Passwords, tokens, API keys, credentials (scripts hard-block these)
  • Private conversations about third parties not relevant to work
  • Speculation or uncertain information
  • Transient state ("user is currently looking at page X")
  • Information the user explicitly said not to remember

Scripts

ScriptLanguagePurposeSecurity
session_state.pyPythonHOT RAM working memory (WAL)Sensitive data filter + sanitization
session_cache.pyPythonSession-scoped temp cacheSensitive data filter + path-safe IDs
compact_session.pyPythonContext compression & digestsPath containment + sensitive filter
extract_memories.shBashMemory extraction guide & auto-extractRead-only + sensitive filter (Python)
classify_memory.pyPythonKeyword + n-gram type classification, related searchDry-run mode, duplicate check
memory_decay.pyPythonTemporal decay & LESSON promotionDry-run mode
memory_health.shBashHealth report (stats, orphans, tokens)Read-only
memory_search_bm25.pyPythonBM25 semantic search over memoriesLocal-only, zero network
memory_graph.pyPythonSQLite knowledge graph (entities + relations)Local-only, SELECT-only queries

References

  • 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 set
  • references/memory_schema.md — Full schema and format spec

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Research

Cognee Memory System

AI知识引擎 - 6行代码实现记忆系统。remember/recall/forget/improve循环,向量+图搜索,支持OpenClaw插件。

Registry SourceRecently Updated
800Profile unavailable
Automation

Unified Memory V5

统一记忆系统 - AI Agent 专用记忆系统,支持 Context Tree、智能摘要、知识图谱、工作流引擎。零依赖,完整对标 QMD/MetaGPT

Registry SourceRecently Updated
7800Profile unavailable
Automation

Agency Agents Zh

193 个即插即用的 AI 专家角色库 - 覆盖工程、设计、营销、产品、游戏、安全、金融等 18 个部门。支持多智能体协作工作流。

Registry SourceRecently Updated
2390Profile unavailable
Automation

Claw Recall

Searchable conversation memory that survives context compaction. Indexes session transcripts into SQLite with full-text and semantic search so your agent can...

Registry SourceRecently Updated
3681Profile unavailable