mcpField
S
self-improving-agent

self-improving-agent

github.com/kimasplundAgent 工作流0212 次安装40 周前更新
代码仓库

关于 self-improving-agent

self-improving-agent 是一项供 Agent 使用的技能,可跨会话记录纠正、错误、能力缺口和改进方法。它通过钩子记录事件,并在会话开始时回顾经验,还可与 QAVR 集成。

主要功能

  1. 01通过钩子记录失败和纠正
  2. 02跟踪能力缺口
  3. 03会话开始时回顾经验
  4. 04集成 QAVR 记忆排序

适用场景

  1. 01检查反复出现的命令或 API 错误
  2. 02跨会话跟踪用户纠正
  3. 03识别频繁请求但缺失的能力

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/kimasplund/clawdbot-skills-pack --skill self-improving-agent

安装后在 Claude Code 中输入/self-improving-agent确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

capability-tracker.js
correction-detector.js
enhanced-failure-logger.js

详细介绍

自我改进 Agent

记录经验、错误和纠正内容,以便在不同会话中持续改进。

激活触发条件

此技能会在以下情况自动激活:

触发条件记录内容位置
命令失败错误类型、上下文、恢复建议logs/failures_detailed.jsonl
用户纠正“不对,这错了……”“其实……”logs/corrections.jsonl
缺少能力用户询问“你能做 X 吗?”,但不具备 X 能力logs/missing_capabilities.jsonl
API/工具失败失败模式、建议的修复方法logs/failures_detailed.jsonl
发现更好的方法学到的优化方法logs/learnings.jsonl

工作原理

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
2. 汇总经验

所有经验都会写入 logs/learnings.jsonl:

{
  "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. 会话开始时回顾

每次会话开始时,都会显示近期经验:

=== 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 集成

成功的经验会提升相关记忆的 Q 值,从而改进后续检索。

手动命令

回顾经验
# Show all learnings
cat ~/.claude/logs/learnings.jsonl | tail -20

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

# Show capability gaps report
node ~/.claude/scripts/hooks/capability-tracker.js --report
测试检测
# Test correction detector
node ~/.claude/scripts/hooks/correction-detector.js

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

# Test capability tracker
node ~/.claude/scripts/hooks/capability-tracker.js

经验类别

纠正类型
  • factual_error - 提供的信息有误
  • retry_request - 用户要求重试
  • misunderstanding - 误解了请求
  • failed_solution - 解决方案不起作用
失败类型
  • permission_error - 访问被拒绝
  • not_found - 文件/资源缺失
  • timeout - 操作超时
  • network_error - 连接问题
  • syntax_error - 语法无效
  • api_error - 外部 API 调用失败
  • command_failed - Shell 命令失败
  • agent_failed - 子 Agent 失败
能力类别
  • web_browsing - 互联网访问请求
  • image_processing - 图像/照片处理
  • communication - 电子邮件/消息
  • database_access - SQL/数据库查询
  • external_api - 第三方服务
  • memory_persistence - 长期记忆

配置

在 settings.json 中,这些钩子可启用自我改进:

{
  "hooks": {
    "SessionStart": [...],  // Reviews learnings
    "PostToolUse": [
      {"matcher": "Bash", "hooks": [{"command": "enhanced-failure-logger.js"}]},
      {"matcher": "Task", "hooks": [{"command": "enhanced-failure-logger.js"}]}
    ]
  }
}

优势

  1. 从错误中学习 - 避免重复相同的错误
  2. 了解用户偏好 - 跟踪纠正内容的含义
  3. 识别技能差距 - 了解需要构建哪些功能
  4. 持续改进 - 通过反馈提升 QAVR 排名
  5. 上下文持久化 - 会话重启后仍保留经验

与其他技能的集成

技能集成方式
QAVR成功的经验会提升记忆的 Q 值
Memory Consolidation定期清理旧经验
Confidence Check在执行重要任务前回顾经验
IR-v2利用经验为模式选择提供参考

文件

~/.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)

评论

支持 Markdown