Self-Improving Agent
Overview
This skill enables OpenClaw to continuously improve by capturing learnings from:
- - Failed operations and errors
- User corrections and feedback
- Successful complex task completions
- Periodic review and consolidation
When to Use
- 1. Error Recovery: When a command or operation fails unexpectedly
- User Correction: When the user corrects the agent's behavior or output
- Success Capture: After completing a complex task successfully
- Learning Review: Periodic review of past learnings to consolidate knowledge
Core Workflow
1. Capture Learning
When something noteworthy happens:
CODEBLOCK0
2. Store Learning
Learnings are stored in memory/learnings.jsonl with:
- - Timestamp
- Type and severity
- Full context and details
- Tags for searchability
3. Retrieve Relevant Learnings
Before starting a task, search past learnings:
- - Match by task type
- Match by tags
- Match by error patterns
4. Apply Learnings
Use retrieved learnings to:
- - Avoid past mistakes
- Apply successful patterns
- Adjust approach based on corrections
Memory Structure
Learnings are stored in JSONL format:
CODEBLOCK1
Learning Types
| Type | When to Use | Example |
|---|
| error | Operation failed | Command returned non-zero exit code |
| correction |
User corrected behavior | "Don't use rm, use trash instead" |
|
success | Complex task completed | Successfully deployed to production |
|
insight | Discovered optimization | "This API is faster than alternatives" |
Severity Levels
- - critical: System-breaking errors, data loss risk
- high: Task-blocking errors, significant issues
- medium: Minor issues, workarounds available
- low: Optimization opportunities, nice-to-know
Commands
Capture a Learning
CODEBLOCK2
Search Learnings
CODEBLOCK3
Review Learnings
CODEBLOCK4
Best Practices
- 1. Capture Immediately: Record learnings while context is fresh
- Be Specific: Include full error messages and exact commands
- Generalize Lessons: Extract principles that apply beyond this instance
- Tag Thoughtfully: Use consistent tags for easy retrieval
- Review Regularly: Weekly review helps consolidate knowledge
- Avoid Duplicates: Check existing learnings before adding new ones
Integration Points
- - Error Handlers: Automatically capture command failures
- User Feedback: Listen for correction patterns in conversation
- Task Completion: Prompt for learning capture after complex tasks
- Heartbeat: Include learning review in periodic checks
Example Scenarios
Scenario 1: Command Failure
CODEBLOCK5
Scenario 2: User Correction
CODEBLOCK6
Scenario 3: Success Pattern
CODEBLOCK7
Safety Rules
- - Never store sensitive data (passwords, API keys, tokens)
- Sanitize error messages that might contain secrets
- Require user approval before storing corrections
- Allow users to delete or edit learnings
- Respect user privacy preferences
自我改进型智能体
概述
该技能使OpenClaw能够通过捕获以下内容来持续改进:
- - 失败操作和错误
- 用户纠正和反馈
- 成功完成复杂任务
- 定期审查与整合
使用时机
- 1. 错误恢复:当命令或操作意外失败时
- 用户纠正:当用户纠正智能体的行为或输出时
- 成功捕获:成功完成复杂任务后
- 学习回顾:定期回顾过往学习以整合知识
核心工作流程
1. 捕获学习内容
当有值得注意的事件发生时:
类型:错误 | 纠正 | 成功 | 洞察
上下文:正在尝试执行的操作
问题:出了什么问题(针对错误)
纠正:应该采取哪些不同做法
经验教训:可推广的要点
标签:相关主题/技能
2. 存储学习内容
学习内容存储在 memory/learnings.jsonl 中,包含:
- - 时间戳
- 类型和严重程度
- 完整上下文和详细信息
- 便于搜索的标签
3. 检索相关学习内容
开始任务前,搜索过往学习内容:
4. 应用学习内容
使用检索到的学习内容:
记忆结构
学习内容以JSONL格式存储:
json
{
timestamp: 2026-03-06T10:30:00Z,
type: error,
severity: high,
context: 全局安装npm包,
issue: 未使用sudo时权限被拒绝,
correction: 全局安装时使用sudo或配置npm前缀,
lesson: 始终检查操作是否需要提升权限,
tags: [npm, permissions, installation],
taskSlug: npm-global-install
}
学习类型
| 类型 | 使用时机 | 示例 |
|---|
| 错误 | 操作失败 | 命令返回非零退出码 |
| 纠正 |
用户纠正行为 | 不要用rm,改用trash |
|
成功 | 复杂任务完成 | 成功部署到生产环境 |
|
洞察 | 发现优化方案 | 此API比替代方案更快 |
严重程度级别
- - 严重:系统崩溃性错误,数据丢失风险
- 高:任务阻塞性错误,重大问题
- 中:次要问题,存在变通方案
- 低:优化机会,值得了解
命令
捕获学习内容
bash
手动捕获(用于用户纠正)
openclaw memory add-learning --type correction --context ... --lesson ...
搜索学习内容
bash
按关键词搜索
openclaw memory search-learnings npm permissions
按标签搜索
openclaw memory search-learnings --tag npm
按类型搜索
openclaw memory search-learnings --type error
审查学习内容
bash
审查近期学习内容
openclaw memory review-learnings --days 7
按类别审查
openclaw memory review-learnings --tag deployment
最佳实践
- 1. 立即捕获:在上下文还新鲜时记录学习内容
- 具体明确:包含完整的错误信息和确切的命令
- 提炼经验:提取适用于当前场景之外的原则
- 合理标签:使用一致的标签以便轻松检索
- 定期审查:每周审查有助于整合知识
- 避免重复:添加新学习内容前检查已有内容
集成点
- - 错误处理器:自动捕获命令失败
- 用户反馈:在对话中监听纠正模式
- 任务完成:复杂任务完成后提示捕获学习内容
- 心跳机制:在定期检查中包含学习审查
示例场景
场景1:命令失败
上下文:运行 npm install -g package
问题:EACCES权限错误
纠正:使用sudo运行或配置npm前缀
经验教训:检查全局安装是否需要提升权限
标签:npm, permissions, installation
场景2:用户纠正
上下文:建议使用 rm -rf 进行清理
纠正:用户更倾向于使用 trash 以确保安全
经验教训:默认使用安全、可逆的操作
标签:safety, file-operations, user-preference
场景3:成功模式
上下文:通过SSH部署到VPS
成功:使用带特定标志的rsync确保可靠性
经验教训:rsync -avz --delete 是可靠的部署方式
标签:deployment, ssh, rsync, success
安全规则
- - 绝不存储敏感数据(密码、API密钥、令牌)
- 对可能包含秘密信息的错误消息进行清理
- 存储纠正内容前需获得用户批准
- 允许用户删除或编辑学习内容
- 尊重用户隐私偏好