Handbooks  /  Self-Improving Agents
Handbook~14 min readAgentsworked math + runnable code
Handbook

Self-improving
agents.

The dream is an agent that gets better the more you use it — one that runs in production, notices what worked, and folds it back in. It's real, and it's not magic: improvement happens on exactly two axes. An agent can update its memory (write down what it learned) or update its weights (retrain on what it did). One is a notebook, instant and erasable; the other is a habit, powerful and permanent. Knowing which to use — and how to keep the loop from teaching itself the wrong thing — is the whole discipline.

01

The loop: act, keep what worked, improve

Every self-improving agent runs the same cycle: act on real tasks, evaluate which attempts succeeded, and fold the successes back into future behavior. This isn't new — it's the mechanism family behind STaR (finetune on self-generated correct rationales), Voyager (grow a skill library), and Reflexion (write lessons to memory after a failure). What's new is doing it online, on production traces, on a fast cadence.

The design decision that everything hinges on is where the improvement lands. "Fold it back in" can mean two very different things — write to a memory store, or update the model's weights — and they have opposite properties. Get the choice right and the loop compounds; get it wrong and it either fails to generalize or quietly corrupts the model.

02

Memory: instant, exact, erasable — but doesn't generalize

The first axis is an external memory: store a solved trajectory, a working snippet, a learned skill, and retrieve it when a similar situation returns. Its virtues are speed and reversibility — you can add a memory in one write and delete a bad one just as fast, with no retraining.

memory: recall(store, task) = 1 if task ∈ store else 0  ·  add/forget = instant, reversible

But it's exact, not generalizing: a stored solution helps that task (and near-duplicates) and does nothing for a genuinely unseen one. Memory is a lookup, not a lesson.

That makes memory the right tool for specific, recurring knowledge — this customer's preferences, this repo's build command, this API's quirk — and for anything you might need to revoke. When the improvement should be surgical and undoable, it goes in memory.

03

Weights: generalizing, permanent — and risky

The second axis updates the model itself: fine-tune on filtered successful traces. Unlike memory, a weight update generalizes — train on enough solved instances of a task type and the model gets better at unseen instances of it too. That's the improvement memory can't buy.

weights: accuracy climbs on unseen similar tasks  ·  bounded by data quality  ·  hard to reverse

The catch is permanence. You can forget a memory; you cannot cleanly un-train a weight update. Whatever passed your filter is now baked into the model's habits.

Which is why the filter is everything. Train on verified-correct traces only — the STaR move — and the loop bootstraps toward a ceiling. Skip the filter and you're training on your own confident mistakes, and the loop can drift or collapse. It's the same lesson as RL environment design: what you reinforce is what you get, so reinforce only what you can confirm.

04

The trade-off, and the rails that keep it safe

Memory updateWeight update
Speedinstantslow (a training run)
Generalizationnone (exact recall)yes (to unseen similar tasks)
Reversibilityinstant (forget)hard (bake-in)
Best forspecific, recurring, revocablebroad skills worth making permanent

The safety rails follow directly from that last asymmetry — permanence raises the stakes:

  • Filter first. Only verified-correct traces enter any update. This is the single most important rail.
  • Prefer reversible. When memory can do the job, use it — a mistake you can delete beats one you can't.
  • Canary before rollout. Test a freshly-updated model on a held-out set; keep the ability to roll back.
  • Watch for drift & gaming. A loop optimizing its own signal can find and exploit its holes — monitor for it.
The key idea

Match permanence to confidence. Reversible memory for anything you're unsure about or might revoke; permanent weight updates only for filtered, verified, broadly-useful behavior you'd stake the model on. The runnable model below makes the two axes' properties concrete.

05

Why it matters

Self-improvement is moving from research to production — coding agents that retrain on a short cadence from their own accepted edits, assistants that accumulate skills across sessions. The payoff is compounding: an agent that's a little better every day. The risk is also compounding: a loop that learns from its own errors degrades every day. The difference between the two is entirely in the discipline above — filter, prefer reversible, canary, monitor.

The clean mental model to carry: an agent has a notebook and a set of habits. Write to the notebook freely; change habits only with proof. Everything else — online RL, skill libraries, trace pipelines — is machinery in service of that one judgment call about where a lesson belongs.

Read next

The self-training seed: STaR. The skill-library pattern: Voyager. The reflect-and-remember loop: Reflexion.

RUN IT YOURSELF

Two axes of improvement, side by side

The whole design choice is in the properties. Memory recalls a stored task exactly and can be added or forgotten instantly — but gives an unseen task nothing. Weights improve unseen similar tasks (they generalize) but bake in whatever passed the filter, which is why you keep only verified-correct traces and the flywheel climbs toward a ceiling. Watch memory recall a task and then forget it, watch weights lift an unseen task where memory can't, and watch the safety filter drop the bad traces.

CPython · WebAssembly
Frequently asked

Quick answers

What is a self-improving agent?

One that gets better from its own experience — running tasks, keeping what worked, and folding it back into future behavior via memory updates or weight updates. The first is fast and reversible; the second generalizes but is permanent.

Memory vs weight improvement?

Memory stores concrete experiences for exact recall — instant, erasable, no generalization. Weights fine-tune on filtered traces — generalizes to unseen similar tasks, but bakes in what you trained on. A notebook versus a habit.

Why filter traces before training?

A loop trained on its own output amplifies its own mistakes. Filtering to verified-correct traces means the model learns from successes, not confident errors — the same what-you-reinforce-is-what-you-get rule as RL.

What safety rails are needed?

Filter to correct-only; prefer reversible memory over irreversible weights; canary-test and keep rollback; watch for drift and reward hacking. You can forget a bad memory but can't cleanly un-train a bad weight update.

Finished this one? 0 / 160 Handbooks done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.