🧠 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-generatorAI画图、生成插画网页抓取web-scraper爬取数据、提取网页内容Shell命令shell-automation写脚本、批处理Git操作git-assistantcommit、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, SkillRegistrywork_review工作复盘分析 + 明日计划生成WorkAnalyzer, TomorrowPlannerskill_explorer技能缺口检测 + 自主学习GapDetector, SkillLearnerskill_developer全自动技能生成(AI生成+质量评估+注册)SkillGenerator, SkillQualityAssessorreporter每日完整汇报(六大模块)DailyReporter, SkillReportGenerator
技能活跃度 = 调用次数 × 质量系数 × 时间衰减
等级标识分值范围说明高度活跃🔥≥80调用频繁,持续进化正常📈60-79稳定使用低活跃💤40-59使用较少,建议复习休眠🗄️20-39长期未用,待激活已归档⚰️<20彻底停用
衰减规则:
与早7点+晚10点蒸馏同步执行,完整汇报保存为 daily-report-YYYY-MM-DD.md:
text
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 设计,新增短长记忆合并机制:
text
short-term-recall.json ← 活跃recall条目(上限200条)
memory/.rag/longterm.jsonl ← 老旧条目RAG存储
晋升条件:
召回流程:
效果: 记忆越来越精准,不像以前每次都从零开始。
text
用户对话
↓
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
↓
归档区 → 真相文件写回 → 梦境报告
所有记忆组织为 四层有向图,形成倒锥结构:
text
锥尖(容易精确命中)
↓
┌─────────────────────────┐
│ 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图结构:
text
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:
text
查询 → 向量化 → 4层锥形搜索 → 代价传播 → 最小路径Episode
RAG召回(v4.x新增):
text
当日关键词 → 查询longterm.jsonl → 召回相关旧记忆 → 注入蒸馏上下文
⑤ 蓝斑核(Locus Coeruleus)— 警觉与新鲜度信号
freshness分数——最近被提及的记忆权重更高
text
memory/
├── .dreams/
│ └── short-term-recall.json # 活跃recall条目(上限200条)
└── .rag/
└── longterm.jsonl # 老旧条目RAG存储(JSONL格式)
python
# 晋升条件
if age_days > 30 and recall_count < 3:
promote_to_longterm_rag(entry)
python
# 蒸馏前
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}"
bash
# 查看短/长记忆状态
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:
text
memory/patterns/
└── p-xxx.md # Pattern files with trigger + response
Pattern格式(含M-FLOW元数据):
yaml
---
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 TypeL4 EntityL3 FacetPointsL1 Episodeuseruser.luyirole, pref, goal, communication_styletopics/user_*.mdfeedbackfeedbackcorrection, error, insight, confirmationtopics/feedback_*.mdprojectproject.{name}decision, tool, deadline, contexttopics/project_*.mdreferencereferencecredential, link, skill, systemtopics/reference_*.mdlongterm(RAG)aged, promoted.rag/longterm.jsonl
text
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
MetricWeightFormulaFreshness0.20entries_referenced_last_30_days / totalCoverage0.20categories_updated_last_14_days / 10Coherence0.20entries_with_semantic_edges / totalGraph Connectivity0.20connected_components_ratioEfficiency0.10max(0, 1 - line_count/500)Reachability0.10Bundle Search路径覆盖率
When cron triggers:
Bundle Search预热:用今日日志构建临时图结构,快速验证图连通性
Read memory/logs/{date}.md
Read .learnings/LEARNINGS.md, .learnings/ERRORS.md, .learnings/FEATURE_REQUESTS.md
Read MEMORY.md, topic files, graph/index.json, procedures.md for context
Snapshot BEFORE: count entries, decisions, lessons, procedures
[4.x] 技能积分榜读取:调用 score_tracker.py today,获取今日技能王 + 调用统计,注入蒸馏上下文
[4.5] RAG召回:从当日条目提取关键词 → 查询longterm.jsonl → 注入蒸馏上下文
图增强检索:对每个learnings entry执行Bundle Search,找到相关Episode
Distillation Agent: Run sub-agent on raw entries + learnings + RAG results → produce:
memory/topics/[4.6] RAG晋升:30天+未召回条目 → 写入longterm.jsonl
更新图结构:
graph/episodes.jsongraph/facetpoints.jsongraph/edges.json(含语义描述)Write topic files (from Distillation Agent output)
Update truth files ( user_state.md, pending.md)
Update graph/index.json entry metadata + 重新计算向量锚点
Compute health metrics → update graph/index.json stats
Archive eligible entries → append to archive.md
Update MEMORY.md index (max 200 lines)
Snapshot AFTER: calculate deltas
Write dream report to memory/dreams/{date}.md and dream-log.md
v5.0 技能扩展模块:执行 skill_evolution + work_review + skill_explorer + skill_developer + reporter
v5.0 每日汇报:生成 daily-report-{date}.md 完整六大模块汇报
[Optional SwarmRecall]: 如果配置了API key,执行云端图同步
markdown
# 🌙 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 标志是安全机制,防止意外执行
无此标志时,脚本只显示将要做什么但不会实际修改
使用前请确保您了解 cron 作业的当前状态: 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/ 不存在则失败排查:
bash
ls -la ~/.openclaw/workspace/memory/logs/2026/
# 如果 05/ 目录不存在,说明本月还没有消息被记录
手动修复:
bash
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:
bash
# 查看 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 后生效:
bash
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 RoleZeroLongTermMemoryDream Long-Term RAGRAG引擎Chroma + LLMRankerJSONL + 关键词匹配召回触发memory_k 溢出 或 用户需求每次蒸馏前晋升条件count > memory_kage > 30天 且 recallCount < 3向量化embedding 模型词袋模型(简化版)复杂度依赖 Chroma/llama-index纯 Python,无外部依赖