Loading...
Loading...
一款通用的自我改进Agent,可从所有技能经验中学习。采用多内存架构(语义+情景+工作内存)持续演进代码库。基于钩子机制的自我修正功能会在技能完成/出错时自动触发。
npx skill4agent add charon-fan/agent-playbook self-improving-agent"一款可从每次交互中学习、积累模式和洞见以持续提升自身能力的AI Agent。" — 基于2025年终身学习研究
| 研究 | 核心洞见 | 应用 |
|---|---|---|
| SimpleMem | 高效终身内存 | 模式积累系统 |
| Multi-Memory Survey | 语义+情景内存 | 世界知识+经验存储 |
| Lifelong Learning | 持续任务流学习 | 从每次技能使用中学习 |
| Evo-Memory | 测试时终身学习 | 实时适配 |
┌─────────────────────────────────────────────────────────────────┐
│ UNIVERSAL SELF-IMPROVEMENT │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Skill Event → Extract Experience → Abstract Pattern → Update │
│ │ │ │ │ │
│ ▼ ▼ ▼ ▼ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ MULTI-MEMORY SYSTEM │ │
│ ├─────────────────────────────────────────────────────┤ │
│ │ Semantic Memory │ Episodic Memory │ Working Memory │ │
│ │ (Patterns/Rules) │ (Experiences) │ (Current) │ │
│ │ memory/semantic/ │ memory/episodic/ │ memory/working/│ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ FEEDBACK LOOP │ │
│ │ User Feedback → Confidence Update → Pattern Adapt │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘| 事件 | 触发条件 | 动作 |
|---|---|---|
| before_start | 任意技能启动 | 记录会话开始 |
| after_complete | 任意技能完成 | 提取模式,更新技能 |
| on_error | Bash返回非零退出码 | 捕获错误上下文,触发自我修正 |
| 触发条件 | 目标技能 | 优先级 | 动作 |
|---|---|---|---|
| 发现新的PRD模式 | prd-planner | 高 | 添加到质量检查清单 |
| 明确架构权衡 | architecting-solutions | 高 | 添加到决策模式 |
| 学到API设计规则 | api-designer | 高 | 更新模板 |
| 发现调试修复方案 | debugger | 高 | 添加到反模式库 |
| 发现评审检查清单漏洞 | code-reviewer | 高 | 添加检查项 |
| 获得性能/安全洞见 | performance-engineer, security-auditor | 高 | 添加到模式库 |
| 发现UI/UX规范问题 | prd-planner, architecting-solutions | 高 | 添加视觉规范要求 |
| 学到React/状态模式 | debugger, refactoring-specialist | 中 | 添加到模式库 |
| 改进测试策略 | test-automator, qa-expert | 中 | 更新方法 |
| 发现CI/部署修复方案 | deployment-engineer | 中 | 添加到故障排查库 |
memory/semantic-patterns.json{
"patterns": {
"pattern_id": {
"id": "pat-2025-01-11-001",
"name": "Pattern Name",
"source": "user_feedback|implementation_review|retrospective",
"confidence": 0.95,
"applications": 5,
"created": "2025-01-11",
"category": "prd_structure|react_patterns|async_patterns|...",
"pattern": "One-line summary",
"problem": "What problem does this solve?",
"solution": { ... },
"quality_rules": [ ... ],
"target_skills": [ ... ]
}
}
}memory/episodic/memory/episodic/
├── 2025/
│ ├── 2025-01-11-prd-creation.json
│ ├── 2025-01-11-debug-session.json
│ └── 2025-01-12-refactoring.json{
"id": "ep-2025-01-11-001",
"timestamp": "2025-01-11T10:30:00Z",
"skill": "debugger",
"situation": "User reported data not refreshing after form submission",
"root_cause": "Empty callback in onRefresh prop",
"solution": "Implement actual refresh logic in callback",
"lesson": "Always verify callbacks are not empty functions",
"related_pattern": "callback_verification",
"user_feedback": {
"rating": 8,
"comments": "This was exactly the issue"
}
}memory/working/memory/working/
├── current_session.json # Active session data
├── last_error.json # Error context for self-correction
└── session_end.json # Session end markerWhat happened:
skill_used: {which skill}
task: {what was being done}
outcome: {success|partial|failure}
Key Insights:
what_went_well: [what worked]
what_went_wrong: [what didn't work]
root_cause: {underlying issue if applicable}
User Feedback:
rating: {1-10 if provided}
comments: {specific feedback}| 具体经验 | 抽象模式 | 目标技能 |
|---|---|---|
| "用户忘记保存PRD笔记" | "始终将思考内容持久化到文件中" | prd-planner |
| "代码评审遗漏SQL注入问题" | "添加安全检查清单项" | code-reviewer |
| "回调函数为空,无法正常工作" | "验证回调函数实现" | debugger |
| "Net APY位置不明确" | "UI规范需要精确的相对位置" | prd-planner |
If experience_repeats 3+ times:
pattern_level: critical
action: Add to skill's "Critical Mistakes" section
If solution_was_effective:
pattern_level: best_practice
action: Add to skill's "Best Practices" section
If user_rating >= 7:
pattern_level: strength
action: Reinforce this approach
If user_rating <= 4:
pattern_level: weakness
action: Add to "What to Avoid" section<!-- Evolution: 2025-01-12 | source: ep-2025-01-12-001 | skill: debugger -->
## Pattern Added (2025-01-12)
**Pattern**: Always verify callbacks are not empty functions
**Source**: Episode ep-2025-01-12-001
**Confidence**: 0.95
### Updated Checklist
- [ ] Verify all callbacks have implementations
- [ ] Test callback execution paths<!-- Correction: 2025-01-12 | was: "Use callback chain" | reason: caused stale refresh -->
## Corrected Guidance
Use direct state monitoring instead of callback chains:
```typescript
// ✅ Do: Direct state monitoring
const prevPendingCount = usePrevious(pendingCount);
### 阶段4:内存整合
1. **更新语义内存**(`memory/semantic-patterns.json`)
2. **存储情景内存**(`memory/episodic/YYYY-MM-DD-{skill}.json`)
3. **基于应用情况/反馈更新模式置信度**
4. **清理过时模式**(低置信度、近期无应用的模式)
## 自我修正(on_error钩子)
在以下情况触发:
- Bash命令返回非零退出码
- 遵循技能指导后测试失败
- 用户反馈指导产生错误结果
**流程:**
```markdown
## Self-Correction Workflow
1. Detect Error
- Capture error context from working/last_error.json
- Identify which skill guidance was followed
2. Verify Root Cause
- Was the skill guidance incorrect?
- Was the guidance misinterpreted?
- Was the guidance incomplete?
3. Apply Correction
- Update skill file with corrected guidance
- Add correction marker with reason
- Update related patterns in semantic memory
4. Validate Fix
- Test the corrected guidance
- Ask user to verify<!-- Correction: 2025-01-12 | was: "useMemo for claimable ids" | reason: stale data at click time -->
## Self-Correction: Click-Time Computation
**Issue**: Using useMemo for claimable IDs caused stale data
**Fix**: Compute at click time for always-fresh data
**Pattern**: click_time_vs_open_time_computationreferences/appendix.md~/.claude/settings.json{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash|Write|Edit",
"hooks": [
{
"type": "command",
"command": "bash ${SKILLS_DIR}/self-improving-agent/hooks/pre-tool.sh \"$TOOL_NAME\" \"$TOOL_INPUT\""
}
]
}
],
"PostToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "bash ${SKILLS_DIR}/self-improving-agent/hooks/post-bash.sh \"$TOOL_OUTPUT\" \"$EXIT_CODE\""
}
]
}
],
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "bash ${SKILLS_DIR}/self-improving-agent/hooks/session-end.sh"
}
]
}
]
}
}${SKILLS_DIR}references/appendix.md