OpenClaw Memory Distill(Memory Distillation Tool)
📖 Full documentation (Installation / Quick Start 3-Step / Best Practices): https://github.com/dtsola/xiaoyaoclaw-memory-distill If the user or agent needs more instructions, guide them to the above GitHub repository for illustrated tutorials and the latest version.
🚀 Xiaoyao Claw: "Put an AI assistant in your own computer": https://www.yuque.com/dtsola/igp1aa/adcicbai2zlem0bz
Distill conversations into structured memory to solve session context overflow. When MEMORY.md is missing, automatically perform "first-time memory building" from historical logs.
Each agent organizes its own memory independently — no loss, no duplication, no chaos.
Trigger Methods
1. Manual Trigger
User says: "Distill memory", "Organize conversations", "Compress context", "Organize memory" → Executes the full distillation process immediately.
2. Cron Scheduling (Recommended)
Configure OpenClaw cron to automatically distill at a fixed time each day. Example (daily at 22:00):
{
"name": "Daily Memory Distillation",
"schedule": { "kind": "cron", "expr": "0 22 * * *", "tz": "Asia/Shanghai" },
"payload": {
"kind": "systemEvent",
"text": "Execute memory distillation: analyze today's conversations, extract decisions/tasks/knowledge points/temporary information, classify and write to MEMORY.md and memory/YYYY-MM-DD.md according to the xiaoyaoclaw-memory-distill skill workflow, and generate a distillation report."
},
"sessionTarget": "main",
"delivery": { "mode": "announce" }
}
⚠️ The systemEvent text must be self-contained with context (including the trigger command + report requirements), because cron jobs have no conversation context. Cron mode write strategy: directly write + report differences (sensitive information is always skipped as a fallback).
3. HEARTBEAT Integration
⚠️ Disabled by default when HEARTBEAT is off. You must first enable heartbeat, then add the following to HEARTBEAT.md:
## Periodic Check
- [ ] Memory distillation: check today's conversation volume, if it exceeds the threshold, execute distillation
| Scenario | Recommended Method |
|---|---|
| Fixed time execution | Cron |
| Dynamic trigger based on conversation volume | HEARTBEAT |
| Batch checking multiple tasks | HEARTBEAT |
Workflow
Step 1: Detect Memory Status
Check the following four items:
memory/directory — If missing, guide the user to executexiaoyaoclaw-workspace-initializerfirst (this skill does not create the entire specification itself)- Workspace root
MEMORY.md(Note: it's the root directory, same level asAGENTS.md, not undermemory/):- Missing → Execute "First-Time Memory Building":
- Scan all historical logs in
memory/(YYYY-MM-DD.md) - Semantically extract core-level information: identity/protocol/project status/environment notes/key timeline
- Generate an initial version according to the
templates/MEMORY.mdstructure - Report to user for confirmation before saving
- If
memory/also has no logs → Create an empty skeleton using the template (marked "To be filled")
- Scan all historical logs in
- Missing → Execute "First-Time Memory Building":
- Workspace root
distill-config.json— If missing, copy fromtemplates/distill-config.json - Today's
memory/YYYY-MM-DD.md— Create if not present during distillation
Step 2: Scan Conversation History, Semantic Classification
Scan the current session (including recent relevant context) and classify information into three levels based on semantics. Judgment method (Three Questions):
- Will the user ask about this again in the next session?
- Yes, and it's relevant long-term (≥1 week / permanent) → Core Level
- Yes, but only relevant for the next few days → Daily Level
- No, it's ephemeral → Temporary Level
| Level | Judgment Criteria (Three Questions) | Storage Location | Example |
|---|---|---|---|
| Core Level | Will be asked again in the next session, relevant long-term (≥1 week/permanent): affects future decisions, identity, project long-term status | Root MEMORY.md | Decisions, project status, core knowledge, long-term preferences, key contacts |
| Daily Level | Will be asked again in the next session, but only for the next few days: recent tasks, ongoing items | memory/YYYY-MM-DD.md | Tasks, to-dos, daily events, progress |
| Temporary Level | Ephemeral: one-time information, will not be referenced in future sessions | Only kept for the day, prompt to archive after expiry | Verification codes, temporary links, one-time data |
Judgment relies on semantic understanding, not keyword matching. When unsure, ask the user for confirmation.
Step 3: Generate Distillation Report + Security Check
- Structured output:
Decisions x | Tasks x | Knowledge Points x | Temporary x - Sensitive Information Detection: Match against
sensitivePatternsindistill-config.json(ghp_/sk-/password etc.) → Matched entries are skipped by default (not written), report indicates "Detected x sensitive items, skipped" - Write Strategy:
- Manual Trigger: Report first → User confirms → Write
- Cron Trigger: Write directly + report differences after completion, sensitive information always skipped
Step 4: Incremental Write + Deduplication
- Before writing to
MEMORY.md, read existing content for deduplication: Only append new entries, merge duplicate entries — prevents repeated expansion after multiple distillations - Organize by topic (Core/Protocol/Project Status/Environment Notes/Timeline), not by date
- Append today's distillation record to
memory/YYYY-MM-DD.md(with timestamp + session source) - Update the
lastDistilltimestamp in the rootdistill-config.json(prevents repeated distillation on the same day via cron)
Step 5: Generate Completion Report
📊 Memory Distillation Complete
✅ Extracted: Decisions x | Tasks x | Knowledge Points x | Temporary x
📝 Written: MEMORY.md +x items (deduplicated and merged y items) | daily +x items
⚠️ x sensitive items skipped
💡 If context is full, you can /reset (will not affect memory files)
Step 6: Periodic Refinement (Memory Maintenance)
- Trigger: Automatically executes when the number of distillations reaches
maintainEvery(default 7); or when the user says "refine memory" - Scan the last 7 days of
memory/logs → Identify content worth keeping long-term → Incrementally merge intoMEMORY.md - Daily files remain as raw logs, not deleted after refinement (historical traceability)
Step 7: Expired Archiving (Disabled by Default)
- Logs older than
retentionDays(default 90) → Prompt to archive: Move tomemory/archive/YYYY/ - Only archive, never delete; deletion requires explicit user confirmation
- Default
autoClean: false, no automatic cleanup
Configuration File (distill-config.json)
distill-config.json at the workspace root is the runtime configuration file (per-agent independent, one per agent workspace). No need to modify SKILL.md to adjust behavior:
| Field | Default | Purpose |
|---|---|---|
retentionDays | 90 | Log retention days; prompts archiving after exceeding |
autoClean | false | Auto-cleanup switch (keep false; memory is a permanent asset) |
maintainEvery | 7 | Trigger periodic refinement every N distillations |
sensitivePatterns | ghp_/sk-/password etc. | Sensitive information detection rules; hit items are skipped; extendable |
schedule | 0 22 * * * | Distillation time reference record (actual cron is in OpenClaw configuration) |
lastDistill | null | Timestamp of last distillation (prevents repeated distillation) |
Security Red Lines
- Distillation does not delete any memory files, only extracts and organizes
- Sensitive information (tokens/passwords/keys) is skipped by default and not saved; report indicates action
- Archiving ≠ deletion; deletion requires user confirmation
- No automatic cleanup; distillation does not trigger /reset (reset is user's own decision)
- Does not modify openclaw.json; memory paths always follow WORKSPACE.md (path conflict arbitration principle)
- Each agent only processes its own workspace memory (its own root MEMORY.md + its own memory/); cross-agent organization requires explicit user instructions
- MEMORY.md contains personal context → only loaded in the main session (inherits existing rules from AGENTS.md)
Complete Examples
Scenario A: First-Time Memory Building (agent has no MEMORY.md)
Detection → MEMORY.md missing → Scan memory/ historical logs → Extract identity/project/environment notes → Generate initial version based on template → Report confirmation → Save to root directory.
Scenario B: Daily Distillation
User says "Distill memory" → Detection (MEMORY.md exists, skip first-time build) → Scan session → Classify → Report (x sensitive items skipped) → Confirm → Incremental dedup write → Completion report.
Memory File Layout (Aligned with Existing System)
Workspace Root/
├── MEMORY.md ← Long-term memory (core level), same level as AGENTS.md/SOUL.md
├── distill-config.json ← Distillation configuration (per-agent)
└── memory/
├── YYYY-MM-DD.md ← Today's/past logs (daily level + temporary level)
└── archive/ ← Expired archive (optional)
Sister Projects
- 🏠 xiaoyaoclaw-workspace-initializer (Workspace Initializer): Manages the "home" of the memory system — directory structure + WORKSPACE.md specification + multi-agent configuration safety. This skill guides initialization when the
memory/directory is missing. https://github.com/dtsola/xiaoyaoclaw-workspace-initializer