> 🧠 v5.1 技能进化插件 — AI自主学习、用进废退、全自动技能开发 + 完整每日汇报
Phase 3(✅ 已实现): OpenClaw Hook hippocampus 监听每条消息,实时写入 memory/logs/
Phase 3(✅ 已实现): dream.py v4.x 定时蒸馏 + M-FLOW Bundle Search检索
Phase 3(✅ 已实现): dream.py v4.x Long-Term RAG 长记忆层
Phase 4(✅ 已实现): dream.py v5.0 技能用进废退 + 全自动技能开发 + 完整每日汇报
extensions/skill_explorer/gap_detector.py v2.0 整合 skill-evolver 核心逻辑:
| 新增方法 | 功能 |
|---|---|
| --------- | ------ |
get_active_capabilities() | 从 ~/.skill_scoreboard/scores.json 推断用户能力需求 |
scan_shared_skills() | 扫描 ~/SharedSkills/ 所有技能清单 |
detect_gaps_from_scores() | 基于评分数据检测能力缺口(比原有任务分析更精准) |
generate_skill_draft() | 为缺口生成完整 SKILL.md 草稿(含触发词、使用场景、步骤、工具) |
detect_and_generate() | 一次性执行缺口检测 + 草稿生成 + 过时技能扫描 |
SKILL.md 草稿模板库(已实现):
| 能力 | 生成的技能名 | 触发词示例 |
|---|---|---|
| ------ | ------------ | ----------- |
| 搜索/研究 | deep-researcher | 帮我调研、搜索论文 |
| 图片生成 | image-generator | AI画图、生成插画 |
| 网页抓取 | web-scraper | 爬取数据、提取网页内容 |
| Shell命令 | shell-automation | 写脚本、批处理 |
| Git操作 | git-assistant | commit、PR、解决冲突 |
| 飞书集成 | feishu-integration | 飞书文档、飞书消息 |
| 视频生成 | video-generator | 生成视频、AI视频 |
| 文档总结 | doc-summarizer | 总结文档、长文章摘要 |
| 数据分析 | data-analyst | 分析数据、生成图表 |
| PPT制作 | ppt-generator | 制作PPT、演示文稿 |
| 翻译 | translator | 中英互译、润色英文 |
| 通用 | {能力英文名} | 能力名本身 |
E6/E8 流程更新(dream.py v5.1):
GapDetector.detect_and_generate() → 同时获取缺口列表 + SKILL.md 草稿generate_skill_draft() 生成完整草稿~/SharedSkills/{skill_name}/SKILL.mdscripts/main.pyskill_development.drafts 字段与 skill-evolver 共用数据源:~/.skill_scoreboard/scores.json
| 模块 | 功能 | 关键类 |
|---|---|---|
| ------ | ------ | -------- |
| skill_evolution | 技能评分(调用×质量×衰减)+ 用进废退引擎 + 技能注册表 | SkillScorer, DecayEngine, SkillRegistry |
| work_review | 工作复盘分析 + 明日计划生成 | WorkAnalyzer, TomorrowPlanner |
| skill_explorer | 技能缺口检测 + 自主学习 | GapDetector, SkillLearner |
| skill_developer | 全自动技能生成(AI生成+质量评估+注册) | SkillGenerator, SkillQualityAssessor |
| reporter | 每日完整汇报(六大模块) | DailyReporter, SkillReportGenerator |
技能活跃度 = 调用次数 × 质量系数 × 时间衰减
| 等级 | 标识 | 分值范围 | 说明 |
|---|---|---|---|
| ------ | ------ | ---------- | ------ |
| 高度活跃 | 🔥 | ≥80 | 调用频繁,持续进化 |
| 正常 | 📈 | 60-79 | 稳定使用 |
| 低活跃 | 💤 | 40-59 | 使用较少,建议复习 |
| 休眠 | 🗄️ | 20-39 | 长期未用,待激活 |
| 已归档 | ⚰️ | <20 | 彻底停用 |
衰减规则:
与早7点+晚10点蒸馏同步执行,完整汇报保存为 daily-report-YYYY-MM-DD.md:
extensions/
├── __init__.py
├── skill_evolution/ # 用进废退核心
│ ├── scorer.py # 技能评分器
│ ├── decay.py # 衰减引擎
│ └── registry.py # 技能注册表
├── work_review/ # 工作复盘
│ ├── analyzer.py # 工作分析器
│ └── planner.py # 明日计划生成器
├── skill_explorer/ # 技能探索
│ ├── gap_detector.py # 缺口检测器
│ └── learner.py # 技能学习器
├── skill_developer/ # 技能开发
│ ├── templates.py # 技能模板库
│ ├── generator.py # 技能生成器
│ └── quality.py # 质量评估器
└── reporter/ # 汇报生成
├── daily_report.py # 每日汇报生成器
└── skill_report.py # 技能专项报告
参考 MetaGPT 的 RoleZeroLongTermMemory 设计,新增短长记忆合并机制:
short-term-recall.json ← 活跃recall条目(上限200条)
memory/.rag/longterm.jsonl ← 老旧条目RAG存储
晋升条件:
召回流程:
效果: 记忆越来越精准,不像以前每次都从零开始。
用户对话
↓
OpenClaw Hook: message:preprocessed
↓
丘脑过滤(Thalamus)→ 杏仁核标记(Amygdala)→ 海马体存储(memory/logs/)
↓
cron 触发(早7点/晚10点)
dream.py v4.x
↓
[4.5] RAG查询 — 从当日条目提取关键词 → 查询memory/.rag/longterm.jsonl → 注入蒸馏上下文
↓
Bundle Search检索(替代简单grep)
↓
杏仁核标记融合 → Auditor审计 → 分析皮层模式识别 → 前额叶蒸馏规划
↓
[4.6] RAG晋升 — 30天+未召回条目 → 写入longterm.jsonl
↓
归档区 → 真相文件写回 → 梦境报告
所有记忆组织为四层有向图,形成倒锥结构:
锥尖(容易精确命中)
↓
┌─────────────────────────┐
│ L4 Entity │ ← 用户/项目/系统等实体节点
│ L3 FacetPoint │ ← 具体属性、特征、标签
│ L2 Facet │ ← 一组相关特征
│ L1 Episode(锥底) │ ← 最终返回的知识单元
└─────────────────────────┘
锥底(返回给用户)
搜索逻辑(Bundle Search):
三条核心设计原则:
| 原则 | 说明 | 对应效果 |
|---|---|---|
| ------ | ------ | --------- |
| 边携带语义 | 每条边附带自然语言描述,参与检索 | 不是被动连接,是主动语义过滤器 |
| 路径最小代价 | 一条强证据链就足以证明相关性 | 不被无关路径稀释分数 |
| 惩罚直接命中Episode | 直接匹配摘要反而加惩罚 | 偏好精准锚点路径,防止宽泛匹配 |
① 丘脑(Thalamus)— 注意力门控
> 过滤纯问候/简单确认,只记录有意义的事件
> 标记类型:event / decision / correction / completed / insight / error
② 杏仁核(Amygdala)— 情绪标记
> correction/error/decision/completed/insight 携带 HIGH 权重,优先蒸馏
③ 海马体(Hippocampus)— M-FLOW图存储 + RAG
Phase 1:memory/logs/ 追加日志(Episode层)
Phase 2:构建M-FLOW图结构:
Episode (L1) ← daily log / topic file
↓ semantic edge
Facet (L2) ← grouping: correction_group, project_xxx
↓ semantic edge
FacetPoint (L3) ← specific tag: error.timeout, user.pref
↓ semantic edge
Entity (L4) ← user, project, tool, skill
FacetPoint = type + topic + keywords 的向量描述(向量化后参与Bundle Search)
语义边描述 = "这个FacetPoint为什么属于这个Episode" 的自然语言说明
④ 前额叶(Prefrontal Cortex)— Bundle Search + RAG召回 + 蒸馏规划
Bundle Search检索替代简单grep:
查询 → 向量化 → 4层锥形搜索 → 代价传播 → 最小路径Episode
RAG召回(v4.x新增):
当日关键词 → 查询longterm.jsonl → 召回相关旧记忆 → 注入蒸馏上下文
⑤ 蓝斑核(Locus Coeruleus)— 警觉与新鲜度信号
> freshness分数——最近被提及的记忆权重更高
memory/
├── .dreams/
│ └── short-term-recall.json # 活跃recall条目(上限200条)
└── .rag/
└── longterm.jsonl # 老旧条目RAG存储(JSONL格式)
# 晋升条件
if age_days > 30 and recall_count < 3:
promote_to_longterm_rag(entry)
# 蒸馏前
keywords = [v['snippet'][:100] for v in tagged.values()][:20]
query = ' '.join(keywords[:5])
rag_results = query_longterm_rag(query, k=5)
# 召回结果注入蒸馏上下文
learnings['LEARNINGS.md'] += f"\n\n## Long-Term Memory (RAG)\n{rag_text}"
# 查看短/长记忆状态
python skills/dream-selfimproving/scripts/longterm_rag.py --status
# 手动晋升老条目
python skills/dream-selfimproving/scripts/longterm_rag.py --promote
# 搜索长记忆
python skills/dream-selfimproving/scripts/longterm_rag.py --query "关键词"
Patterns are reusable response templates extracted from recurring learnings:
memory/patterns/
└── p-xxx.md # Pattern files with trigger + response
Pattern格式(含M-FLOW元数据):
---
name: pattern名称
trigger: 什么情况下触发
response: 如何响应
examples: [案例1, 案例2]
created: YYYY-MM-DD
updated: YYYY-MM-DD
# M-FLOW 元数据
entity: pattern # L4 Entity
facets: [tag1, tag2] # L3 FacetPoints
episode_id: p-xxx # L1 Episode
---
| Memory Type | L4 Entity | L3 FacetPoints | L1 Episode |
|---|---|---|---|
| ------------ | ----------- | ----------------- | -------------- |
| user | user.luyi | role, pref, goal, communication_style | topics/user_*.md |
| feedback | feedback | correction, error, insight, confirmation | topics/feedback_*.md |
| project | project.{name} | decision, tool, deadline, context | topics/project_*.md |
| reference | reference | credential, link, skill, system | topics/reference_*.md |
| longterm | (RAG) | aged, promoted | .rag/longterm.jsonl |
memory/
├── graph/ # M-FLOW 知识图谱
│ ├── entities.json # L4 Entity 节点列表
│ ├── facetpoints.json # L3 FacetPoint 节点列表
│ ├── facets.json # L2 Facet 节点列表
│ ├── episodes.json # L1 Episode 节点列表
│ ├── edges.json # 语义边(含描述文本)
│ └── index.json # 图索引 + 向量锚点
├── logs/
│ └── YYYY/MM/YYYY-MM-DD.md # Daily append-only logs (Episode)
├── topics/ # Distilled topic memories
│ ├── user_xxx.md
│ ├── feedback_xxx.md
│ ├── project_xxx.md
│ └── reference_xxx.md
├── patterns/ # Pattern Library
│ └── p-xxx.md
├── episodes/ # Project narratives
├── .dreams/
│ └── short-term-recall.json # 活跃recall条目(上限200条)
├── .rag/
│ └── longterm.jsonl # Long-Term RAG(v4.x新增)
├── procedures.md # Workflow preferences
├── archive.md # Compressed old entries
├── dream-log.md # Dream cycle reports
└── MEMORY.md # INDEX only
.learnings/ # self-improving-agent
├── LEARNINGS.md
├── ERRORS.md
└── FEATURE_REQUESTS.md
| Metric | Weight | Formula |
|---|---|---|
| -------- | -------- | --------- |
| Freshness | 0.20 | entries_referenced_last_30_days / total |
| Coverage | 0.20 | categories_updated_last_14_days / 10 |
| Coherence | 0.20 | entries_with_semantic_edges / total |
| Graph Connectivity | 0.20 | connected_components_ratio |
| Efficiency | 0.10 | max(0, 1 - line_count/500) |
| Reachability | 0.10 | Bundle Search路径覆盖率 |
When cron triggers:
memory/logs/{date}.md.learnings/LEARNINGS.md, .learnings/ERRORS.md, .learnings/FEATURE_REQUESTS.mdMEMORY.md, topic files, graph/index.json, procedures.md for contextscore_tracker.py today,获取今日技能王 + 调用统计,注入蒸馏上下文memory/topics/graph/episodes.jsongraph/facetpoints.jsongraph/edges.json(含语义描述)user_state.md, pending.md)graph/index.json entry metadata + 重新计算向量锚点graph/index.json statsarchive.mdMEMORY.md index (max 200 lines)memory/dreams/{date}.md and dream-log.mddaily-report-{date}.md 完整六大模块汇报# 🌙 Dream Report — {date}
## 🧠 系统状态
- 原始日志条目 | recall store 总数 | Auditor AI味 | 蓝斑核健康
## 🫀 蓝斑核健康评分 (v4.0 M-FLOW)
- 新鲜度 | 连贯性 | 覆盖度 | 图连通性 | 效率 | 可达性
## 🧠 M-FLOW 知识图谱状态
- L4 Entity | L3 FacetPoint | L1 Episode | 语义边
- Bundle Search 结果
## 🏆 技能积分榜(v4.x 新增)
- 今日技能王 + 调用次数 + 积分
- 原始榜单摘要(若有数据;无数据时此节不显示)
## 💡 我学到了
- {genuine insight 1(含技能积分洞察)}
- {genuine insight 2}
## 🎯 明日重点
- {actionable item 1}
- {actionable item 2}
## 🔁 重复模式(≥3次)
## 🗄️ 归档候选
## Patterns Updated
此脚本用于修改 OpenClaw cron 作业,属于特权操作。
--confirm 标志是安全机制,防止意外执行```bash
openclaw cron list
```
metadata.openclaw.requires.env.SWARMRECALL_API_KEY此技能会访问和修改以下位置的文件:
~/.openclaw/workspace/memory/logs/ — 对话日志~/.openclaw/workspace/memory/.dreams/ — 梦境报告~/.openclaw/workspace/memory/.rag/ — 长记忆 RAG 存储~/.openclaw/workspace/memory/.truth/ — 真相文件~/.openclaw/workspace/memory/.learnings/ — 学习记录~/.openclaw/hooks/hippocampus/ — Hook 配置诊断参考: references/diagnostic-checklist.md — 快速健康检查命令清单
问题现象:
memory/logs/YYYY/MM/ 月份目录不存在时,append_to_log() 会静默失败(不抛异常)mkdir(parents=True, exist_ok=True) 只创建最后一级目录;如果 YYYY/ 存在但 MM/ 不存在,且代码写的是 mkdir("2026/05", parents=True) → 不会创建 2026/ 本身log_dir = LOGS_DIR / year / month 后直接 ensure_dir(log_dir),如果 2026/ 存在但 05/ 不存在 → 正常创建;但如果整个 YYYY/ 不存在则失败排查:
ls -la ~/.openclaw/workspace/memory/logs/2026/
# 如果 05/ 目录不存在,说明本月还没有消息被记录
手动修复:
mkdir -p ~/.openclaw/workspace/memory/logs/2026/05
问题现象:
generated_at 与日志日期不匹配排查步骤:
~/.skill_scoreboard/daily/ 文件时间戳是否连续~/.hermes/cron/output/ 是否有对应日志openclaw cron list 确认实际 cron 配置(如果 openclaw CLI 可用)问题: 在 WSL 环境中访问 localhost:3012(OpenClaw-Admin)可能失败,Chrome 报错 libnspr4.so: cannot open shared object file
解决: 不依赖浏览器,用 API 直接调 OpenClaw:
# 查看 cron 任务
openclaw cron list
# 查看环境变量
openclaw env get
场景: 飞书消息后出现 "Auxiliary title generation failed: HTTP 404",用户不知道来源
排查方向:
~/.hermes/cron/output/)dream.py — Phase 2 蒸馏脚本(v4.x,M-FLOW Bundle Search + RAG召回/晋升 + 技能积分榜融合)update-cron-date.py — 每日 cron 日期注入 ⚠️ 特权操作,需 --confirmgraph-builder.py — 从日志构建M-FLOW图结构bundle-search.py — Bundle Search检索实现longterm_rag.py — Long-Term RAG 管理脚本(v4.x新增)> dream.py 蒸馏前自动调用 ~/SharedSkills/skill-scoreboard/scripts/score_tracker.py today,将今日技能王 + 积分注入蒸馏上下文和梦境报告,无需额外配置。
Hook 目录: ~/.openclaw/hooks/hippocampus/
已配置: openclaw.json 中 hooks.internal.entries.hippocampus: enabled: true
功能: 监听 message:preprocessed 事件,自动记录对话到 memory/logs/YYYY/MM/YYYY-MM-DD.md
丘脑过滤规则:
重启 gateway 后生效:
schtasks /run /tn "OpenClaw Gateway"
| 维度 | 旧架构(平坦检索) | M-FLOW(倒锥图路由) |
|---|---|---|
| ------ | ------------------- | ---------------------- |
| 存储结构 | 平面文件列表 | 四层有向图 |
| 检索方式 | grep / 向量相似度 | Bundle Search代价传播 |
| 关系表示 | 简单link引用 | 带语义描述的边 |
| 短长记忆 | 无分层 | 30天老化晋升RAG |
~/.hermes/scripts/sync_openclaw_memory.pypython3 ~/.hermes/scripts/sync_openclaw_memory.py [--dry-run]references/hermes-openclaw-memory-sync.md| 维度 | MetaGPT RoleZeroLongTermMemory | Dream Long-Term RAG |
|---|---|---|
| ------ | ------------------------------- | --------------------- |
| RAG引擎 | Chroma + LLMRanker | JSONL + 关键词匹配 |
| 召回触发 | memory_k 溢出 或 用户需求 | 每次蒸馏前 |
| 晋升条件 | count > memory_k | age > 30天 且 recallCount < 3 |
| 向量化 | embedding 模型 | 词袋模型(简化版) |
| 复杂度 | 依赖 Chroma/llama-index | 纯 Python,无外部依赖 |
共 2 个版本