PluginBench
Skill
Review
Audit score 70

self-improving-agent

charon-fan/agent-playbook

Universal self-improving agent that learns from all skill experiences using multi-memory architecture.

What is self-improving-agent?

A self-improvement system that learns from every skill interaction using semantic, episodic, and working memory. It automatically extracts patterns from skill completions and errors, then evolves the codebase through hooks-based self-correction and continuous feedback loops.

  • Implements multi-memory architecture (semantic + episodic + working) to capture and store patterns from skill experiences
  • Auto-triggers on skill events (before_start, after_complete, on_error) via hooks integration
  • Extracts reusable patterns from concrete experiences and abstracts them into actionable rules
  • Maintains episodic memory of specific skill interactions with outcomes and user feedback
  • Provides self-correction by detecting skill guidance errors and updating target skills
  • Generates evolution markers with source attribution for traceable codebase improvements

How to install self-improving-agent

npx skills add https://github.com/charon-fan/agent-playbook --skill self-improving-agent
Claude Code
Cursor
Windsurf
Cline

How to use self-improving-agent

  1. 1.Install the skill using the provided npx command
  2. 2.Allow the agent to run with Read, Write, Edit, Bash, Grep, Glob, and WebSearch tools enabled
  3. 3.Execute other skills normally; the self-improving agent automatically hooks into their lifecycle events
  4. 4.Review generated patterns in memory/semantic-patterns.json and memory/episodic/ directories
  5. 5.Provide user feedback ratings and comments after skill completions to improve pattern confidence
  6. 6.Approve pull requests when the agent submits skill improvements after completing self-improvement cycles

Use cases

Good for
  • After a debugging session, automatically extract the root cause pattern and update the debugger skill with new anti-patterns
  • When a code review catches a security issue, capture the insight and add it to the code-reviewer's checklist
  • Following a PRD creation task, learn from user feedback and refine the prd-planner's quality rules
  • During error handling, log the failure context and trigger self-correction in related skills
  • Periodically validate skill accuracy by reviewing episodic memory and updating semantic patterns
Who it's for
  • AI agents running multiple skills that need continuous improvement
  • Teams using agent playbooks who want skills to evolve from real usage patterns
  • Developers building lifelong learning systems for coding agents
  • Projects requiring traceable, research-backed self-improvement mechanisms

self-improving-agent FAQ

How does this avoid infinite recursion when errors occur?

The on_error hook only logs to session and does not trigger self-correction directly. Self-correction is triggered by other skills (debugger, code-reviewer) completing their work, preventing infinite loops.

What skills does this improve?

It can improve any skill in the agent playbook. The Evolution Priority Matrix targets prd-planner, architecting-solutions, api-designer, debugger, code-reviewer, performance-engineer, security-auditor, test-automator, qa-expert, and deployment-engineer based on the type of pattern discovered.

How is confidence in patterns calculated?

Patterns track confidence scores (0-1) and application counts. Confidence increases as patterns are successfully applied across multiple skill uses and validated by user feedback.

Can I manually trigger self-improvement?

Yes. You can trigger evolution manually by saying 'self-improve', 'analyze today's experiences', or asking the agent to improve a specific skill.

What format are memories stored in?

Semantic patterns are stored in memory/semantic-patterns.json, episodic memories in memory/episodic/ organized by date, and working memory in memory/working/ for current session context.

Full instructions (SKILL.md)

Source of truth, from charon-fan/agent-playbook.


name: self-improving-agent description: 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. allowed-tools: Read, Write, Edit, Bash, Grep, Glob, WebSearch metadata: hooks: before_start: - trigger: session-logger mode: auto context: "Start {skill_name}" after_complete: - trigger: create-pr mode: ask_first condition: skills_modified reason: "Submit improvements to repository" - trigger: session-logger mode: auto context: "Self-improvement cycle complete" # Note: on_error intentionally only logs to session to avoid infinite recursion # Self-correction is triggered by other skills (debugger, code-reviewer) completing their work on_error: - trigger: session-logger mode: auto context: "Error captured in {skill_name}"

Self-Improving Agent

"An AI agent that learns from every interaction, accumulating patterns and insights to continuously improve its own capabilities." — Based on 2025 lifelong learning research

Overview

This is a universal self-improvement system that learns from ALL skill experiences, not just PRDs. It implements a complete feedback loop with:

  • Multi-Memory Architecture: Semantic + Episodic + Working memory
  • Self-Correction: Detects and fixes skill guidance errors
  • Self-Validation: Periodically verifies skill accuracy
  • Hooks Integration: Auto-triggers on skill events (before_start, after_complete, on_error)
  • Evolution Markers: Traceable changes with source attribution

Research-Based Design

Based on 2025 research:

ResearchKey InsightApplication
SimpleMemEfficient lifelong memoryPattern accumulation system
Multi-Memory SurveySemantic + Episodic memoryWorld knowledge + experiences
Lifelong LearningContinuous task stream learningLearn from every skill use
Evo-MemoryTest-time lifelong learningReal-time adaptation

The Self-Improvement Loop

┌─────────────────────────────────────────────────────────────────┐
│                    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   │       │
│   └─────────────────────────────────────────────────────┘       │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

When This Activates

Automatic Triggers (via hooks)

EventTriggerAction
before_startAny skill startsLog session start
after_completeAny skill completesExtract patterns, update skills
on_errorBash returns non-zero exitCapture error context, trigger self-correction

Manual Triggers

  • User says "自我进化", "self-improve", "从经验中学习"
  • User says "分析今天的经验", "总结教训"
  • User asks to improve a specific skill

Evolution Priority Matrix

Trigger evolution when new reusable knowledge appears:

TriggerTarget SkillPriorityAction
New PRD pattern discoveredprd-plannerHighAdd to quality checklist
Architecture tradeoff clarifiedarchitecting-solutionsHighAdd to decision patterns
API design rule learnedapi-designerHighUpdate template
Debugging fix discovereddebuggerHighAdd to anti-patterns
Review checklist gapcode-reviewerHighAdd checklist item
Perf/security insightperformance-engineer, security-auditorHighAdd to patterns
UI/UX spec issueprd-planner, architecting-solutionsHighAdd visual spec requirements
React/state patterndebugger, refactoring-specialistMediumAdd to patterns
Test strategy improvementtest-automator, qa-expertMediumUpdate approach
CI/deploy fixdeployment-engineerMediumAdd to troubleshooting

Multi-Memory Architecture

1. Semantic Memory (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": [ ... ]
    }
  }
}

2. Episodic Memory (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"
  }
}

3. Working Memory (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

Self-Improvement Process

Phase 1: Experience Extraction

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}

Phase 2: Pattern Abstraction

Convert experiences to reusable patterns:

Concrete ExperienceAbstract PatternTarget 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

Phase 3: Skill Updates

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)

## Promotion Policy

Self-improvement has two separate jobs:

1. **Capture** facts, corrections, failed assumptions, and reusable patterns as memory or proposal artifacts.
2. **Promote** only validated patterns into `SKILL.md`, `AGENTS.md`, docs, or CLI behavior.

Default to capture-first. Promote a change only when one of these is true:

- The user explicitly asks to update a skill or repository instruction.
- The same pattern recurs across multiple episodes.
- A focused test or review proves the current guidance is wrong or incomplete.
- The change is low-risk documentation that preserves existing behavior and is clearly traceable.

Promotion targets:

| Artifact | Use For | Approval Level |
|----------|---------|----------------|
| `memory/episodic/*.json` | Raw episode facts and signals | Auto |
| `memory/semantic-patterns.json` | Candidate reusable patterns with confidence | Auto |
| `memory/proposals/*.md` | Proposed skill/doc/code changes with evidence | Auto |
| `SKILL.md` / `references/` | Validated workflow guidance | Ask first unless user requested editing |
| `AGENTS.md` / repo rules | Cross-repo behavior or hard constraints | Ask first |
| CLI/runtime code | Automation semantics | Require tests |

## 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. Create Proposal
   - Write a proposal with evidence, affected skill names, and expected behavior
   - Add correction marker text in the proposal, not directly in the skill yet
   - Update related patterns in semantic memory with low initial confidence

4. Validate Fix
   - Test the corrected guidance
   - Ask user to verify

5. Promote
   - Apply the skill/doc/code change after validation or explicit approval
   - Keep the source episode/proposal id in the change note

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

Self-Validation

Use the validation template in references/appendix.md when reviewing updates.

Hooks Integration

Runtime Trigger Source

agent-playbook self-improve reads skill chaining from each skill's SKILL.md frontmatter:

metadata:
  hooks:
    after_complete:
      - trigger: self-improving-agent
        mode: background
        reason: "Extract patterns"

Treat metadata.hooks as the source of truth. Do not maintain a second hardcoded hook map in runtime code. This keeps skill behavior auditable and lets Skill Creator style reviews inspect the same file that the agent executes.

Wiring Hooks in Claude Code Settings

For Claude Code, install hooks through agent-playbook init --hooks when possible. If you need manual setup, add hook entries to Claude Code settings at the appropriate user or project scope.

{
  "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.

Additional References

See references/appendix.md for memory structure, workflow diagrams, metrics, feedback templates, and research links.

Best Practices

DO

  • ✅ Learn from EVERY skill interaction
  • ✅ Extract patterns at the right abstraction level
  • ✅ Update multiple related skills
  • ✅ Track confidence and apply counts
  • ✅ Ask for user feedback on improvements
  • ✅ Use evolution/correction markers for traceability
  • ✅ Validate guidance before applying broadly
  • ✅ Write proposals before mutating durable skill guidance
  • ✅ Keep hook routing in metadata.hooks

DON'T

  • ❌ Over-generalize from single experiences
  • ❌ Update skills without confidence tracking
  • ❌ Ignore negative feedback
  • ❌ Make changes that break existing functionality
  • ❌ Create contradictory patterns
  • ❌ Update skills without understanding context
  • ❌ Silently promote self-improvement findings into repo rules
  • ❌ Duplicate hook definitions in CLI code and skill frontmatter

Quick Start

After a high-signal skill workflow completes, this agent can:

  1. Analyzes what happened
  2. Extracts patterns and insights
  3. Writes memory and proposal artifacts
  4. Promotes validated improvements only when approval or evidence is sufficient
  5. Reports summary to user

References

Related skills

More from charon-fan/agent-playbook and the wider catalog.

PL

planning-with-files

charon-fan/agent-playbook

Uses persistent markdown files for general planning, progress tracking, and knowledge storage (Manus-style workflow). Use for multi-step tasks, research projects, or general organization WITHOUT mentioning PRD. For PRD-specific work, use prd-planner skill instead.

1.1k installsAudited
SE

security-auditor

charon-fan/agent-playbook

Security vulnerability expert covering OWASP Top 10 and common security issues. Use when conducting security audits or reviewing code for vulnerabilities.

935 installs
AR

architecting-solutions

charon-fan/agent-playbook

Designs technical solutions and architecture. Use when user says "design solution", "architecture design", "technical design", or "方案设计" WITHOUT mentioning PRD. For PRD-specific work, use prd-planner skill instead.

762 installs
SK

skill-router

charon-fan/agent-playbook

Intelligently routes user requests to the most appropriate Claude Code skill. ALWAYS use this skill FIRST when user asks for help, mentions "skill", "which", "how to", or seems unsure about which approach to take. This is the default entry point for all skill-related requests.

758 installsAudited
TE

test-automator

charon-fan/agent-playbook

Test automation framework expert for creating and maintaining automated tests. Use when user asks to write tests, automate testing, or improve test coverage.

724 installsAudited
PR

prd-planner

charon-fan/agent-playbook

Creates PRDs using persistent file-based planning. Use when user explicitly says "PRD", "product requirements document", or "产品需求文档". Combines PRD methodology with planning-with-files to avoid context switching.

715 installs