Small Models Decide, Large Models Code: A Recursive Self-Improvement Framework Explained
Why do large language models get stuck in endless bug-fixing loops when asked to improve code autonomously? This article breaks down a recursive self-improvement (RSI) framework that separates strategy from execution: a small model handles high-level decision-making with cross-round memory, while a large model focuses on turning strategies into working code. It covers the three core components—decision core, workspace, and evaluation arena—along with UCB-based policy learning, structured strategy memory, and rigorous evaluation practices to prove that progress is real.
1. The Starting Problem: Why Models Get Stuck in a “Bug-Fixing Loop”
When a model is asked to autonomously complete programming and optimization tasks, a recurring pattern emerges: it tends to make incremental patches on top of existing implementations. A failing test triggers a one-line fix; if that fails, another patch. The model rarely stops to ask whether the originally chosen algorithmic approach was wrong in the first place. This local patching behavior is efficient for short tasks, but it quickly exhausts the budget on tasks that require structural breakthroughs.
The root cause can be broken down into two layers:
- Capability mismatch: Proposing a new algorithmic route (searching the strategy space) and turning that route into runnable code (executing the implementation space) are two different capabilities. Assigning both to a single model makes it gravitate toward the implementation patterns it knows best.
- Lack of cross-round memory: Most execution loops are stateless. Each round only sees the current error message, with no awareness that “this route has already failed three times,” so the model repeats the same mistakes.
Decoupling decision-making from execution, and giving the decision side cross-round memory, is the fundamental starting point for this kind of framework.
2. Overall Architecture: Decision Core, Workspace, and Evaluation Arena
A usable RSI framework typically consists of three decoupled components:
- Decision core: Online policy learning that determines “what to try next.”
- Workspace: Skill and experience management that determines “which existing assets to use.”
- Evaluation arena: Unified, reproducible assessment that determines “whether this step actually improved things.”
The three are coupled through a shared state and a unified evaluation protocol, forming a closed loop. Without the third component, the entire loop degenerates into a random walk that only appears to make progress.
3. Decision Core: Shared Search State and Online Policy Learning
3.1 Shared Search State
The decision core maintains a continuously updated experiment archive—essentially a scored evolution tree that records at minimum:
- Tried code versions and their evaluation results;
- Derivation relationships between versions (which version was modified from which);
- The strategy label for each version (explore a new route vs. improve an existing implementation);
- Branches not yet explored;
- Remaining experiment budget.
With it, decision-making upgrades from “looking at the current error” to “looking at the entire search tree.”
3.2 UCB-Based Policy Learning
A classic approach to balancing exploitation and exploration is the upper confidence bound method. The KL variant (KL-UCB) replaces the simple mean-plus-variance bound with a confidence interval over the observed distribution, making it more sensitive to binary success/failure signals. In this context:
- Exploitation: Prioritize expanding versions with high historical success rates;
- Exploration: Give higher priority to branches with few visits and high uncertainty;
- Budget awareness: The less budget remains, the more the policy leans toward exploitation.
3.3 Memory-Based Policy Learning
Merely recording “success/failure” carries too little information. A more effective approach is to distill experience into structured strategy memory that includes applicability conditions and concrete guidance:
{"strategy_id": "S-017","context": {"task_type": "combinatorial optimization", "bottleneck": "search space too large"},"action": "Reduce problem size first, then run the main algorithm","outcome": "success","evidence": {"trials": 4, "win_rate": 0.75},"confidence": 0.7,"last_used": "round-23"}
Memory entries are reinforced or revised as new experiments arrive, and retired when their applicability conditions no longer hold—this is the key to preventing the experience base from bloating into a noise base.
3.4 Research Workflow: Breaking Out of the Patching Mindset
When all historical versions are constrained by the same line of thinking, an explicit “route change” channel is needed, usually with two collaborating roles:
- Proposer: Analyzes the task definition, the existing execution harness, and historical results, identifies capability gaps, and proposes a new approach orthogonal to the current route;
- Executor: Turns the proposal into code, completes debugging and self-testing, and returns structured results.
The closed loop in pseudocode:
state = SharedSearchState(budget=N)while state.remaining_budget > 0:node = state.select_node(KL_UCB) # select a historical versionmode = policy.choose_mode(node) # explore or improveplan = proposer.analyze(task, harness, state) # propose a strategypatch = worker.implement(plan, workspace.skills)result = arena.evaluate(patch, baseline=node) # unified evaluationstate.update(node, patch, result) # write back to the search treeworkspace.distill(result) # distill/revise experience
4. Workspace: Making Experience Reusable, Not Just Retellable
The workspace solves not “remembering conclusions” but “remembering executable assets”:
- Skill library: Persist repeatedly useful implementations (data loading, validation, benchmark harnesses) as callable units to avoid rewriting them every round;
- Experience entries: The strategy memory described above, with applicability conditions and confidence levels;
- Version and artifact management: Code, logs, and evaluation artifacts are archived uniformly so any historical version can be reproduced;
- Retirement mechanism: Low-confidence experiences, those unused for a long time, or those conflicting with new evidence are downgraded or removed.
On the engineering side, this component pairs well with general-purpose cloud capabilities: object storage for experiment artifacts, container platforms for isolated and reproducible execution environments, logging services and monitoring alerts for tracking long-running loops, and message queues to decouple the proposer and executor roles.
5. Evaluation Arena: Proving That Progress Is Real
The biggest risk in RSI is self-deception. Credible evaluation must at least satisfy:
- Same-baseline comparison: New versions must be compared against their parent version and fixed baselines on the same set of test cases;
- Budget alignment: Fix the number of experiments or compute budget when comparing; otherwise conclusions are invalid;
- Repetition and variance: Run the same configuration multiple times and report both means and variance, so a single lucky run doesn’t drive decisions;
- Multi-dimensional metrics: Beyond pass rate, include runtime, resource usage, and code complexity to prevent overfitting to the test set;
- Regression protection: Failures introduced by a new version must be explicitly recorded and must not be hidden by averaged scores.
6. Common Pitfalls and Practical Recommendations
- Pitfall 1: Letting the small model directly modify code. A safer division of labor is small model for strategy, large model for implementation—single responsibilities are easier to evaluate.
- Pitfall 2: Storing only conclusions in memory. Experience without applicability conditions will mislead later decisions.
- Pitfall 3: Unbounded loops. Set limits on rounds, duration, and cost, and support pausing and resuming at any time.
- Pitfall 4: Drifting evaluation criteria. Version and freeze evaluation scripts; otherwise cross-round comparisons lose meaning.
In practice, start by validating the closed loop on a small task set before gradually opening up the strategy space. Also treat end-to-end structured logs as a first-class citizen: they serve both as a debugging aid and as raw material for experience distillation.
7. Conclusion
The value of recursive self-improvement lies not in “a model writing itself,” but in engineering the improvement process: explicitly maintaining search state, using confidence bounds to balance exploration and exploitation, structuring experience into retirable memory, and constraining every step’s gains with rigorous evaluation. When decision-making and execution are cleanly layered, even a billion-parameter-scale small model can contribute high-quality directions at the strategy level, while the large model focuses on turning those directions into runnable, verifiable implementations.
