Self-Optimization
Use this skill to close the loop after real work. The goal is not just to log what went wrong. The goal is to convert signal from mistakes, corrections, and repeated effort into stronger future behavior.
Core Loop
- 1. Detect meaningful signal.
- Capture it in
.learnings/. - De-duplicate and link related entries.
- Promote stable patterns into durable guidance.
- Extract reusable skills when the pattern is broad and proven.
Quick Reference
| Situation | Action |
|---|
| Command, tool, or integration fails unexpectedly | Append an entry to INLINECODE1 |
| User corrects the agent or provides missing facts |
Append an entry to
.learnings/LEARNINGS.md |
| A better repeatable approach is discovered | Append an entry to
.learnings/LEARNINGS.md |
| User asks for a missing capability | Append an entry to
.learnings/FEATURE_REQUESTS.md |
| Same issue keeps reappearing | Link entries, bump priority, and consider promotion |
| Pattern is stable across tasks | Promote to
AGENTS.md,
CLAUDE.md,
TOOLS.md,
SOUL.md, or
.github/copilot-instructions.md |
| Pattern is reusable beyond one repo | Extract a new skill scaffold |
Detection Triggers
Capture a learning when any of these happen:
- - The first attempt was wrong and needed correction.
- A tool or command failed in a non-obvious way.
- The user revealed a project convention that was not documented.
- The agent discovered a stronger pattern than the one it started with.
- The same workaround or warning has appeared more than once.
- The user asked for a capability the current system does not provide.
Skip noisy one-off trivia. Capture things that would realistically save a future session time, confusion, or rework.
Log Files
Create a local .learnings/ directory in the workspace or in the OpenClaw workspace.
CODEBLOCK0
LEARNINGS.md
Use for:
- - corrections
- knowledge gaps
- best practices
- project conventions
- improved workflows
Template:
INLINECODE12
ERRORS.md
Use for:
- - command failures
- exceptions
- bad tool assumptions
- API or integration breakage
Template:
INLINECODE14
FEATURE_REQUESTS.md
Use for:
- - missing tooling
- automation requests
- product gaps
- missing agent behaviors
Template:
INLINECODE16
ID Format
Use TYPE-YYYYMMDD-XXX.
- -
LRN for learning - INLINECODE19 for error
- INLINECODE20 for feature request
Examples:
- - INLINECODE21
- INLINECODE22
- INLINECODE23
Promotion Rules
Promote an entry when it becomes more valuable as guidance than as a historical note.
| Target | Promote When |
|---|
| INLINECODE24 | Project facts, conventions, or recurring gotchas |
| INLINECODE25 |
Workflow rules, delegation patterns, automation steps |
|
.github/copilot-instructions.md | Repo guidance that should reach Copilot |
|
TOOLS.md | Tool quirks, auth requirements, environment gotchas |
|
SOUL.md | Behavioral or communication rules for OpenClaw sessions |
Promotion checklist:
- 1. Distill the learning into a short prevention rule.
- Add it to the right target file.
- Update the original entry status to
promoted. - Record where it was promoted.
Recurrence And Dedupe
Before creating a new entry for a familiar issue:
- 1. Search
.learnings/ for a related keyword or Pattern-Key. - If a related item exists, link it with
See Also. - Increase
Recurrence-Count and refresh Last-Seen. - Escalate priority if the pattern is recurring and costly.
Recurring issues often mean one of three things:
- - documentation is missing
- automation is missing
- the architecture or workflow is inviting the same failure
When To Extract A Skill
Extract a reusable skill when the pattern is:
- - resolved and trustworthy
- useful across multiple tasks
- non-obvious enough to justify explicit guidance
- portable beyond a single private incident
Use the helper:
CODEBLOCK5
Then customize the generated SKILL.md and update the original learning entry with:
- - INLINECODE36
- INLINECODE37
Review Rhythm
Review .learnings/ at these checkpoints:
- - before major tasks
- after finishing a feature or bugfix
- when working in an area with previous failures
- during periodic maintenance
Useful checks:
CODEBLOCK6
OpenClaw Setup
OpenClaw works especially well with this skill because workspace files and hooks let the improvement loop stay visible between sessions.
Install
CODEBLOCK7
Manual install:
CODEBLOCK8
This package is an OpenClaw-oriented evolution of the earlier self-learning workflow.
Hook Setup
Optional bootstrap reminder:
CODEBLOCK9
Workspace Layout
CODEBLOCK10
Hook Support For Other Agents
Claude Code / Codex
Use hook scripts in settings:
CODEBLOCK11
GitHub Copilot
Add a reminder to .github/copilot-instructions.md:
CODEBLOCK12
Best Practices
- 1. Log signal, not noise.
- Prefer prevention rules over postmortems.
- Link related incidents instead of duplicating them.
- Promote broadly useful guidance quickly.
- Treat repeated friction as a systems problem, not just a note-taking problem.
- Review learnings before repeating the same class of work.
技能名称:自我优化
自我优化
使用此技能在实际工作完成后形成闭环。目标不仅仅是记录出错之处,而是将来自错误、修正和重复劳动的信号,转化为未来更强大的行为模式。
核心循环
- 1. 检测有意义的信号。
- 将其捕获到 .learnings/ 目录中。
- 去重并关联相关条目。
- 将稳定的模式提升为持久的指导。
- 当模式广泛且经过验证时,提取可复用的技能。
快速参考
| 情况 | 操作 |
|---|
| 命令、工具或集成意外失败 | 向 .learnings/ERRORS.md 追加条目 |
| 用户纠正智能体或提供缺失的事实 |
向 .learnings/LEARNINGS.md 追加条目 |
| 发现了更好的可重复方法 | 向 .learnings/LEARNINGS.md 追加条目 |
| 用户请求缺失的能力 | 向 .learnings/FEATURE_REQUESTS.md 追加条目 |
| 同一问题反复出现 | 关联条目,提升优先级,并考虑升级 |
| 模式在多个任务中稳定 | 升级到 AGENTS.md、CLAUDE.md、TOOLS.md、SOUL.md 或 .github/copilot-instructions.md |
| 模式可跨仓库复用 | 提取新的技能框架 |
检测触发器
当发生以下任一情况时,捕获一条学习记录:
- - 首次尝试出错并需要修正。
- 工具或命令以非明显方式失败。
- 用户揭示了未记录的项目约定。
- 智能体发现了比初始模式更优的模式。
- 相同的变通方案或警告出现超过一次。
- 用户请求了当前系统未提供的能力。
跳过嘈杂的一次性琐事。捕获那些能在未来会话中切实节省时间、避免困惑或返工的内容。
日志文件
在工作区或 OpenClaw 工作区中创建本地 .learnings/ 目录。
text
.learnings/
├── LEARNINGS.md
├── ERRORS.md
└── FEATURE_REQUESTS.md
LEARNINGS.md
用于记录:
模板:
markdown
[LRN-YYYYMMDD-XXX] 类别
记录时间: 2026-04-01T10:00:00Z
优先级: 低 | 中 | 高 | 关键
状态: 待处理
领域: 前端 | 后端 | 基础设施 | 测试 | 文档 | 配置
摘要
对经验教训的一句话陈述。
详情
什么出错了,改变了什么,以及现在已知的正确做法是什么。
建议操作
下次应该采取什么不同的做法。
元数据
- - 来源: 对话 | 调试 | 用户反馈 | 简化与强化
- 相关文件: path/to/file
- 标签: 标签-a, 标签-b
- 另见: LRN-20260401-001
- 模式键: optional.stable.key
- 重复次数: 1
- 首次发现: 2026-04-01
- 最近发现: 2026-04-01
ERRORS.md
用于记录:
模板:
markdown
[ERR-YYYYMMDD-XXX] 命令或工具
记录时间: 2026-04-01T10:00:00Z
优先级: 中
状态: 待处理
领域: 后端 | 基础设施 | 测试 | 文档 | 配置
摘要
对失败的简短描述。
错误
text
实际的错误输出放在这里。
上下文
建议修复
下一步应尝试或记录的内容。
元数据
- - 可重现: 是 | 否 | 未知
- 相关文件: path/to/file
- 另见: ERR-20260401-001
FEATURE_REQUESTS.md
用于记录:
模板:
markdown
[FEAT-YYYYMMDD-XXX] 能力名称
记录时间: 2026-04-01T10:00:00Z
优先级: 低 | 中 | 高
状态: 待处理
领域: 前端 | 后端 | 基础设施 | 测试 | 文档 | 配置
请求的能力
用户想要什么。
用户上下文
他们为什么想要。
复杂度评估
简单 | 中等 | 复杂
建议实现
如何构建或扩展。
元数据
- - 频率: 首次 | 重复出现
- 相关功能: 现有功能
ID 格式
使用 类型-YYYYMMDD-XXX。
- - LRN 代表学习记录
- ERR 代表错误
- FEAT 代表功能请求
示例:
- - LRN-20260401-001
- ERR-20260401-002
- FEAT-20260401-003
升级规则
当一个条目作为指导的价值超过其作为历史记录的价值时,将其升级。
| 目标文件 | 升级时机 |
|---|
| CLAUDE.md | 项目事实、约定或反复出现的陷阱 |
| AGENTS.md |
工作流规则、委托模式、自动化步骤 |
| .github/copilot-instructions.md | 应传达给 Copilot 的仓库指导 |
| TOOLS.md | 工具特性、认证要求、环境陷阱 |
| SOUL.md | OpenClaw 会话的行为或沟通规则 |
升级检查清单:
- 1. 将学习内容提炼为简短的预防规则。
- 将其添加到正确的目标文件中。
- 将原始条目的状态更新为 已升级。
- 记录升级到的位置。
重复与去重
在为熟悉的问题创建新条目之前:
- 1. 在 .learnings/ 中搜索相关关键词或 模式键。
- 如果存在相关条目,使用 另见 进行关联。
- 增加 重复次数 并更新 最近发现 时间。
- 如果模式重复出现且代价高昂,则提升优先级。
重复出现的问题通常意味着以下三种情况之一:
- - 缺少文档
- 缺少自动化
- 架构或工作流本身容易导致相同的失败
何时提取技能
当模式满足以下条件时,提取可复用的技能:
- - 已解决且可靠
- 在多个任务中有用
- 足够非显而易见,值得明确的指导
- 可移植到单个私有事件之外
使用辅助脚本:
bash
./skills/self-optimization/scripts/extract-skill.sh my-new-skill --dry-run
./skills/self-optimization/scripts/extract-skill.sh my-new-skill
然后自定义生成的 SKILL.md,并更新原始学习条目,添加:
- - 状态: 已升级为技能
- 技能路径: skills/my-new-skill
审查节奏
在以下检查点审查 .learnings/:
- - 在主要任务之前
- 完成功能或错误修复之后
- 在处理之前有失败记录的领域时
- 在定期维护期间
有用的检查命令:
bash
grep -h 状态\\\\: 待处理 .learnings/*.md | wc -l
grep -B5 优先级\\\\: 高 .learnings/*.md | grep ^## \\[
grep -l 领域\\\\: 后端 .learnings/*.md
OpenClaw 设置
OpenClaw 与此技能配合尤其出色,因为工作区文件和钩子使得改进循环在会话之间保持可见。
安装
bash
clawdhub install self-optimization
手动安装:
bash
git clone ~/.openclaw/skills/self-optimization
此包是早期自学习工作流程的面向 OpenClaw 的演进版本。
钩子设置
可选的启动提醒:
bash
cp -r hooks/openclaw ~/.openclaw/hooks/self-optimization
openclaw hooks enable self-optimization
工作区布局
text
~/.openclaw/workspace/
├── AGENTS.md
├── SOUL.md
├── TOOLS.md
├── MEMORY.md
├── memory/
└── .learnings/
├── LEARNINGS.md
├── ERRORS.md
└── FEATURE_REQUESTS.md
##