Proposes gated, reversible edits to the agent's own prompts or skills from successful runs only. Use only when a human asked the system to evolve its instructions.
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 Brain?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/andreibesleaga-brain-3bfac85d)
---
name: self-improvement
description: Proposes gated, reversible edits to the agent's own prompts or skills from successful runs only. Use only when a human asked the system to evolve its instructions.
triggers: [self improvement, evolve my instructions, rewrite my own prompt, improve own skill]
tags: [brain]
context_cost: high
tools: [replace_file_content, task_boundary]
---
# Self-Improvement Skill
## Goal
> "The software that writes itself."
Propose small, reversible edits to the agent's own instructions, based on successful runs, and only when the human asked for this.
## Steps
## 1. Evolutionary Prompts (The Genome)
Treat the `system_prompt` and `skill.md` files as **DNA**.
- **Genes:** Individual instructions (e.g., "Always use TDD").
- **Phenotype:** The agent's actual behavior in a session.
- **Fitness Function:** Did the user accept the code? Did the tests pass?
## 2. The Mutation Cycle
When the agent encounters a novel failure or success:
1. **Selection:** Identify the "Gene" (Prompt Instruction) responsible.
2. **Mutation:** Rewrite the instruction.
- *Example:* Change "Write clean code" -> "Write clean code adhering to AIRBNB style guiding."
3. **Crossover:** Combine two successful skills into a new hybrid skill.
## 3. Recursive Self-Editing
The agent may edit its own skill files only when the human asked for it in this request. Edit on a branch named `evolve/<name>`, never on main (`update-scan.skill`).
**Protocol:**
1. **Trigger:** "I keep failing to import this library correctly."
2. **Analysis:** "My knowledge base is outdated."
3. **Action:** edit the skill file concerned (for example `<skill-name>.skill.md`) on the `evolve/<name>` branch.
4. **Commit:** prepare the commit ("Updated skill memory with correct import syntax.") for the human; run it only if asked.
## 4. Safety Guardrails (Homeostasis)
To prevent "Cancer" (Runaway bad mutations):
- **Version Control:** All skill edits must be committed by the human: prepare the commit command and run it only if the human asked for it in this request (Constitution Article 0).
- **Revert:** If `success_rate` drops after a mutation, auto-revert.
- **Core Immutable:** The "Prime Directives" (Safety, Obedience) cannot be mutated.
## 5. Implementation
```python
def optimize_prompt(task_history):
# 1. Analyze Failure
failure_pattern = find_pattern(task_history, status="failed")
# 2. Propose Mutation
new_instruction = llm.generate_fix(failure_pattern)
# 3. Simulate (Mental Sandbox)
predicted_success = llm.simulate(new_instruction)
# 4. Integrate
if predicted_success > threshold:
update_skill_file(new_instruction)
```
## Cost & Permission Gating
Self-improvement (prompt/gene evolution) only runs inside `GABBE_AUTONOMY` + budget bounds:
- **A2 paradigm only:** evolve from **successful** trajectories. Apply the misaligned-replay guard — never integrate a mutation derived from a failed/known-bad run, or one that ingested external text, without sanitizing first (see Security below).
- **Cost-gated:** do not spend budget evolving when a cheaper static choice already meets the bar. Evolution that needs expensive search/SOTA models requires human approval (Article X).
- **Canary + rollback:** prefer shadow/canary adoption of an evolved gene with easy revert; version it so a regression is reproducible (`brain/learning-adaptation.skill`).
- **Auditable:** log every adopted/rejected mutation to `AUDIT_LOG.md`; humans must be able to see and revert what evolved (`update-scan.skill`).
## Constraints
- Edit only skills the human named; keep the safety block of each skill unchanged.
- Each edit is one small change that can be reverted on its own.
## Output Format
For each proposed edit: the skill file, the old and new text, the successful run that motivates it, and the check that shows no regression. Log adopted and rejected edits in `AUDIT_LOG.md`.
## Limits and safety
- Run only when the human asked the system to evolve its instructions; work on a branch `evolve/<name>`, never on main.
- Learn only from successful runs; clean any failure text of instructions before using it.
- Keep the safety rules (Constitution, human approval) in a separate block of each skill and never edit that block.
- A test the agent changed cannot count as proof of improvement; use an independent check such as mutation testing.
- Do not narrow a general skill to the last bug. Simulate a change in text only; do not run the edited skill on live files.
- Prepare the commit command and run it only when asked.