self-improving-agent by charon-fan/agent-playbook
npx skills add https://github.com/charon-fan/agent-playbook --skill self-improving-agent"一个从每次交互中学习,积累模式和洞见以持续提升自身能力的 AI 智能体。" — 基于 2025 年终身学习研究
这是一个通用的自我进化系统,它从所有技能经验中学习,而不仅仅是 PRD。它实现了一个完整的反馈循环,包含:
基于 2025 年研究:
| 研究 | 关键洞见 | 应用 |
|---|---|---|
| SimpleMem | 高效的终身记忆 | 模式积累系统 |
| Multi-Memory Survey | 语义 + 情景记忆 | 世界知识 + 经验 |
| Lifelong Learning |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 连续任务流学习 |
| 从每次技能使用中学习 |
| 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 # 活跃会话数据
├── last_error.json # 用于自我修正的错误上下文
└── session_end.json # 会话结束标记
任何技能完成后,提取:
What 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 |
| "净 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);
memory/semantic-patterns.json)memory/episodic/YYYY-MM-DD-{skill}.json)在以下情况触发:
过程:
## 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_computation
在审查更新时,使用 references/appendix.md 中的验证模板。
添加到 Claude Code 设置 (~/.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。
任何技能完成后,此智能体会自动:
每周安装量
5.8K
仓库
GitHub 星标数
10
首次出现
Jan 22, 2026
安全审计
安装于
opencode5.5K
gemini-cli5.5K
codex5.5K
cursor5.5K
github-copilot5.5K
kimi-cli5.4K
"An AI agent that learns from every interaction, accumulating patterns and insights to continuously improve its own capabilities." — Based on 2025 lifelong learning research
This is a universal self-improvement system that learns from ALL skill experiences, not just PRDs. It implements a complete feedback loop with:
Based on 2025 research:
| Research | Key Insight | Application |
|---|---|---|
| SimpleMem | Efficient lifelong memory | Pattern accumulation system |
| Multi-Memory Survey | Semantic + Episodic memory | World knowledge + experiences |
| Lifelong Learning | Continuous task stream learning | Learn from every skill use |
| Evo-Memory | Test-time lifelong learning | Real-time adaptation |
┌─────────────────────────────────────────────────────────────────┐
│ 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 │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
| Event | Trigger | Action |
|---|---|---|
| before_start | Any skill starts | Log session start |
| after_complete | Any skill completes | Extract patterns, update skills |
| on_error | Bash returns non-zero exit | Capture error context, trigger self-correction |
Trigger evolution when new reusable knowledge appears:
| Trigger | Target Skill | Priority | Action |
|---|---|---|---|
| New PRD pattern discovered | prd-planner | High | Add to quality checklist |
| Architecture tradeoff clarified | architecting-solutions | High | Add to decision patterns |
| API design rule learned | api-designer | High | Update template |
| Debugging fix discovered | debugger | High | Add to anti-patterns |
| Review checklist gap | code-reviewer | High | Add checklist item |
| Perf/security insight | performance-engineer, security-auditor | High | Add to patterns |
| UI/UX spec issue | prd-planner, architecting-solutions | High |
memory/semantic-patterns.json)Stores abstract patterns and rules reusable across contexts:
{
"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/)Stores specific experiences and what happened :
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/)Stores current session context :
memory/working/
├── current_session.json # Active session data
├── last_error.json # Error context for self-correction
└── session_end.json # Session end marker
After any skill completes, extract:
What 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}
Convert experiences to reusable patterns:
| Concrete Experience | Abstract Pattern | Target Skill |
|---|---|---|
| "User forgot to save PRD notes" | "Always persist thinking to files" | prd-planner |
| "Code review missed SQL injection" | "Add security checklist item" | code-reviewer |
| "Callback was empty, didn't work" | "Verify callback implementations" | debugger |
| "Net APY position ambiguous" | "UI specs need exact relative positions" | prd-planner |
Abstraction Rules:
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
Update the appropriate skill files with evolution markers :
<!-- 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 Markers (when fixing wrong guidance):
<!-- 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);
### Phase 4: Memory Consolidation
1. **Update semantic memory** (`memory/semantic-patterns.json`)
2. **Store episodic memory** (`memory/episodic/YYYY-MM-DD-{skill}.json`)
3. **Update pattern confidence** based on applications/feedback
4. **Prune outdated patterns** (low confidence, no recent applications)
## Self-Correction (on_error hook)
Triggered when:
- Bash command returns non-zero exit code
- Tests fail after following skill guidance
- User reports the guidance produced incorrect results
**Process:**
```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
Example:
<!-- 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_computation
Use the validation template in references/appendix.md when reviewing updates.
Add to Claude Code settings (~/.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"
}
]
}
]
}
}
Replace ${SKILLS_DIR} with your actual skills path.
See references/appendix.md for memory structure, workflow diagrams, metrics, feedback templates, and research links.
After any skill completes, this agent automatically:
Weekly Installs
5.8K
Repository
GitHub Stars
10
First Seen
Jan 22, 2026
Security Audits
Gen Agent Trust HubWarnSocketPassSnykPass
Installed on
opencode5.5K
gemini-cli5.5K
codex5.5K
cursor5.5K
github-copilot5.5K
kimi-cli5.4K
97,600 周安装
| Add visual spec requirements |
| React/state pattern | debugger, refactoring-specialist | Medium | Add to patterns |
| Test strategy improvement | test-automator, qa-expert | Medium | Update approach |
| CI/deploy fix | deployment-engineer | Medium | Add to troubleshooting |