Agent Self-Improvement Harness (5/12) — skill-evolve: How an Agent Builds and Fixes Its Skills

Automatic pattern analysis after complex tasks, promotion via repetition threshold, and infinite-loop prevention


Summary

  • After completing a complex task (5+ tools, error recovery), the agent automatically analyzes patterns and registers skill candidates.
  • Only patterns with sufficient repetitions are promoted to skills — a low threshold causes coincidences to become skills.
  • Skills self-improve through a trial-apply → issue-detect → immediate-patch loop.
  • Self-improvement triggers exclusively after real tasks — anything else causes an infinite loop.

Background

Agent skills are typically authored by humans. A developer writes "in this situation, follow this procedure."

The problem is scale. As the variety of tasks an agent handles grows, maintaining every skill manually becomes impractical. Worse, the patterns an agent discovers during actual work — "this approach worked" — are often impossible for a human to anticipate in advance.

The question then becomes: what if an agent could generate its own skills? Detect recurring patterns during complex work, and formalize them into reusable skills.

In OpenClaw, this was implemented under the name skill-evolve.


Body

1. Trigger Conditions — Not Every Task Gets Analyzed

Running pattern analysis after every task is wasteful. A single-line edit or a trivial file change contains nothing worth extracting.

Two trigger conditions were defined:

  • Tasks using 5 or more distinct tools. Multi-tool combinations signal procedure, not simple repetition.
  • Tasks that include error recovery. A sequence that hit an error and resolved it is inherently valuable knowledge.
  • Either condition being met triggers automatic pattern analysis after task completion.

This single filter reduced the analysis target to roughly 20% of all tasks. The remaining 80% were simple tasks that needed no skill extraction.

2. skill-candidates.json — Candidate Registration and Repetition Threshold

A detected pattern does not immediately become a skill. It is first registered as a candidate in skill-candidates.json.

{
  "candidates": [
    {
      "pattern": "SQLite migration with column rename",
      "occurrences": 2,
      "first_seen": "<initial_stage>",
      "last_seen": "<recent_stage>",
      "status": "candidate",
      "tool_sequence": ["read_file", "execute_sql", "write_file", "verify_schema", "run_test"],
      "error_recovery": "column mismatch → ALTER TABLE → re-migrate"
    }
  ]
}

The key design decision is the repetition threshold. The initial value was set low (2 occurrences). The results were poor.

Problem with a low threshold: Coincidences became skills. Two consecutive API errors with similar symptoms were caused by entirely different root causes — one was a timeout, the other an expired auth token. Pattern detection treated them as the same pattern, and the resulting skill proposed the wrong fix.

After raising the threshold: Higher repetition count substantially reduces the probability of coincidence. It signals that the pattern recurs structurally. Incorrect skill generation dropped to near zero.

OpenClaw currently uses 3 occurrences as the baseline. Two was too low; five was too high and suppressed practical skill generation. Three is the empirically derived minimum that qualifies as "sufficiently repeated." Depending on the project's task volume, four may be appropriate.

3. Trial Application and Immediate Patching — Skills Have Bugs Too

Once a candidate crosses the threshold and is promoted, it does not go straight to production. It enters a trial application phase.

The next time a matching task arrives, the new skill is applied. The result is then verified against three criteria:

  • Did the procedure the skill proposed actually succeed?
  • Were there any unexpected side effects?
  • Were any steps missing?

If a problem is found, the skill file is patched immediately and the reason for the change is recorded. This is what "self-improvement" means in practice. A skill is not permanent once created — it is validated and refined with every application.

Real example: when a file migration skill was first created, the "create backup" step was absent. During trial application, a migration failure left no way to recover the original files. "Step 0: Backup source" was added immediately.

4. Infinite Loop Prevention — The Self-Improvement Trap

Self-improvement introduces a fundamental risk: a loop that improves the improvement process itself.

If pattern analysis is itself detected as a complex task, the system starts analyzing the analysis, then analyzing that analysis — an unbounded loop.

The prevention rule is simple: self-improvement triggers only after a real task.

Real task (file edit, code generation, bug fix, etc.)
  → Pattern analysis ✓ (triggered)

Pattern analysis itself
  → Pattern analysis ✗ (not triggered)

Skill patching itself
  → Pattern analysis ✗ (not triggered)

"Real task" is defined precisely: a task initiated by a user request that produces changes to project files. Meta-tasks — skill management, memory cleanup, pattern analysis — are excluded from the trigger scope.


Lessons Learned

Skill explosion. When the threshold was low, skill candidates proliferated rapidly. Most were useless, and managing the candidate list itself became a cost. Raising the threshold cut candidate generation rate by more than half and raised average quality.

Over-generalization. "Read a file, modify it, save it" matches nearly every task. Skills built on overly general patterns have no value. The minimum tool sequence length (5 steps) and the error-recovery requirement filtered out this class of candidates.

Token runaway during Hermes migration. When migrating self-improvement logic from OpenClaw to Hermes, the trigger rules were not ported first. The self-improvement loop began firing on meta-tasks, and token usage exploded. OpenClaw was restored and the trigger isolation rules were hardened. A Hermes retry is now under validation. When migrating a self-improvement architecture, port the trigger isolation rules before anything else.


Conclusion

The skill self-improvement loop gives an agent the ability to learn from experience.

  1. Restrict the trigger. Analyze only complex tasks — 5+ tools used or error recovery present.
  2. Promote after sufficient repetition. The minimum criterion that distinguishes structure from coincidence. OpenClaw's current baseline is 3.
  3. Trial-apply, then patch. Skills have bugs like code does. Fix them in use.
  4. Meta-tasks do not trigger. Infinite self-improvement loops are blocked at the source.

Given enough operating time, skills the agent generated from real work become more practical than the ones a human authored in advance — because the agent encountered those exact situations firsthand.

Series overview: Series index

๋Œ“๊ธ€

์ด ๋ธ”๋กœ๊ทธ์˜ ์ธ๊ธฐ ๊ฒŒ์‹œ๋ฌผ

Agent Memory Engine (2/10) — Building an AI Agent Memory System with SQLite Alone

"ML Foundations (9/9) — PyTorch vs TensorFlow, and the Road to Local LLMs"

"RAG Core Study (14/26) — Evaluation Sets with RAGAS & DeepEval"

"ML Foundations (8/9) — Deep Learning Architectures: CNN, RNN, Attention"

"ML Foundations (7/9) — Deep Learning Training: Optimizers, Regularization, Initialization"

OpenClaw to Hermes Migration (2/13) — What to Preserve, Partially Port, or Discard

AI Agents I Built (5/7) — Building an Automated Blogger API Publishing System