SuperAPI AI Directory

memory-management

Agents & models

View repository

Updated 10-16 16:26

About this skill

Memory Management

Cross-session memory management based on openclaw-mem. Agents forget everything when a session ends — this skill structures their memory.

Environment setup

export OPENCLAW_MEM_ROOT=$WORKSPACE/.openclaw/workspace
MEM=$WORKSPACE/.openclaw/workspace/openclaw-mem/.venv/bin/openclaw-mem

In all commands, $MEM refers to the path above.


1. Five-layer memory structure

Layer File/system Characteristics Size limit
L0 memory/core.md Hot cache, always loaded Strictly <2KB
L1 memory/working-memory.md Current task focus, volatile Unrestricted
L2 memory/decisions.md Master decision log, append-only Unlimited (archive periodically)
L3 memory/YYYY-MM-DD.md + memory/handoffs/ Episodic memory Keep the most recent 7 days
L4 LanceDB (rag/lancedb/) Semantic search across the entire workspace Managed automatically

Reading order: L0 → L1 → L2 (recent) → search L3/L4 as needed


2. Session lifecycle

Session start (MUST)

# 1. 이전 세션 핸드오프 읽기
$MEM handoff read

# 2. 워킹 메모리 확인
$MEM working-memory show

# 3. 최근 결정 확인
$MEM decision list --last 5

Use the output of the three commands to understand "what you were working on" before starting work.

During the session

When an important decision is made, record it immediately :

# Master가 결정한 사항
$MEM decision log "Rust+Godot 전용, JS/TS 금지" --tag master

# 에이전트 학습/인사이트
$MEM observe "LanceDB 인덱싱은 --changed가 --all보다 10x 빠름" --tag learning

# 에러 기록
$MEM observe "Godot export 시 --headless 필수" --tag error

If working memory has changed:

$MEM working-memory set "현재 포커스: NAS 마이그레이션 Phase 2"
$MEM working-memory update "추가: DNS 전파 대기 중"

Session end (MUST)

# 1. 핸드오프 노트 작성 (다음 세션 자신에게)
$MEM handoff write "블로그 배포 완료. 남은 작업: 게임 페이지 스크린샷 4장"

# 2. 워킹 메모리 갱신
$MEM working-memory set "다음: 게임 스크린샷 촬영 → 블로그 게임 포스트 완성"

# 3. 변경된 파일 인덱싱
$MEM index --changed

3. Brain management

Brain = memory/projects/{name}.md — persistent context for each project.

Creation

cat > memory/projects/eastsea-blog.md << 'EOF'
# eastsea-blog Brain
## Stack: Hugo + GitHub Pages
## Repo: eastsea-blog/
## Deploy: git push → GitHub Actions → pages
## 주의: baseURL은 https://eastsea.xyz
EOF

Update principles

  • When a fact changes, update the Brain immediately (stale information is harmful)
  • Keep the size <1KB — the full content is injected into subagent context.
  • Record decisions in L2 (decisions.md), not in the Brain.

Injecting the Brain into subagents

When spawning a subagent:

  1. Read the Brain file and include its content in the prompt.
  2. Instead of saying "read the Brain first," inject its content directly
  3. Do not inject the entire AGENTS.md — include only the Brain and task-specific rules.

4. Memory hygiene

L0 hot-cache management (core.md <2KB)

wc -c memory/core.md  # 2048 초과 시 정리 필요

If the limit is exceeded, move older or less important items to L2 or L4.

Archiving

# 드라이런 (무엇이 아카이브될지 확인)
$MEM archive --days 30

# 실행
$MEM archive --days 30 --execute

# 아카이브 후 재인덱싱
$MEM archive --reindex

When to reindex RAG

Event Command
Daily at 01:00 KST (cron) $MEM index --changed
After bulk file changes $MEM index --all
After archiving $MEM archive --reindex
Manually add a specific file $MEM index path/to/file.md

Episodic cleanup

memory/YYYY-MM-DD.md is eligible for archiving after 7 days. memory/handoffs/follows the same rule.


5. openclaw-mem CLI reference

search — semantic search (Progressive Disclosure)

$MEM search "배포 프로세스" --top-k 5     # 기본 검색
$MEM search "배포" --index                 # Step 1: 요약만
$MEM search --detail "chunk:0:abc123"      # Step 2: 전체 내용
$MEM search "에러" --tag error             # 태그 필터
$MEM search "Godot" --source memory --raw  # 소스 필터 + 사람 읽기용

index — vector database indexing

$MEM index --changed          # 변경된 파일만 (일상용)
$MEM index --all              # 전체 재인덱싱
$MEM index path/to/file.md   # 단일 파일

observe — record structured observations

$MEM observe "텍스트" --tag learning   # learning|decision|error|insight

working-memory — volatile working buffer

$MEM working-memory show               # 현재 상태
$MEM working-memory set "새 포커스"     # 전체 교체
$MEM working-memory update "추가 내용"  # 덧붙이기
$MEM working-memory clear              # 초기화

decision — decision log (append-only)

$MEM decision log "결정 내용" --tag master  # 기록
$MEM decision list --last 10               # 최근 10개
$MEM decision search "Rust"                # 키워드 검색

handoff — session handoff

$MEM handoff write "핸드오프 내용"   # 작성
$MEM handoff read                   # 최신 읽기
$MEM handoff history                # 히스토리

archive — cold storage

$MEM archive                        # 드라이런
$MEM archive --execute              # 실행
$MEM archive --reindex              # 아카이브 인덱싱
$MEM archive --days 14 --execute    # 14일 기준

auto-capture — automatic extraction from session transcripts

$MEM auto-capture --since 6h        # 최근 6시간
$MEM auto-capture --file session.md # 특정 파일
$MEM auto-capture --dry-run         # 미리보기

Prohibitions

  • ❌ Writing more than 2KB to core.md
  • ❌ Editing or deleting decisions.md entries (append-only)
  • ❌ Ending a session without a handoff
  • ❌ Dumping the entire memory/ directory into a subagent
  • ❌ --all indexing overuse (reindexing everything when nothing has changed)