Install
openclaw skills install agent-memory-hierarchyStructure an OpenClaw agent's memory like a computer — using a cache hierarchy (hot/warm/cold), a YAML fact store for directly addressable data, a lookup index for O(1) retrieval, and prose files only for narrative and behavioral context. Use when asked to restructure agent memory, reduce context window token usage, improve memory retrieval speed, migrate from prose-only memory to structured memory, or design a new agent memory system from scratch.
openclaw skills install agent-memory-hierarchyAgents typically store everything as prose in a single MEMORY.md. This works but wastes tokens and makes retrieval fuzzy. This skill structures memory the way computers do: hot cache, warm storage, cold archives, typed data, and a lookup index.
Facts go in YAML. Narrative goes in prose. Everything gets an index.
Three reasons:
File: MEMORY.md
Contains only:
Does NOT contain: facts, dates, numbers, file paths, IDs, project statuses, todos.
Target size: under 80 lines / ~1000 tokens.
Files: memory/facts.yaml, memory/lookup-index.md, memory/project-*.md
facts.yaml — All structured factual data:
lookup-index.md — Explicit directory table:
| I need to know... | Go here |
|---|---|
| Contact info | memory/facts.yaml → identity |
| Project statuses | memory/facts.yaml → projects |
| Book research | workspace/book-research/ |
project-*.md — Full narrative project files, loaded only when working on that project.
Files: memory/YYYY-MM-DD.md (daily logs)
Raw session logs. Never loaded automatically. Retrieved only when investigating history or refreshing long-term memory.
Follow this order when converting an existing prose-only MEMORY.md:
Read the full file and categorize every piece of information:
facts.yaml (name, email, date, number, path, ID, status)project-*.mdmemory/facts.yamlUse this schema pattern:
# memory/facts.yaml
# Structured factual data — directly addressable, token-efficient
# Last updated: YYYY-MM-DD
identity:
full_name: ...
email: ...
telegram_id: ...
health:
condition: ...
status: ...
technical:
machine: ...
os: ...
workspace: ...
paths:
api_keys: ...
error_log: ...
projects:
project_name: {file: memory/project-name.md, status: "one-line status"}
todos:
- Todo item one
- Todo item two
Rules for facts.yaml:
# Last updated: YYYY-MM-DD at topmemory/lookup-index.mdCreate a markdown table mapping "I need to know X" → exact file and section. Every project file, reference file, and key section should have an entry. This is your agent's O(1) lookup. When you need something, check here first.
Remove everything that moved to facts.yaml. What remains:
# Structured facts → memory/facts.yaml and # Find anything → memory/lookup-index.mdAfter migration, confirm:
At session start: Load MEMORY.md (hot cache) only.
When you need a specific fact: Check lookup-index.md → go directly to that file/section.
When working on a project: Load the specific project-*.md file.
When updating facts: Edit facts.yaml directly. No need to touch MEMORY.md.
When updating todos: Edit facts.yaml → todos. One place, always current.
Maintenance cadence:
facts.yaml if any facts changedMEMORY.md behavioral rules for accuracySome things resist YAML and belong in prose:
When in doubt: if it would lose meaning as a key-value pair, keep it in prose.
references/facts-yaml-template.md — copy-paste starting template for facts.yamlreferences/lookup-index-template.md — copy-paste starting template for lookup-index.md