Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Universal self-improvement system that learns from every skill interaction using multi-memory architecture.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: self-improving-agent3description: A universal self-improving agent that learns from ALL skill experiences. Uses multi-memory architecture (semantic + episodic + working) to continuously evolve the codebase. Auto-triggers on skill completion/error with hooks-based self-correction.4allowed-tools: Read, Write, Edit, Bash, Grep, Glob, WebSearch5metadata:6hooks:7before_start:8- trigger: session-logger9mode: auto10context: "Start {skill_name}"11after_complete:12- trigger: create-pr13mode: ask_first14condition: skills_modified15reason: "Submit improvements to repository"16- trigger: session-logger17mode: auto18context: "Self-improvement cycle complete"19# Note: on_error intentionally only logs to session to avoid infinite recursion20# Self-correction is triggered by other skills (debugger, code-reviewer) completing their work21on_error:22- trigger: session-logger23mode: auto24context: "Error captured in {skill_name}"25---2627# Self-Improving Agent2829> "An AI agent that learns from every interaction, accumulating patterns and insights to continuously improve its own capabilities." — Based on 2025 lifelong learning research3031## Overview3233This is a **universal self-improvement system** that learns from ALL skill experiences, not just PRDs. It implements a complete feedback loop with:3435- **Multi-Memory Architecture**: Semantic + Episodic + Working memory36- **Self-Correction**: Detects and fixes skill guidance errors37- **Self-Validation**: Periodically verifies skill accuracy38- **Hooks Integration**: Auto-triggers on skill events (before_start, after_complete, on_error)39- **Evolution Markers**: Traceable changes with source attribution4041## Research-Based Design4243Based on 2025 research:4445| Research | Key Insight | Application |46|----------|-------------|-------------|47| [SimpleMem](https://arxiv.org/html/2601.02553v1) | Efficient lifelong memory | Pattern accumulation system |48| [Multi-Memory Survey](https://dl.acm.org/doi/10.1145/3748302) | Semantic + Episodic memory | World knowledge + experiences |49| [Lifelong Learning](https://arxiv.org/html/2501.07278v1) | Continuous task stream learning | Learn from every skill use |50| [Evo-Memory](https://shothota.medium.com/evo-memory-deepminds-new-benchmark) | Test-time lifelong learning | Real-time adaptation |5152## The Self-Improvement Loop5354```55┌─────────────────────────────────────────────────────────────────┐56│ UNIVERSAL SELF-IMPROVEMENT │57├─────────────────────────────────────────────────────────────────┤58│ │59│ Skill Event → Extract Experience → Abstract Pattern → Update │60│ │ │ │ │ │61│ ▼ ▼ ▼ ▼ │62│ ┌─────────────────────────────────────────────────────┐ │63│ │ MULTI-MEMORY SYSTEM │ │64│ ├─────────────────────────────────────────────────────┤ │65│ │ Semantic Memory │ Episodic Memory │ Working Memory │ │66│ │ (Patterns/Rules) │ (Experiences) │ (Current) │ │67│ │ memory/semantic/ │ memory/episodic/ │ memory/working/│ │68│ └─────────────────────────────────────────────────────┘ │69│ │70│ ┌─────────────────────────────────────────────────────┐ │71│ │ FEEDBACK LOOP │ │72│ │ User Feedback → Confidence Update → Pattern Adapt │ │73│ └─────────────────────────────────────────────────────┘ │74│ │75└─────────────────────────────────────────────────────────────────┘76```7778## When This Activates7980### Automatic Triggers (via hooks)8182| Event | Trigger | Action |83|-------|---------|--------|84| **before_start** | Any skill starts | Log session start |85| **after_complete** | Any skill completes | Extract patterns, update skills |86| **on_error** | Bash returns non-zero exit | Capture error context, trigger self-correction |8788### Manual Triggers8990- User says "自我进化", "self-improve", "从经验中学习"91- User says "分析今天的经验", "总结教训"92- User asks to improve a specific skill9394## Evolution Priority Matrix9596Trigger evolution when new reusable knowledge appears:9798| Trigger | Target Skill | Priority | Action |99|---------|--------------|----------|--------|100| New PRD pattern discovered | prd-planner | High | Add to quality checklist |101| Architecture tradeoff clarified | architecting-solutions | High | Add to decision patterns |102| API design rule learned | api-designer | High | Update template |103| Debugging fix discovered | debugger | High | Add to anti-patterns |104| Review checklist gap | code-reviewer | High | Add checklist item |105| Perf/security insight | performance-engineer, security-auditor | High | Add to patterns |106| UI/UX spec issue | prd-planner, architecting-solutions | High | Add visual spec requirements |107| React/state pattern | debugger, refactoring-specialist | Medium | Add to patterns |108| Test strategy improvement | test-automator, qa-expert | Medium | Update approach |109| CI/deploy fix | deployment-engineer | Medium | Add to troubleshooting |110111## Multi-Memory Architecture112113### 1. Semantic Memory (`memory/semantic-patterns.json`)114115Stores **abstract patterns and rules** reusable across contexts:116117```json118{119"patterns": {120"pattern_id": {121"id": "pat-2025-01-11-001",122"name": "Pattern Name",123"source": "user_feedback|implementation_review|retrospective",124"confidence": 0.95,125"applications": 5,126"created": "2025-01-11",127"category": "prd_structure|react_patterns|async_patterns|...",128"pattern": "One-line summary",129"problem": "What problem does this solve?",130"solution": { ... },131"quality_rules": [ ... ],132"target_skills": [ ... ]133}134}135}136```137138### 2. Episodic Memory (`memory/episodic/`)139140Stores **specific experiences and what happened**:141142```143memory/episodic/144├── 2025/145│ ├── 2025-01-11-prd-creation.json146│ ├── 2025-01-11-debug-session.json147│ └── 2025-01-12-refactoring.json148```149150```json151{152"id": "ep-2025-01-11-001",153"timestamp": "2025-01-11T10:30:00Z",154"skill": "debugger",155"situation": "User reported data not refreshing after form submission",156"root_cause": "Empty callback in onRefresh prop",157"solution": "Implement actual refresh logic in callback",158"lesson": "Always verify callbacks are not empty functions",159"related_pattern": "callback_verification",160"user_feedback": {161"rating": 8,162"comments": "This was exactly the issue"163}164}165```166167### 3. Working Memory (`memory/working/`)168169Stores **current session context**:170171```172memory/working/173├── current_session.json # Active session data174├── last_error.json # Error context for self-correction175└── session_end.json # Session end marker176```177178## Self-Improvement Process179180### Phase 1: Experience Extraction181182After any skill completes, extract:183184```yaml185What happened:186skill_used: {which skill}187task: {what was being done}188outcome: {success|partial|failure}189190Key Insights:191what_went_well: [what worked]192what_went_wrong: [what didn't work]193root_cause: {underlying issue if applicable}194195User Feedback:196rating: {1-10 if provided}197comments: {specific feedback}198```199200### Phase 2: Pattern Abstraction201202Convert experiences to reusable patterns:203204| Concrete Experience | Abstract Pattern | Target Skill |205|--------------------|------------------|--------------|206| "User forgot to save PRD notes" | "Always persist thinking to files" | prd-planner |207| "Code review missed SQL injection" | "Add security checklist item" | code-reviewer |208| "Callback was empty, didn't work" | "Verify callback implementations" | debugger |209| "Net APY position ambiguous" | "UI specs need exact relative positions" | prd-planner |210211**Abstraction Rules:**212213```yaml214If experience_repeats 3+ times:215pattern_level: critical216action: Add to skill's "Critical Mistakes" section217218If solution_was_effective:219pattern_level: best_practice220action: Add to skill's "Best Practices" section221222If user_rating >= 7:223pattern_level: strength224action: Reinforce this approach225226If user_rating <= 4:227pattern_level: weakness228action: Add to "What to Avoid" section229```230231### Phase 3: Skill Updates232233Update the appropriate skill files with **evolution markers**:234235```markdown236<!-- Evolution: 2025-01-12 | source: ep-2025-01-12-001 | skill: debugger -->237238## Pattern Added (2025-01-12)239240**Pattern**: Always verify callbacks are not empty functions241242**Source**: Episode ep-2025-01-12-001243244**Confidence**: 0.95245246### Updated Checklist247- [ ] Verify all callbacks have implementations248- [ ] Test callback execution paths249```250251**Correction Markers** (when fixing wrong guidance):252253```markdown254<!-- Correction: 2025-01-12 | was: "Use callback chain" | reason: caused stale refresh -->255256## Corrected Guidance257258Use direct state monitoring instead of callback chains:259```typescript260// ✅ Do: Direct state monitoring261const prevPendingCount = usePrevious(pendingCount);262```263```264265### Phase 4: Memory Consolidation2662671. **Update semantic memory** (`memory/semantic-patterns.json`)2682. **Store episodic memory** (`memory/episodic/YYYY-MM-DD-{skill}.json`)2693. **Update pattern confidence** based on applications/feedback2704. **Prune outdated patterns** (low confidence, no recent applications)271272## Self-Correction (on_error hook)273274Triggered when:275- Bash command returns non-zero exit code276- Tests fail after following skill guidance277- User reports the guidance produced incorrect results278279**Process:**280281```markdown282## Self-Correction Workflow2832841. Detect Error285- Capture error context from working/last_error.json286- Identify which skill guidance was followed2872882. Verify Root Cause289- Was the skill guidance incorrect?290- Was the guidance misinterpreted?291- Was the guidance incomplete?2922933. Apply Correction294- Update skill file with corrected guidance295- Add correction marker with reason296- Update related patterns in semantic memory2972984. Validate Fix299- Test the corrected guidance300- Ask user to verify301```302303**Example:**304305```markdown306<!-- Correction: 2025-01-12 | was: "useMemo for claimable ids" | reason: stale data at click time -->307308## Self-Correction: Click-Time Computation309310**Issue**: Using useMemo for claimable IDs caused stale data311**Fix**: Compute at click time for always-fresh data312**Pattern**: click_time_vs_open_time_computation313```314315## Self-Validation316317Use the validation template in `references/appendix.md` when reviewing updates.318319## Hooks Integration320321### Wiring Hooks in Claude Code Settings322323Add to Claude Code settings (`~/.claude/settings.json`):324325```json326{327"hooks": {328"PreToolUse": [329{330"matcher": "Bash|Write|Edit",331"hooks": [332{333"type": "command",334"command": "bash ${SKILLS_DIR}/self-improving-agent/hooks/pre-tool.sh \"$TOOL_NAME\" \"$TOOL_INPUT\""335}336]337}338],339"PostToolUse": [340{341"matcher": "Bash",342"hooks": [343{344"type": "command",345"command": "bash ${SKILLS_DIR}/self-improving-agent/hooks/post-bash.sh \"$TOOL_OUTPUT\" \"$EXIT_CODE\""346}347]348}349],350"Stop": [351{352"matcher": "",353"hooks": [354{355"type": "command",356"command": "bash ${SKILLS_DIR}/self-improving-agent/hooks/session-end.sh"357}358]359}360]361}362}363```364365Replace `${SKILLS_DIR}` with your actual skills path.366367## Additional References368369See `references/appendix.md` for memory structure, workflow diagrams, metrics, feedback templates, and research links.370371## Best Practices372373### DO374375- ✅ Learn from EVERY skill interaction376- ✅ Extract patterns at the right abstraction level377- ✅ Update multiple related skills378- ✅ Track confidence and apply counts379- ✅ Ask for user feedback on improvements380- ✅ Use evolution/correction markers for traceability381- ✅ Validate guidance before applying broadly382383### DON'T384385- ❌ Over-generalize from single experiences386- ❌ Update skills without confidence tracking387- ❌ Ignore negative feedback388- ❌ Make changes that break existing functionality389- ❌ Create contradictory patterns390- ❌ Update skills without understanding context391392## Quick Start393394After any skill completes, this agent automatically:3953961. **Analyzes** what happened3972. **Extracts** patterns and insights3983. **Updates** relevant skill files3994. **Logs** to memory for future reference4005. **Reports** summary to user401402## References403404- [SimpleMem: Efficient Lifelong Memory for LLM Agents](https://arxiv.org/html/2601.02553v1)405- [A Survey on the Memory Mechanism of Large Language Model Agents](https://dl.acm.org/doi/10.1145/3748302)406- [Lifelong Learning of LLM based Agents](https://arxiv.org/html/2501.07278v1)407- [Evo-Memory: DeepMind's Benchmark](https://shothota.medium.com/evo-memory-deepminds-new-benchmark)408- [Let's Build a Self-Improving AI Agent](https://medium.com/@nomannayeem/lets-build-a-self-improving-ai-agent-that-learns-from-your-feedback-722d2ce9c2d9)409