Community写作与编辑github.com

dtsola/xiaoyaoclaw-memory-distill

OpenClaw memory distillation & organization: distill conversations into MEMORY.md + daily logs, first-run memory building, dedup, sensitive info skip. 中文:OpenClaw 记忆整理工具,对话蒸馏为结构化记忆。

xiaoyaoclaw-memory-distill 是什么?

xiaoyaoclaw-memory-distill is a Claude Code agent skill that openClaw memory distillation & organization: distill conversations into MEMORY.md + daily logs, first-run memory building, dedup, sensitive info skip. 中文:OpenClaw 记忆整理工具,对话蒸馏为结构化记忆。.

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add dtsola/xiaoyaoclaw-memory-distill

Installed? Explore more 写作与编辑 skills: steipete/notion, langchain-ai/langchain, bytedance/podcast-generation · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

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
ScenarioRecommended Method
Fixed time executionCron
Dynamic trigger based on conversation volumeHEARTBEAT
Batch checking multiple tasksHEARTBEAT

Workflow

Step 1: Detect Memory Status

Check the following four items:

  1. memory/ directory — If missing, guide the user to execute xiaoyaoclaw-workspace-initializer first (this skill does not create the entire specification itself)
  2. Workspace root MEMORY.md (Note: it's the root directory, same level as AGENTS.md, not under memory/):
    • 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.md structure
      • Report to user for confirmation before saving
      • If memory/ also has no logs → Create an empty skeleton using the template (marked "To be filled")
  3. Workspace root distill-config.json — If missing, copy from templates/distill-config.json
  4. 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):

  1. 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
LevelJudgment Criteria (Three Questions)Storage LocationExample
Core LevelWill be asked again in the next session, relevant long-term (≥1 week/permanent): affects future decisions, identity, project long-term statusRoot MEMORY.mdDecisions, project status, core knowledge, long-term preferences, key contacts
Daily LevelWill be asked again in the next session, but only for the next few days: recent tasks, ongoing itemsmemory/YYYY-MM-DD.mdTasks, to-dos, daily events, progress
Temporary LevelEphemeral: one-time information, will not be referenced in future sessionsOnly kept for the day, prompt to archive after expiryVerification 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 sensitivePatterns in distill-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 lastDistill timestamp in the root distill-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 into MEMORY.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 to memory/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:

FieldDefaultPurpose
retentionDays90Log retention days; prompts archiving after exceeding
autoCleanfalseAuto-cleanup switch (keep false; memory is a permanent asset)
maintainEvery7Trigger periodic refinement every N distillations
sensitivePatternsghp_/sk-/password etc.Sensitive information detection rules; hit items are skipped; extendable
schedule0 22 * * *Distillation time reference record (actual cron is in OpenClaw configuration)
lastDistillnullTimestamp of last distillation (prevents repeated distillation)

Security Red Lines

  1. Distillation does not delete any memory files, only extracts and organizes
  2. Sensitive information (tokens/passwords/keys) is skipped by default and not saved; report indicates action
  3. Archiving ≠ deletion; deletion requires user confirmation
  4. No automatic cleanup; distillation does not trigger /reset (reset is user's own decision)
  5. Does not modify openclaw.json; memory paths always follow WORKSPACE.md (path conflict arbitration principle)
  6. Each agent only processes its own workspace memory (its own root MEMORY.md + its own memory/); cross-agent organization requires explicit user instructions
  7. 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

相关技能