360 Secure SkillHub
360 安全技能中心

Dream

核心功能:基于5脑区架构,Phase1实时过滤存储有效对话(标记高权重事件),Phase2定时(早7晚10)或手动触发蒸馏,生成洞察、动作项、主题文件,更新健康指标,归档低价值内容;可整合自改进代理数据,提取复用模式,可选云端去重/矛盾处理。 典型场景:AI对话记忆管理、自我持续进化优化。 输入:对话内容、自改进代理的学习/错误日志;输出:梦境报告、主题库、模式库、健康评分;触发方式:手动说"dream"或定时cron。

luis1213899
luis1213899
热度 19.70
最近更新 2026-04-18 03:06:47
分类:知识依赖:代码执行 / 读写文件 / 第三方 API / MCP 服务 / 内部调用大模型应用场景:数据处理 / 自动化脚本 / 报告撰写 / 摘要总结 ...

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add dream-distill
Metadata
name
dream
description
Dream self-evolution skill — 5 brain-region architecture for AI memory. (1) Thalamus: attention gating (what to log). (2) Amygdala: emotional tagging (corrections/errors = high weight). (3) Hippocampus: raw memory storage (append-only logs). (4) Prefrontal Cortex: distillation planning + circuit breakers. (5) Locus Coeruleus: freshness signals for health scoring. Phase 1 logs continuously, Phase 2 cron-triggered distillation produces topics/patterns/reports. Inspired by Claude Code KAIROS, eo-ability-dream, openclaw-auto-dream. Trigger: say dream, or cron.
metadata
{"openclaw":{"requires":{"env":["OPENCLAW_WORKSPACE","OPENCLAW_BIN","OPENCLAW_SCRIPT","OPENCLAW_PATH","DREAM_MORNING_JOB_ID","DREAM_NIGHT_JOB_ID"],"bins":["python3"]},"notes":"Required env vars: OPENCLAW_WORKSPACE (workspace root), OPENCLAW_BIN (node binary),\nOPENCLAW_SCRIPT (openclaw entry point), OPENCLAW_PATH (openclaw binary path),\nDREAM_MORNING_JOB_ID / DREAM_NIGHT_JOB_ID (cron job IDs for date injection).\n\nCron editing: update-cron-date.py modifies dream cron job messages via 'openclaw cron edit'.\nThis is a privileged action. Use --confirm flag to enable: python update-cron-date.py --confirm\n\nSwarmRecall (optional): SWARMRECALL_API_KEY enables cloud deduplication/contradiction resolution.\n"}}

Dream — Nightly Memory Distillation & Self-Evolution

现状

Phase 1(✅ 已实现): OpenClaw Hook hippocampus 监听每条消息,实时写入 memory/logs/ Phase 2(✅ 已实现): dream.py v3.3 定时蒸馏,新增 Distillation Agent 做真正的推理

完整链路

用户对话
   ↓
OpenClaw Hook: message:preprocessed
   ↓
丘脑过滤(Thalamus)→ 杏仁核标记(Amygdala)→ 海马体存储(memory/logs/)
   ↓
cron 触发(早7点/晚10点)
dream.py v3.3
   ↓
读取 hippocampus 日志 + recall store
   ↓
杏仁核标记融合 → Auditor审计 → 分析皮层模式识别 → 前额叶蒸馏规划 → 归档区 → 真相文件写回 → 梦境报告

脑区协同架构

① 丘脑(Thalamus)— 注意力门控

过滤纯问候/简单确认,只记录有意义的事件 标记类型:event / decision / correction / completed / insight / error

② 杏仁核(Amygdala)— 情绪标记

correction/error/decision/completed/insight 携带 HIGH 权重,优先蒸馏

③ 海马体(Hippocampus)— 原始存储

Phase 1:OpenClaw hook 实时追加到 memory/logs/YYYY/MM/YYYY-MM-DD.md Phase 2:dream.py 读取日志,融合 recall store,一并蒸馏

④ 前额叶(Prefrontal Cortex)— 蒸馏规划 + 执行控制

人脑中前额叶负责计划、推理、抑制冲动。核心功能是「在适当的时候做适当的事」。 Dream 中:

  • 规划:cron 触发时决定今天沉淀什么、遗忘什么
  • 抑制:断路器规则——3轮内无法完成则终止,防止死循环
  • 调度:协调分析皮层和归档区的工作顺序

⑤ 蓝斑核(Locus Coeruleus)— 警觉与新鲜度信号

人脑中蓝斑核释放去甲肾上腺素,调节警觉和注意力,对新奇事物敏感。 Dream 中:health metrics 里的 freshness 分数——最近被提及的记忆权重更高。 公式:freshness = entries_referenced_last_30_days / total_entries


Phase 1 — 丘脑 + 杏仁核 + 海马体(始终活跃)

对话进行时,三个脑区协同工作:

  1. 丘脑过滤:「这条要记吗?」→ 重要事件才写日志
  2. 杏仁核标记:correction / error 携带 [HIGH] 权重
  3. 海马体存储:追加到 memory/logs/YYYY/MM/YYYY-MM-DD.md

Phase 2 — 前额叶 + 分析皮层 + 蓝斑核(cron 或手动触发)

cron 触发时:

  1. 前额叶规划:读取今日日志 + .learnings/ + 现有 topic 文件,制定蒸馏计划
  2. 分析皮层扫描:失败模式 / 重复错误 / 用户纠正规律 → 提炼 Pattern
  3. 蓝斑核评分:计算 freshness / coverage / coherence → 更新 health metrics
  4. 归档区执行:90天未引用且低价值的条目归档
  5. 前额叶输出:梦境报告(生长指标 + 洞察 + 明日重点)

Integration with self-improving-agent

Dream reads and promotes entries from the self-improving-agent skill:

.learnings/
├── LEARNINGS.md        # Corrections, insights, best practices
├── ERRORS.md          # Command failures, integration errors
└── FEATURE_REQUESTS.md # User-requested capabilities

Distillation logic:

  • Corrections (category: correction) → promote to feedback topic
  • Recurring errors (3+ occurrences) → extract to Pattern Library
  • Errors with fixes → promote to relevant topic
  • Feature requests → create project topic if validated
  • Best practices → promote to relevant topic
  • Mark promoted entries as status: promoted

Pattern Library (from eo-ability-dream)

Patterns are reusable response templates extracted from recurring learnings:

memory/patterns/
└── p-xxx.md           # Pattern files with trigger + response

Pattern format:

---
name: pattern名称
trigger: 什么情况下触发
response: 如何响应
examples: [案例1, 案例2]
created: YYYY-MM-DD
updated: YYYY-MM-DD
---

Extraction criteria:

  • Same error occurs ≥3 times across logs
  • User-corrected mistake ≥2 times
  • Non-obvious fix discovered through debugging

Memory Taxonomy

Four memory types:

  • user — User preferences, role, goals, communication style
  • feedback — User corrections and confirmations
  • project — Project context, decisions, deadlines, tools in use
  • reference — External systems, links, credentials locations

Directory Structure

memory/
├── logs/
│   └── YYYY/MM/YYYY-MM-DD.md   # Daily append-only logs
├── topics/                      # Distilled topic memories
│   ├── user_xxx.md
│   ├── feedback_xxx.md
│   ├── project_xxx.md
│   └── reference_xxx.md
├── patterns/                    # Pattern Library (from eo-ability-dream)
│   └── p-xxx.md               # Reusable patterns
├── episodes/                    # Project narratives (from openclaw-auto-dream)
├── procedures.md               # Workflow preferences
├── archive.md                  # Compressed old entries
├── dream-log.md               # Dream cycle reports
├── index.json                 # Entry metadata (v3.0 schema)
└── MEMORY.md                   # INDEX only — points to topics

.learnings/                     # self-improving-agent
├── LEARNINGS.md
├── ERRORS.md
└── FEATURE_REQUESTS.md

Health Score (from openclaw-auto-dream)

Five metrics measured each dream cycle:

Metric Weight Formula
Freshness 0.25 entries_referenced_last_30_days / total
Coverage 0.25 categories_updated_last_14_days / 10
Coherence 0.20 entries_with_relations / total
Efficiency 0.15 max(0, 1 - line_count/500)
Reachability 0.15 graph connectivity (connected components)

Health Score = weighted sum × 100 (0-100)

Score Rating
80-100 Excellent
60-79 Good
40-59 Fair
20-39 Poor
0-19 Critical

Importance Scoring (from openclaw-auto-dream)

importance = base_weight × recency_factor × reference_boost
  • base_weight: default 1.0, 🔥HIGH = 2.0, ⚠️PERMANENT = 1.0 (skip formula)
  • recency_factor: max(0.1, 1.0 - days/180)
  • reference_boost: max(1.0, log2(refs + 1))

Archive conditions (all must be true):

  • days_since_referenced > 90
  • importance < 0.3
  • NOT ⚠️PERMANENT, NOT 📌PIN, NOT in episodes/

Optional: SwarmRecall Cloud Tier

Only active if SWARMRECALL_API_KEY environment variable is set.

SwarmRecall provides advanced cloud-side operations for large memory stores:

  • Tier 1 (server-side): deduplication clustering, importance decay, stale pruning
  • Tier 2 (agent-driven): contradiction resolution, session summarization, knowledge graph enrichment

Setup

  1. Get an API key: POST /api/v1/register with { "name": "<agent-name>" }
  2. Set environment variable: SWARMRECALL_API_KEY=<your-key>
  3. SwarmRecall is now active — Tier 1 runs automatically on configured interval

SwarmRecall Endpoints Used

  • POST /api/v1/dream — start dream cycle
  • POST /api/v1/dream/execute — run server-side ops (decay, prune)
  • GET /api/v1/dream/candidates/duplicates — find duplicate clusters
  • GET /api/v1/dream/candidates/contradictions — find conflicting memories
  • GET /api/v1/dream/candidates/stale — find prunable memories
  • PATCH /api/v1/dream/:id — report dream results

Privacy

  • Data transmitted over HTTPS to swarmrecall-api.onrender.com
  • Only your agent's existing memory data is sent — no new external data collected
  • Archived memories are soft-deleted (recoverable)
  • Tenant-isolated by owner ID and agent ID

MEMORY.md Index Format

MEMORY.md is an INDEX ONLY — one line per topic:

# MEMORY.md — Long-Term Memory Index

_Last updated: YYYY-MM-DD_

## Topics
- [Title](topics/file.md) — one-line description
- [Title](topics/file.md) — one-line description

## Patterns
- [pattern-name](patterns/p-xxx.md) — trigger summary

## Stats
- Total entries: N | Health: N/100 | Streak: N dreams

Daily Log Format

Append to memory/logs/YYYY/MM/YYYY-MM-DD.md after each significant event:

## HH:MM

- [type] content description
- completed: task name
- decision: what was decided
- correction: user feedback received
- insight: what was learned

Types: event | decision | correction | completed | insight | error | question

Cron Configuration

Two cron jobs:

  • dream-morning: 7:00 AM
  • dream-night: 10:00 PM
  • --no-deliver (writes to file only)

Cron message is updated daily via update-cron-date.py script which injects current date.

Dream Distillation Steps (v3.3)

When cron triggers:

  1. Read memory/logs/{date}.md
  2. Read .learnings/LEARNINGS.md, .learnings/ERRORS.md, .learnings/FEATURE_REQUESTS.md
  3. Read MEMORY.md, topic files, index.json, procedures.md for context
  4. Snapshot BEFORE: count entries, decisions, lessons, procedures
  5. Analyze failures:
    • Count occurrences of each error in ERRORS.md
    • Identify recurring patterns (≥3 occurrences)
    • Extract root cause
  6. Distillation Agent(新增): Run sub-agent on raw entries + learnings + health metrics → produce:
    • 3-5 genuine insights ("I learned that...")
    • 1-3 tomorrow action items
    • 0-3 topic files to write to memory/topics/
    • Health metric interpretation
  7. Write topic files (from Distillation Agent output)
  8. Update truth files (user_state.md, pending.md)
  9. Update index.json entry metadata (id, importance, tags, related)
  10. Compute health metrics → update index.json stats
  11. Archive eligible entries → append to archive.md
  12. Update MEMORY.md index (max 200 lines)
  13. Snapshot AFTER: calculate deltas
  14. Write dream report to memory/dreams/{date}.md and dream-log.md
  15. Regenerate dashboard.html if exists
  16. [Optional SwarmRecall]: If SWARMRECALL_API_KEY is set:
    • Start dream cycle: POST /api/v1/dream
    • Run server-side ops: POST /api/v1/dream/execute
    • Fetch duplicate clusters → merge redundant memories
    • Fetch contradictions → resolve conflicting entries
    • Update dream cycle with results

Dream Report Format (v3.3)

# 🌙 Dream Report — {date}

## System Status
- Raw entries: N | recall store: N | Health: {score}/100

## Health Insights
- {insight based on coherence/freshness metrics}

## Insights ("I Learned")
- {genuine insight 1}
- {genuine insight 2}

## Tomorrow's Focus
- {actionable item 1}
- {actionable item 2}

## Topic Files Written
- {filename}: {title}

## Analysis
- Recurring errors found: {list}
- Root causes identified: {analysis}

## Patterns Updated
- {pattern_name}: {change}

First Dream (post-install)

After initial setup, run a full scan of ALL existing daily logs (not just last 3 days). Compare before/after metrics and send user a First Dream Report showing:

  • How many logs scanned, entries extracted
  • Before → After table
  • Personalized reflection based on actual log content

User Prompts

  • "dream report" / "梦境报告" → read and display latest dream report
  • "dream" / "做梦" → run distillation now
  • "/dream status" → show health score, pattern count, streak, stale threads

Scripts

  • dream.py — Phase 2 蒸馏脚本(v3.3,Distillation Agent)
  • update-cron-date.py — 每日 cron 日期注入

Phase 1 启用(hippocampus hook)

Hook 目录: ~/.openclaw/hooks/hippocampus/ 已配置: openclaw.json 中 hooks.internal.entries.hippocampus: enabled: true

功能: 监听 message:preprocessed 事件,自动记录对话到 memory/logs/YYYY/MM/YYYY-MM-DD.md

丘脑过滤规则:

  • 纯问候 / 简单确认(<20字)不记录
  • 高权重标记:correction / error / decision / completed / insight

重启 gateway 后生效:

schtasks /run /tn "OpenClaw Gateway"

技能整合说明

Phase 1 + Phase 2 完整闭环(已实现)

  • Phase 1:~/.openclaw/hooks/hippocampus/ — OpenClaw hook 实时记录
  • Phase 2:dream.py v3.3 — Distillation Agent 做真正的推理,取代"444个候选topic"的列表

已整合

  • self-improving-agent → dream 的日志层(.learnings/),无需单独使用

其他AI自我进化技能定位

  • recursive-self-improvement:代码级自修复系统(错误检测→根因分析→修复→测试→验证),与 dream 是不同维度,可共存
  • dream = 记忆蒸馏 + Pattern提取 + 健康评分
  • recursive-self-improvement = 代码错误自动修复