Install
openclaw skills install @brucetangc/self-improvement-llmAutonomous AI memory and self-learning system that logs, extracts lessons, verifies improvements, adapts behavior, manages preferences, and generates reusabl...
openclaw skills install @brucetangc/self-improvement-llmA continuous learning loop that automatically captures learnings, tracks improvements, and verifies their effectiveness.
Inspiration: This skill fuses the structured recording format and detection triggers from pskoett/self-improving-agent (6.1k installs) with a verification/hypothesis loop that most agent learning systems lack.
These are required behaviors, not suggestions. Execute them during conversation without being told.
Detect learning opportunities in real-time. After every user message or tool result, mentally check:
python3 scripts/reflect.py --detect "USER_MESSAGE".learning-trail.json immediately.learning-trail.json immediatelyLog corrections immediately. When the user says "不对", "错了", "no", "actually", etc.:
python3 scripts/learn.py --log correction "具体纠正了什么"
Set pattern_key for dedup: --log correction "message" --area behavior --priority high
Log errors automatically. When a tool call fails or returns unexpected output:
python3 scripts/learn.py --log error "工具名: 错误简述" --area tooling --priority medium
After significant tasks, append to today's daily log:
python3 scripts/reflect.py --log "完成了什么"
Check .hook-context.txt (written by plugin hook at gateway startup):
Use read(path="memory/.hook-context.txt") to check it.
If it shows pending verifications or patterns ready for promotion, act on them.
Run a quick status check:
python3 scripts/learn.py --status
python3 scripts/learn.py --cycle
skillgen.py --auto)record_change for verification trackingCRITICAL RULE — 任何文件编辑前必须先 read 获取当前内容。
# ❌ 错误:凭记忆构造 oldText
edit(path="MEMORY.md", oldText="我印象中的内容", newText="新内容")
# ✅ 正确:先读文件,拿到实际内容
read(path="MEMORY.md")
# 然后用实际内容构造 oldText
edit(path="MEMORY.md", oldText="从 read 结果中复制的精确文本", newText="新内容")
为什么: edit 工具要求 oldText 与文件内容逐字符匹配(含空白和换行)。凭记忆构造几乎必然失败,导致 cron 假性 error。
适用场景: 编辑 MEMORY.md、TOOLS.md、USER.md、AGENTS.md、SOUL.md 等任何文件。
python3 scripts/learn.py --record-change MEMORY.md "what was changed" "why this should help"
python3 scripts/learn.py --score 8 7 9 8 7 "brief justification"
Session / Task
↓
[DETECT] ← Automatic triggers: corrections, errors, feature requests
↓
[LOG] ← Structured entries with IDs, priorities, categories
↓
[EXTRACT] ← Distill patterns from repeated entries
↓
[PROMOTE] ← To AGENTS.md / SOUL.md / TOOLS.md / MEMORY.md
↓
[VERIFY] ← 7-day check: did this change actually help?
↓
[ADAPT] ← Reinforce success, revert failure
↓
(back to detect on next interaction)
The skill also manages the agent's memory system — daily logs, user preferences, and knowledge retention.
| Layer | Store | Content |
|---|---|---|
| L1 Session Context | memory/sessions/*.md | 会话摘要 |
| L2 Persistent Store | MEMORY.md, memory/*.md, memory/skills/ | 蒸馏知识、经验教训 |
| L3 User Model | memory/preferences.json, USER.md | 用户偏好、沟通风格 |
Inspired by Nous Research Hermes Agent.
At the end of each session or significant task, write a summary to memory/YYYY-MM-DD.md. Do NOT log individual micro-events (corrections, errors, tool failures) here — those go to .learning-trail.json only.
### 📝 Session summary
Completed tasks, user requests, decisions, key outcomes.
Keep entries concise (3-5 lines per session).
| Type | Layer | Where | Example |
|---|---|---|---|
| Session summaries | L1 | memory/sessions/*.md | "2026-05-27 搜了苏超、装了 SearXNG" |
| Daily logs | L2 | memory/YYYY-MM-DD.md | "10:30 创建 self-improvement skill" |
| Distilled principles | L2 | MEMORY.md | "Simple before powerful" |
| Auto-generated skills | L2 | memory/skills/*.md | "SearXNG 部署流程" |
| User preferences | L3 | memory/preferences.json | "直接回答,不要解释" |
| User profile | L3 | USER.md | "技术背景强,中文沟通" |
| Structured learning | — | .learning-trail.json | 所有 LRN/ERR/FEAT 条目 |
| Memory | Retention | Action |
|---|---|---|
| Daily logs | Keep forever | Append-only, never delete |
| Learning entries | 90 days | Auto-resolve pending items after 90d |
| Verified principles | Keep forever | Part of long-term knowledge |
| User preferences | Keep until changed | Update when user says otherwise |
| Tool notes | Keep until outdated | Update when tools change |
When user asks "之前说过什么" or "帮我回忆一下":
MEMORY.md (distilled knowledge)USER.md (preferences).learning-trail.json for structured entriesgrep recent memory/*.md files会话中
→ 检测到用户偏好 / 知识 / 错误
→ 仅写入 .learning-trail.json(结构化)
会话结束(每次对话结束)
→ 自动生成 L1 会话摘要到 memory/sessions/YYYY-MM-DD-NNN.md
→ 摘要包含:做了什么任务、学到了什么、用户反馈、生成了哪些技能
→ 追加概要到 memory/YYYY-MM-DD.md
心跳/空闲
→ 读取 .learning-trail.json 的 patterns
→ 达到阈值的晋升为 MEMORY.md 原则或 memory/preferences.json 偏好
→ 检查是否有值得生成技能的任务(8+ 工具调用且含写操作/脚本执行)
新会话开始
→ MEMORY.md 自动注入上下文
→ .learning-trail.json 的 watchlist 提醒我注意
Automatically log when you notice:
Corrections → log to .learning-trail.json (category: correction)
Feature Requests → log to .learning-trail.json
Knowledge Gaps → log to .learning-trail.json (category: knowledge_gap)
Errors → log to .learning-trail.json
Successes → log to .learning-trail.json (category: best_practice)
| Trigger | When | Action |
|---|---|---|
| Session end | After completion | Auto-log summary to memory/YYYY-MM-DD.md + memory/sessions/ L1 summary |
| Skill gen check | After complex task | Auto-generate skill if 8+ tool calls (with write/exec/workflow) or user says "记住" |
| Heartbeat | Idle time | Run learn.py --cycle: check verifications, promote patterns |
| Improve yourself | On demand | Full cycle + report |
| Hook | Session start | If hook installed, review pending learnings |
每次会话/任务完成后,自动生成会话摘要到 memory/sessions/YYYY-MM-DD-NNN.md:
# Session Summary: 2026-05-27-001
## Tasks Completed
- [任务名称] 做了什么,结果是什么
## Learnings
- [学到了什么]
## Skills Generated
- [生成了哪些技能文件]
## User Feedback
- [用户说了什么重要反馈]
## Open Items
- [未完成的或待确认的]
生成时机: 一个完整的任务流程结束后(如装完 SearXNG、搜完新闻等)
当完成一个复杂度达标的任务后,自动生成标准化技能文件。
生成条件(满足任意一个):
自动检测机制:
memory/skills/<task-slug>.mdAll entries use TYPE-YYYYMMDD-XXX IDs (LRN/ERR/FEAT) and go into memory/.learning-trail.json. Full entry formats: references/cli_ref.md.
When logging something that might already exist:
.learning-trail.json for matching Pattern-KeyPromote a pattern to workspace core files when all are true:
Promotion targets:
| Entry Type | Promote To | Example |
|---|---|---|
| Behavioral pattern | SOUL.md | "Be concise, skip disclaimers" |
| Workflow improvement | AGENTS.md | "Spawn sub-agents for long tasks" |
| Tool gotcha | TOOLS.md | "Git push needs auth configured" |
| User preference | USER.md / preferences.json | "User prefers direct answers" |
| Universal principle | MEMORY.md | "Simple before powerful" |
| Reusable procedure | memory/skills/*.md | "SearXNG 部署流程" |
技能复用流程:
memory/skills/ 目录匹配关键词Auto-generated skill template: references/cli_ref.md.
learn.py --cycle checks after 7 days if the change helped. Verification API and outcomes: references/cli_ref.md.
python3 scripts/learn.py --cycle # Full cycle: check verifications + promote patterns
python3 scripts/learn.py --verify # Only check pending verifications
python3 scripts/learn.py --status # Show learning stats
python3 scripts/learn.py --log learning "message" --area behavior --priority high
CLI params reference: references/cli_ref.md.
For automatic reminders at session start, install the hook:
# Copy hook files (HOOK.md + handler.js) to OpenClaw hooks directory
cp skills/self-improvement/hooks/openclaw/HOOK.md ~/.openclaw/hooks/self-improvement/HOOK.md
cp skills/self-improvement/hooks/openclaw/handler.js ~/.openclaw/hooks/self-improvement/handler.js
# Enable it
openclaw hooks enable self-improvement
# Verify
openclaw hooks list
Important: OpenClaw hooks require
HOOK.md+handler.jsat the top level of the hook directory. Shell scripts (hook.sh) are not supported.
The hook checks .learning-trail.json on session start for:
| Situation | Action |
|---|---|
| Command/operation fails | Log to .learning-trail.json |
| User corrects you | Log to .learning-trail.json (correction) |
| User wants missing feature | Log to .learning-trail.json |
| API/external tool fails | Log to .learning-trail.json |
| Knowledge was outdated | Log to .learning-trail.json (knowledge_gap) |
| Found better approach | Log to .learning-trail.json (best_practice) |
| Same error 3x across sessions | Promote to core file |
| Change applied 7+ days ago | Run verification check |
| Priority | When to Use |
|---|---|
| critical | Blocks core functionality, data loss risk, security issue |
| high | Significant impact, affects common workflows, recurring issue |
| medium | Moderate impact, workaround exists |
| low | Minor inconvenience, nice-to-have |
Priority scoring when principles contradict: references/cli_ref.md.
wont_fixWhen the learning system detects a pattern ready for promotion or a change that needs verification, it generates a proposal for user review:
Pattern detected (≥3x across ≥2 sessions)
↓
Generate proposal: what to change, why, risk level
↓
Present to user for approval
↓
User says "approve N" or "skip N"
↓
Apply approved changes, track for verification
Each proposal includes:
| Change Type | Action | Example |
|---|---|---|
| Add note to TOOLS.md | ✅ Auto-apply | "QWeather needs custom host" |
| Add principle to MEMORY.md | ✅ Auto-apply | "Simple before powerful" |
| Add preference to USER.md | ✅ Auto-apply | "User prefers direct answers" |
| Add guideline to SOUL.md | ⚠️ Propose | "Be concise, skip disclaimers" |
| Add rule to AGENTS.md | ⚠️ Propose | "Spawn sub-agents for long tasks" |
| Create new skill | ❌ Always ask | New skill for recurring task |
python3 scripts/learn.py --propose # Generate proposals for review
The agent will present proposals and wait for your approval before applying.
After each significant interaction, score the response on 5 dimensions (0-10):
| Dimension | What it measures |
|---|---|
| Accuracy | Was the output factually correct? |
| Usefulness | Did it solve the user's actual problem? |
| Efficiency | Were tool calls optimal? |
| Tone | Matched SOUL.md persona? |
| Proactiveness | Anticipated needs? |
python3 scripts/learn.py --score 8 9 7 8 6 # Score last conversation
python3 scripts/learn.py --trends 7 # Show 7-day trend
Example in references/cli_ref.md.
Build topic index → detect conversation topic → inject relevant memories.
python3 scripts/learn.py --build-index
python3 scripts/learn.py --query-memory weather
Topics list: references/cli_ref.md. Index rebuilt during --cycle.
Connects 事件 → 教训 → 原则. Node types, edge types, and CLI usage: references/cli_ref.md.
memory/ 目录和 .learning-trail.jsonpython3 scripts/migrate.pypython3 scripts/migrate.py --migratepython3 scripts/migrate.py --migrate如更新后出问题:
memory/ 目录.learning-trail.json在 Windows 上,openclaw skills update 可能失败,报 EPERM: operation not permitted。
原因: OpenClaw Gateway(Node.js)运行时持有技能目录的文件句柄,导致 update 流程中的 rename 操作被操作系统拒绝。
解决方法:
cmd /c rmdir /s /q "<skills路径>\self-improvement-llm"openclaw skills install self-improvement-llmLinux/macOS 不受影响,目录在被读取时仍可 rename。
python3 scripts/sync.py export # 导出到当前目录
python3 scripts/sync.py export /path/to/backup.zip # 导出到指定路径
导出内容:
memory/MEMORY.md — 长期记忆memory/.learning-trail.json — 结构化学习数据memory/.memory-index.json — 记忆索引memory/preferences.json — 用户偏好memory/sessions/ — 会话摘要memory/skills/ — 自动生成的技能memory/.dreams/ — 梦境蒸馏数据memory/*.md — 日常日志python3 scripts/sync.py import /path/to/backup.zip # 导入(不覆盖已有)
python3 scripts/sync.py import /path/to/backup.zip --overwrite # 覆盖导入
python3 scripts/sync.py exportpython3 scripts/sync.py import backup.zippython3 scripts/sync.py status