← 返回
未分类

Agent Memory Hierarchy

Structure 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 ind...
将 OpenClaw 代理的记忆结构得像计算机一样——采用缓存层次(热/温/冷),使用 YAML 事实库实现直接可寻址的数据,并提供查找索引...
kimmi2ue kimmi2ue 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 305
下载
💾 0
安装
1
版本
#latest

概述

Agent Memory Hierarchy

Agents 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.

Core Principle

Facts go in YAML. Narrative goes in prose. Everything gets an index.

Three reasons:

  1. YAML is ~40% more token-efficient than prose for the same information
  2. Specific facts become directly addressable — no semantic search needed
  3. Separation of concerns: behavioral rules, narrative context, and facts are distinct problems

The Three-Layer Architecture

Layer 1 — Hot Cache (always in context)

File: MEMORY.md

Contains only:

  • Identity summary (2-3 lines)
  • Behavioral rules (how the agent must behave)
  • Standing permissions
  • Narrative context that needs interpretation (relationships, mission, origin story)
  • Pointers to Layer 2

Does NOT contain: facts, dates, numbers, file paths, IDs, project statuses, todos.

Target size: under 80 lines / ~1000 tokens.

Layer 2 — Warm Storage (loaded on demand)

Files: memory/facts.yaml, memory/lookup-index.md, memory/project-*.md

facts.yaml — All structured factual data:

  • Identity facts (name, contact, IDs)
  • Dates and numbers (age, salary, target year, budget)
  • File paths and system config
  • Project statuses (one-line each, with pointer to full file)
  • Outstanding TODOs
  • Services and accounts

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.

Layer 3 — Cold Storage (rarely accessed)

Files: memory/YYYY-MM-DD.md (daily logs)

Raw session logs. Never loaded automatically. Retrieved only when investigating history or refreshing long-term memory.


Migration Process

Follow this order when converting an existing prose-only MEMORY.md:

Step 1: Audit existing MEMORY.md

Read the full file and categorize every piece of information:

  • Fact → moves to facts.yaml (name, email, date, number, path, ID, status)
  • Behavioral rule → stays in MEMORY.md
  • Narrative/context → stays in MEMORY.md (relationship descriptions, quotes, origin stories)
  • Project detail → moves to or stays in project-*.md

Step 2: Build memory/facts.yaml

Use 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:

  • Flat where possible, nested where grouping helps
  • One-line values only — no multi-line prose
  • If a value needs explanation, it belongs in MEMORY.md prose instead
  • Add # Last updated: YYYY-MM-DD at top

Step 3: Build memory/lookup-index.md

Create 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.

Step 4: Rewrite MEMORY.md

Remove everything that moved to facts.yaml. What remains:

  • 2-3 line identity/mission summary
  • Behavioral rules (explicit, imperative)
  • Standing permissions
  • Narrative sections that require context to understand
  • Pointers: # Structured facts → memory/facts.yaml and # Find anything → memory/lookup-index.md

Step 5: Verify

After migration, confirm:

  • [ ] Every fact in old MEMORY.md is now in facts.yaml
  • [ ] lookup-index.md covers every project and reference file
  • [ ] MEMORY.md contains no facts (no dates, numbers, paths, IDs)
  • [ ] New MEMORY.md is under 80 lines
  • [ ] Agent can answer "where is X?" using lookup-index.md without searching

Using the Architecture Day-to-Day

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:

  • After each session: update facts.yaml if any facts changed
  • Weekly: review MEMORY.md behavioral rules for accuracy
  • Monthly: read recent daily logs, distill lessons into MEMORY.md, archive old logs

What NOT to Structure

Some things resist YAML and belong in prose:

  • Relationship dynamics ("she calls me Mols, treat her like a friend not a user")
  • Emotional context ("Kim feels like the one who got skipped")
  • Mission statements and quotes
  • Lessons learned with nuance ("DALL-E 3 is inconsistent for coloring pages — use Canva AI instead")
  • Anything where the why matters as much as the what

When in doubt: if it would lose meaning as a key-value pair, keep it in prose.


Reference Files

  • references/facts-yaml-template.md — copy-paste starting template for facts.yaml
  • references/lookup-index-template.md — copy-paste starting template for lookup-index.md

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-21 14:08 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-agent

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,396 📥 322,575
ai-agent

Find Skills

guipi888
场景驱动+关键词双模式技能发现工具。当用户用自然语言描述场景/需求(如"我想做一个海报""帮我分析股票"),或明确说"安装技能/find skills/找个skill"时,自动从官方内置、本地已安装、SkillHub、虾评、GitHub、C
★ 1,461 📥 518,890
it-ops-security

Skill Sentinel

kimmi2ue
通过在首次使用前审计新安装的技能,检测红旗模式,并强制执行硬限制,防止恶意或已受损的 OpenClaw 技能造成危害。
★ 0 📥 327