Curates agent memory and turns repeated lessons into reviewed rules: memory health checks, pattern extraction, feedback and regression analysis. Use when MEMORY.md has grown or has broken pointers, when the same correction keeps recurring, when a rule or memory change may have made the agent worse, or when building agents that learn from their own sessions.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Self Improving Agent?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/borghei-self-improving-agent)
---
name: self-improving-agent
description: >
Curates agent memory and turns repeated lessons into reviewed rules: memory health checks,
pattern extraction, feedback and regression analysis. Use when MEMORY.md has grown or has broken
pointers, when the same correction keeps recurring, when a rule or memory change may have made the
agent worse, or when building agents that learn from their own sessions.
license: MIT + Commons Clause
metadata:
version: 2.2.0
author: borghei
category: engineering
domain: ai-agents
tier: POWERFUL
updated: 2026-11-08
tags: [self-improvement, ai-agents, feedback-loops, auto-memory, meta-learning, memory-curation]
frameworks: feedback-loops, memory-curation, meta-learning, performance-regression
---
# Self-Improving Agent
The agent captures what went wrong or right in a session, curates it in memory, and proposes promoting a lesson into a permanent rule only when it has recurred and a person has approved it. Rules compound: a wrong rule repeats its mistake in every later session, so promotion is a reviewed change, never an automatic one.
## Core Capabilities
- **Memory curation** — a layered memory stack (CLAUDE.md → MEMORY.md → session), review protocol, and promotion criteria for graduating learnings into enforced rules.
- **Feedback loops** — outcome classification, signal extraction, and a capture template that turn every task result into a structured learning.
- **Regression detection** — metrics, thresholds, and a response protocol that flags performance degradation within a few sessions.
- **Skill extraction** — criteria and a 4-step process to graduate proven patterns into standalone skill packages.
- **Meta-learning** — adaptive capture strategy and anti-pattern detection so the agent learns *what* is worth learning.
- **Continuous calibration** — confidence scoring and belief revision for resolving contradictions across learned knowledge.
## When to Use
- Building agents intended to improve over time rather than stay stateless.
- Managing auto-memory (MEMORY.md) and deciding what to keep, promote, or retire.
- Designing self-correcting feedback loops and regression alarms for agent behavior.
- Graduating recurring solutions into reusable skill packages.
## Clarify First
Before capturing or promoting learnings, settle the inputs below. When one is missing or vague and would change the result, ask about it; when it wouldn't, use a sensible default and say which one you used.
- **Loop stage:** remember / extract / promote / review (routes the sub-skill and the whole workflow).
- **Source data:** which session logs, `MEMORY.md`, and rules dir to operate on (the subject the tools read and write).
- **Promotion bar:** min occurrences / confidence threshold for graduating a learning into an enforced rule (`--min-occurrences`; decides what is kept vs discarded).
Ask about the two or three inputs that matter most for this request, not the whole list. If the user wants a result straight away, produce it and state your assumptions at the top.
## Sub-Skills
Compound sub-skill architecture — each file in `skills/` handles one step of the improvement loop:
| Sub-Skill | File | Purpose |
|-----------|------|---------|
| **Remember** | `skills/remember.md` | Capture errors and learnings from current session |
| **Extract** | `skills/extract.md` | Extract reusable patterns from completed work |
| **Promote** | `skills/promote.md` | Graduate proven patterns to permanent rules |
| **Review** | `skills/review.md` | Audit memory health, prune stale entries |
| **Status** | `skills/status.md` | Dashboard showing memory state and learning progress |
Flow: `Remember → Extract → Promote → Review`, with `Status` providing visibility back into the cycle.
## Workflow
1. **Check memory health:** `memory_health_checker.py --memory <MEMORY.md>`. It reads both layouts: `## ` section entries, and index files whose lines point at topic files (Claude Code auto-memory), where it reads each topic file's frontmatter and age and flags pointers to missing files.
2. **Find recurring lessons** in session or feedback logs with `pattern_extractor.py` and `feedback_analyzer.py patterns`.
3. **Propose a promotion:** `rule_promoter.py --entry-title ... --dry-run` (the default; nothing is written) prints the rule text and whether it meets the bar (recurrence, confidence).
4. **Get approval:** show the user the proposed rule and where it will land (CLAUDE.md or `.claude/rules/`), and apply with `--apply` only after an explicit yes.
5. **Watch for regressions** after a rule change with `regression_detector.py compare`; roll the rule back if first-attempt success or corrections get worse.
6. Done when memory has no broken pointers or over-limit files, every promoted rule was approved, and the regression check after the change is clean.
## Quick Start
```bash
# from engineering/self-improving-agent/
python3 scripts/memory_health_checker.py --memory assets/memory_index/MEMORY.md # exit 1: one broken pointer
python3 scripts/feedback_analyzer.py analyze --input assets/sample_feedback.jsonl # exit 1: first-attempt success 25%
python3 scripts/regression_detector.py compare --input assets/sample_metrics.json # exit 1: regression after a rule change
```
Real output of the first command (abridged):
```
MEMORY HEALTH CHECK
Status: NEEDS_ATTENTION
Lines: 6/200
Entries: 3
ACTIONABLE ENTRIES
[STALE] Line 5: Staging URL
- Pointer to missing topic file: reference_staging.md
Fix: Delete line 5 of the index, or create reference_staging.md with the lesson it should hold.
Read 6 lines, 3 entries.
FIX 1 issue
```
## Tools Overview
| Tool | Purpose | Example |
|------|---------|---------|
| `pattern_extractor.py` | Recurring approaches in session logs (JSONL): PROMOTE if it recurs and succeeds, AVOID if it recurs and fails | `python3 scripts/pattern_extractor.py --input assets/sample_sessions.jsonl --min-occurrences 3` |
| `memory_health_checker.py` | Line limits, stale and duplicate entries, broken topic pointers, promotion candidates | `python3 scripts/memory_health_checker.py --memory ./MEMORY.md` |
| `rule_promoter.py` | Validate and (after approval) apply a promotion from `## ` section memory to rules | `python3 scripts/rule_promoter.py --memory assets/memory_sections/MEMORY.md --list-candidates` |
| `feedback_analyzer.py` | `analyze`, `patterns`, `trends`, `opportunities` over a feedback log | `python3 scripts/feedback_analyzer.py analyze --input feedback.jsonl` |
| `regression_detector.py` | `compare`, `diagnose --metric M`, `report` for baseline vs current sessions | `python3 scripts/regression_detector.py report --input metrics.json` |
| `rule_manager.py` | add / list / search / prune / promote / demote over a JSON rules file | `python3 scripts/rule_manager.py --db rules_kb.json list` |
`scripts/common.py` is a shared helper, not a command. Every command accepts `--format text|json` (`--json` is a legacy alias).
## Exit Codes
| Code | Meaning |
|------|---------|
| 0 | Clean: nothing to act on (or, for `rule_manager.py`, the operation succeeded) |
| 1 | Findings: memory issues, a failed health threshold, a recurring pattern to promote or avoid, a regression, a blocked or ready-to-list promotion candidate, or `rule_manager.py prune --dry-run` found rules to remove |
| 2 | Unusable input, one line on stderr: file missing, empty or not a file, no usable entries, wrong JSON shape, unknown rule id, unknown or ambiguous entry title, `--apply` without target, or `--dry-run` with `--apply` |
Rules the tools rely on:
- A memory path, rules database or log that does not exist is exit 2, never a "stateless" or empty result. Only `rule_manager.py add` creates a database.
- `memory_health_checker.py --rules <dir>` is optional, but the directory must already exist (exit 2 otherwise); add `--rules ./.claude/rules/` only once you have promoted a rule there.
- A field missing from a log entry (`corrections`, `turns`) is never counted as 0: `feedback_analyzer.py` reports `n/a` and a finding that names the missing field. A log with no `corrections` at all exits 1, not PASS.
- `regression_detector.py` lists non-numeric values in numeric fields as notes, and labels a verdict drawn from fewer than 5 sessions per period as LOW CONFIDENCE.
- A metric the input cannot support (no `tool_calls`, no `context_items_retrieved`) is reported as `n/a`, not scored as 0.
- Thresholds (70% first-attempt success, 5% tool errors, regression deltas, line limits, scoring weights) are internal heuristics, labelled as such in the output; tune them to your own baseline.
- `rule_promoter.py` handles section-style memory only; for an index-style MEMORY.md it exits 2 and the promotion is done by hand. An entry with no `**Recurrence**` or `**Confidence**` line is blocked, not defaulted.
## Samples
`assets/contract.json` runs every command on a sound input (exit 0), a flawed one (exit 1) and a malformed one (exit 2): `sound_*`, `sample_*`/`clean_*` and `malformed_*` files, plus `memory_clean/`, `memory_sections/` and `memory_index/`. Check with `python3 scripts/skill_contract_check.py --skill engineering/self-improving-agent` from the repo root.
## Anti-Patterns
**Mistake:** Promoting a lesson into CLAUDE.md or rules without asking.
**Why it matters:** Rules apply to every later session; a rule learned from one bad day keeps steering the agent wrong long after.
**Instead:** Show the dry-run rule text and target, and apply only after the user says yes.
**Mistake:** Promoting after a single occurrence.
**Why it matters:** One-off fixes are often context-specific; as rules they misfire elsewhere.
**Instead:** Wait for the recurrence threshold (3 by default) or an explicit user instruction.
**Mistake:** Letting memory grow without curation.
**Why it matters:** Over-limit or duplicate memory crowds the context window and buries the lessons that matter.
**Instead:** Run the health check on a schedule, consolidate duplicates, and delete pointers to topics that no longer hold.
## Reference Documentation
Load the reference that matches the task — keep this file lean and pull detail on demand:
- **[references/memory-curation-guide.md](references/memory-curation-guide.md)** — the memory stack, review protocol, promotion criteria/targets, the Weekly Memory Health Check workflow, and the continuous-calibration (confidence scoring + belief revision) machinery. Read when curating MEMORY.md or promoting learnings to rules.
- **[references/feedback-loop-patterns.md](references/feedback-loop-patterns.md)** — the core improvement-loop architecture and maturity levels, outcome classification + signal extraction, the capture template, regression metrics/response, the post-session and regression-investigation workflows, common pitfalls, troubleshooting, and the success-criteria bar. Read when designing feedback capture or diagnosing a regression.
- **[references/meta-learning-architectures.md](references/meta-learning-architectures.md)** — skill-extraction criteria and process, the adaptive capture strategy, and anti-pattern detection. Read when the agent should adapt its own learning strategy or extract a proven pattern into a skill.
- **[references/self-improvement-methodology.md](references/self-improvement-methodology.md)** — the five layers of agent learning, the confidence-scoring model, the promotion decision tree, the memory-curation checklist, anti-patterns, and the metrics/thresholds table. Read for the end-to-end methodology overview.
## Scope & Limitations
**This skill covers:**
- Architectural patterns for building agents that learn from execution history and user feedback.
- Memory lifecycle management: capture, curation, promotion, and retirement of learned knowledge.
- Performance regression detection frameworks and response protocols for agent systems.
- Skill extraction methodology for graduating proven patterns into reusable, standalone packages.
**This skill does NOT cover:**
- Runtime agent orchestration or multi-agent coordination -- see `engineering/agent-workflow-designer`.
- Prompt engineering, testing, or versioning of the prompts themselves -- see `engineering/prompt-engineer-toolkit`.
- Infrastructure-level observability (logging, tracing, alerting dashboards) -- see `engineering/observability-designer`.
- Initial agent architecture design, tool selection, or capability planning -- see `engineering/agent-designer`.
## Files
| File | Purpose |
|------|---------|
| `skills/*.md` | Sub-skills: remember, extract, promote, review, status |
| `scripts/*.py` | Six stdlib CLIs plus the shared `common.py` helper |
| `assets/contract.json` | Declared runs and exit codes for every command |
| `assets/memory_index/` | Index-style MEMORY.md with two topic files and one broken pointer (flawed) |
| `assets/memory_clean/`, `assets/memory_sections/` | Section-style memory: a healthy one, and one with a ready, a near-ready and an unrecorded entry |
| `assets/sample_feedback.jsonl`, `assets/sound_feedback.jsonl` | Twelve entries with a recurring npm/pnpm correction (flawed) and ten clean ones |
| `assets/sample_sessions.jsonl`, `assets/clean_sessions.jsonl` | Session logs with one approach that recurs and works, one that recurs and fails; and an uneventful one |
| `assets/sample_metrics.json`, `assets/sound_metrics.json` | Baseline vs current around a rule change (regression) and an unchanged pair |
| `assets/sample_rules_kb.json` | A rules knowledge base for `rule_manager.py` |
| `assets/malformed_*` | Unusable inputs, each exits 2 |