AgentSkillsCN

openclaw-mem

面向AI代理的本地优先RAG记忆系统。采用渐进式披露搜索,自动捕获会话数据,为每个项目建立专属的“大脑”目录,并具备注入防御机制。

SKILL.md
--- frontmatter
name: openclaw-mem
description: "Local-first RAG memory system for AI agents. Progressive Disclosure search, Auto-Capture from sessions, Brain directories for per-project context, injection defense."
version: 0.2.0
author: kjaylee
tags: [memory, rag, embeddings, local-first, brain]

openclaw-mem

Local-first RAG memory system for AI agents. No API keys required — runs 100% offline with local embeddings.

Installation

bash
pip install openclaw-mem
openclaw-mem init

This creates the workspace structure:

code
./memory/
├── core.md           # Key decisions & lessons learned
├── observations.md   # Structured observations
└── projects/         # Brain directories (per-project context)
.env                  # OPENCLAW_MEM_ROOT configuration

Key Commands

CommandDescription
openclaw-mem search "query"Semantic search over memory
openclaw-mem index --allIndex all markdown files
openclaw-mem index --changedIncremental index (changed files only)
openclaw-mem observe "text" --tag learningRecord a structured observation
openclaw-mem auto-capture --since 6hExtract observations from session transcripts
openclaw-mem auto-capture --since 6h --route-to-brainAuto-route observations to Brain files
openclaw-mem brain-checkCheck Brain files for injection patterns
openclaw-mem brain-check --fixAuto-fix injection patterns
openclaw-mem archive --executeArchive old memory (3-Layer: Hot/Warm/Cold)

Brain Directories

Per-project persistent context stored in memory/projects/{name}.md:

bash
# Create a project Brain
echo "# My Project Brain\n\n## Architecture\n- Stack: Python + FastAPI\n" > memory/projects/my-project.md

# Index it
openclaw-mem index memory/projects/my-project.md

# Search across all Brains
openclaw-mem search "project architecture"

# Verify integrity
openclaw-mem brain-check

Progressive Disclosure (2-Step Search)

Reduces token usage by returning summaries first, then full content on demand:

bash
# Step 1: Get summaries (index view)
openclaw-mem search "deployment" --index
# Returns: chunk IDs + one-line summaries

# Step 2: Get full content for a specific chunk
openclaw-mem search --detail "chunk:0:abc123"
# Returns: full chunk text

Observation Tags

Tag observations for structured knowledge capture:

bash
openclaw-mem observe "Redis cache TTL should be 1h" --tag decision
openclaw-mem observe "Always test with --dry-run first" --tag learning
openclaw-mem observe "Forgot to check edge case" --tag mistake
openclaw-mem observe "Service mesh pattern works well" --tag architecture
openclaw-mem observe "User prefers dark mode" --tag preference
openclaw-mem observe "Next: add WebSocket support" --tag next

Environment Variables

VariableDefaultDescription
OPENCLAW_MEM_ROOT.Workspace root directory
OPENCLAW_MEM_DB_PATH{root}/lance_dbLanceDB database path
OPENCLAW_MEM_TABLEmemoryLanceDB table name
OPENCLAW_MEM_BACKENDlocalEmbedding backend: local, openai, ollama
OPENCLAW_MEM_MODELall-MiniLM-L6-v2Embedding model name
OPENCLAW_MEM_ARCHIVE_DIR{root}/archiveArchive directory
OPENCLAW_MEM_ARCHIVE_DAYS30Days before auto-archiving
OPENCLAW_MEM_SESSION_DIR{root}/sessionsSession transcripts directory

Security

  • Injection Defense: Brain files are scanned for prompt injection patterns
  • Sanitizer: All indexed content passes through the injection sanitizer
  • Local-first: No data leaves your machine — embeddings run locally