self-improving-agent

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Self-Improving Agent

自我改进Agent

Captures learnings, errors, and corrections to enable continuous improvement across sessions.
捕获学习内容、错误和纠正信息,实现跨会话的持续改进。

Activation Triggers

激活触发条件

This skill automatically activates when:
TriggerWhat Gets LoggedLocation
Command failsError type, context, recovery suggestion
logs/failures_detailed.jsonl
User corrects"No, that's wrong...", "Actually..."
logs/corrections.jsonl
Missing capability"Can you X?" where X isn't available
logs/missing_capabilities.jsonl
API/tool failsFailure pattern, suggested fix
logs/failures_detailed.jsonl
Better approach foundOptimization learned
logs/learnings.jsonl
本技能在以下场景自动激活:
触发条件记录内容存储位置
命令执行失败错误类型、上下文、恢复建议
logs/failures_detailed.jsonl
用户给出纠正"No, that's wrong...", "Actually..."这类表述
logs/corrections.jsonl
能力缺失用户提出当前不支持的功能请求,如"你能做X吗?"
logs/missing_capabilities.jsonl
API/工具调用失败失败模式、建议修复方案
logs/failures_detailed.jsonl
发现更优方案学习到的优化点
logs/learnings.jsonl

How It Works

工作原理

1. Automatic Logging (via hooks)

1. 自动日志记录(通过钩子实现)

PostToolUse → enhanced-failure-logger.js → logs failures with context
UserMessage → correction-detector.js → detects "wrong/actually/try again"
Response → capability-tracker.js → detects unfulfilled requests
PostToolUse → enhanced-failure-logger.js → logs failures with context
UserMessage → correction-detector.js → detects "wrong/actually/try again"
Response → capability-tracker.js → detects unfulfilled requests

2. Learning Aggregation

2. 学习聚合

All learnings flow to
logs/learnings.jsonl
:
json
{
  "timestamp": "2026-01-26T12:00:00Z",
  "type": "user_correction|tool_failure|missing_capability",
  "category": "factual_error|command_failed|web_browsing",
  "description": "what was learned",
  "source": "which detector"
}
所有学习内容都会流入
logs/learnings.jsonl
json
{
  "timestamp": "2026-01-26T12:00:00Z",
  "type": "user_correction|tool_failure|missing_capability",
  "category": "factual_error|command_failed|web_browsing",
  "description": "what was learned",
  "source": "which detector"
}

3. Session Start Review

3. 会话启动回顾

On each session start, recent learnings are shown:
=== Learning Review ===
[Learnings] 47 total entries
[Recent]
  • [tool_failure] Bash failed: timeout - WebFetch to external API...
  • [user_correction] User corrected: "No, use the other file..."
[Corrections] 12 user corrections logged
[Capability Gaps] Top requested:
  • send emails (5x)
  • browse web (3x)
每次会话启动时,会展示近期的学习内容:
=== Learning Review ===
[Learnings] 47 total entries
[Recent]
  • [tool_failure] Bash failed: timeout - WebFetch to external API...
  • [user_correction] User corrected: "No, use the other file..."
[Corrections] 12 user corrections logged
[Capability Gaps] Top requested:
  • send emails (5x)
  • browse web (3x)

4. QAVR Integration

4. QAVR集成

Successful learnings boost Q-values for related memories, improving future retrieval.
成功的学习内容会提升相关记忆的Q值,优化后续的检索效果。

Manual Commands

手动命令

Review Learnings

回顾学习内容

bash
undefined
bash
undefined

Show all learnings

Show all learnings

cat ~/.claude/logs/learnings.jsonl | tail -20
cat ~/.claude/logs/learnings.jsonl | tail -20

Show corrections only

Show corrections only

cat ~/.claude/logs/corrections.jsonl | jq -s 'group_by(.correction_type) | map({type: .[0].correction_type, count: length})'
cat ~/.claude/logs/corrections.jsonl | jq -s 'group_by(.correction_type) | map({type: .[0].correction_type, count: length})'

Show capability gaps report

Show capability gaps report

node ~/.claude/scripts/hooks/capability-tracker.js --report
undefined
node ~/.claude/scripts/hooks/capability-tracker.js --report
undefined

Test Detection

检测功能测试

bash
undefined
bash
undefined

Test correction detector

Test correction detector

node ~/.claude/scripts/hooks/correction-detector.js
node ~/.claude/scripts/hooks/correction-detector.js

Test failure logger

Test failure logger

node ~/.claude/scripts/hooks/enhanced-failure-logger.js
node ~/.claude/scripts/hooks/enhanced-failure-logger.js

Test capability tracker

Test capability tracker

node ~/.claude/scripts/hooks/capability-tracker.js
undefined
node ~/.claude/scripts/hooks/capability-tracker.js
undefined

Learning Categories

学习分类

Correction Types

纠正类型

  • factual_error
    - Wrong information provided
  • retry_request
    - User asked to try again
  • misunderstanding
    - Misinterpreted the request
  • failed_solution
    - Solution didn't work
  • factual_error
    - 提供了错误信息
  • retry_request
    - 用户要求重试
  • misunderstanding
    - 误解了用户请求
  • failed_solution
    - 提供的解决方案无效

Failure Types

失败类型

  • permission_error
    - Access denied
  • not_found
    - File/resource missing
  • timeout
    - Operation timed out
  • network_error
    - Connection issues
  • syntax_error
    - Invalid syntax
  • api_error
    - External API failed
  • command_failed
    - Shell command failed
  • agent_failed
    - Subagent failed
  • permission_error
    - 访问被拒绝
  • not_found
    - 文件/资源不存在
  • timeout
    - 操作超时
  • network_error
    - 连接问题
  • syntax_error
    - 语法无效
  • api_error
    - 外部API调用失败
  • command_failed
    - Shell命令执行失败
  • agent_failed
    - 子Agent运行失败

Capability Categories

能力分类

  • web_browsing
    - Internet access requests
  • image_processing
    - Image/photo handling
  • communication
    - Email/messaging
  • database_access
    - SQL/database queries
  • external_api
    - Third-party services
  • memory_persistence
    - Long-term memory
  • web_browsing
    - 互联网访问请求
  • image_processing
    - 图片/照片处理
  • communication
    - 邮件/消息发送
  • database_access
    - SQL/数据库查询
  • external_api
    - 第三方服务调用
  • memory_persistence
    - 长期记忆存储

Configuration

配置

In
settings.json
, these hooks enable self-improvement:
json
{
  "hooks": {
    "SessionStart": [...],  // Reviews learnings
    "PostToolUse": [
      {"matcher": "Bash", "hooks": [{"command": "enhanced-failure-logger.js"}]},
      {"matcher": "Task", "hooks": [{"command": "enhanced-failure-logger.js"}]}
    ]
  }
}
settings.json
中,以下钩子会启用自我改进功能:
json
{
  "hooks": {
    "SessionStart": [...],  // Reviews learnings
    "PostToolUse": [
      {"matcher": "Bash", "hooks": [{"command": "enhanced-failure-logger.js"}]},
      {"matcher": "Task", "hooks": [{"command": "enhanced-failure-logger.js"}]}
    ]
  }
}

Benefits

优势

  1. Learn from mistakes - Don't repeat the same errors
  2. Understand user preferences - Track what corrections mean
  3. Identify skill gaps - Know what features to build
  4. Improve over time - QAVR ranking gets better with feedback
  5. Context persistence - Learnings survive session restarts
  1. 从错误中学习 - 不会重复犯相同的错误
  2. 理解用户偏好 - 追踪用户纠正内容背后的偏好
  3. 识别能力缺口 - 明确需要开发的功能方向
  4. 持续优化 - QAVR排序会随着反馈不断优化
  5. 上下文持久化 - 学习内容不会随着会话重启丢失

Integration with Other Skills

与其他技能的集成

SkillIntegration
QAVRSuccessful learnings boost memory Q-values
Memory ConsolidationPeriodic cleanup of old learnings
Confidence CheckReview learnings before major tasks
IR-v2Use learnings to inform pattern selection
技能集成逻辑
QAVR成功的学习内容会提升记忆Q值
Memory Consolidation定期清理过时的学习内容
Confidence Check执行重要任务前回顾学习内容
IR-v2基于学习内容优化模式选择

Files

文件结构

~/.claude/
├── logs/
│   ├── learnings.jsonl           # All learnings
│   ├── corrections.jsonl         # User corrections
│   ├── failures_detailed.jsonl   # Enhanced failure logs
│   ├── missing_capabilities.jsonl # Capability requests
│   └── capability_gaps.json      # Aggregated gaps
└── scripts/hooks/
    ├── correction-detector.js
    ├── enhanced-failure-logger.js
    ├── capability-tracker.js
    └── session-start.js (reviews learnings)
~/.claude/
├── logs/
│   ├── learnings.jsonl           # All learnings
│   ├── corrections.jsonl         # User corrections
│   ├── failures_detailed.jsonl   # Enhanced failure logs
│   ├── missing_capabilities.jsonl # Capability requests
│   └── capability_gaps.json      # Aggregated gaps
└── scripts/hooks/
    ├── correction-detector.js
    ├── enhanced-failure-logger.js
    ├── capability-tracker.js
    └── session-start.js (reviews learnings)