How Small Models Guide Large Models Toward Recursive Self-Improvement
When code fails, large models often keep patching the current approach. This article explains a recursive self-improvement architecture in which a smaller model plans experiments and a larger model implements them, using shared search state, exploration-exploitation balance, strategy memory, a structured workspace, and evaluation to decide whether real progress is occurring.
In intelligent programming systems, a model that encounters a failed run usually keeps revising variables, adjusting conditions, or replacing local implementation details along its current line of thinking. That approach works well for simple defects, but it yields limited gains when the real problem is a poor algorithm choice, an unreasonable system structure, or a misunderstanding of the task goal.
A more promising direction is to separate strategy generation from strategy execution across models with different capabilities and sizes. A smaller model analyzes experiment history, looks for new directions, and chooses the next action. A more capable large model writes code, runs tests, and submits results. By continuously recording feedback, the system can gradually form a recursive self-improvement mechanism, or RSI.
The key is not to let the model directly modify its own parameters. It is to let the system continuously update the basis for its decisions. After each experiment, the result enters a shared state and the system reassesses whether the current approach deserves further optimization, whether the algorithm path should change, which failures should not be repeated, and where the remaining budget should go. The agent then shifts from a one-shot code generator into a decision system that manages an experimental process.
1. Why large models fall into patching loops
When programming, large models tend to preserve the existing code structure. There are three main reasons.
First, local edits carry lower risk. The model can adjust the area around an error without reinterpreting the whole task. For syntax errors, type errors, and boundary-condition mistakes, this strategy can solve the problem quickly.
Second, an existing implementation creates path dependence. After several rounds of changes, the model may assume that the overall direction is correct and look only for local problems. Even when the original algorithm is unsuitable, it may continue adding patches around it.
Third, the model lacks stable experimental memory. If the system does not preserve each attempt’s code, test results, failure causes, and relationships among changes, later decisions depend only on the current context. The model may repeat methods that have already failed and cannot accurately compare the long-term value of different approaches.
An effective RSI system therefore cannot focus only on generating the next piece of code. It must also answer the higher-level question of what should be tried next.
2. A division of labor: small models plan, large models execute
In a collaborative system, roles can be divided between a strategy model and an execution model.
The strategy model does not take on the full coding task. It answers questions such as:
- Which historical version is most worth optimizing now;
- Whether the current problem should be repaired further or redesigned;
- Whether to prioritize a new algorithm, a data-processing method, or an engineering structure;
- Whether an experimental path is already showing diminishing returns;
- How the current experiment budget should be allocated.
The execution model turns that strategy into concrete action: reading existing code, changing the implementation, adding tests, running the program, analyzing logs, and submitting structured results.
This division keeps the strategy model from being fully constrained by current code details. Because it focuses on experiment trajectories and result distributions, it has a better chance of recognizing that the problem may lie in the method rather than the implementation. The execution model has stronger code understanding and generation ability and is better suited to the engineering work.
A small model is not inherently smarter, nor is it better than a large model on every task. Its value lies mainly in lower decision cost, faster response, and the ability to operate within a clearly defined strategy space. With a well-designed experiment state, it can make frequent directional choices while reserving more expensive large-model calls for work that actually requires code execution.
3. Shared search state: making every experiment traceable
The foundation of an RSI system is shared search state. It can be understood as a continuously growing experiment tree. Each node represents a runnable code version, and the links record evolution through modification, refactoring, or algorithm replacement.
A complete state should generally include:
Version information
Code snapshots, configuration files, dependency environments, and generation time, so experiments can be reproduced.Experiment results
Not only the final score, but also whether the run succeeded, elapsed time, resource consumption, test pass rate, and error type.Change description
The idea used in this round, the modules changed, and the problem the change was expected to solve.Parent-child relationships
The historical version from which the current version came, creating a clear search path.Unexplored directions
Algorithms, parameter ranges, data-processing methods, and architectural changes that have not yet been tried.Budget state
Remaining calls, runtime, compute resources, and the permitted number of experiment rounds.
With this information, the strategy model can choose the next action from evidence rather than from a natural-language description alone. Failed experiments should not simply be marked unusable. A better practice is to record the conditions of failure: a method may work on small data but time out under high concurrency, or an optimization may improve accuracy while consuming too much memory. Failure experience becomes reusable only when that context is preserved.
4. Balancing exploration and exploitation
If the system always chooses the currently best-performing approach, it overuses existing experience and may miss better paths. If every round tries an entirely new direction, it wastes experiment budget. Strategy selection therefore needs a balance between exploitation and exploration.
A common method is a decision mechanism based on an upper confidence bound. The system considers both a path’s historical return and its current uncertainty:
- Strong historical performance has high exploitation value;
- Paths tried only a few times lack evidence but have high exploration value;
- Paths that fail repeatedly for stable reasons should receive lower priority;
- Paths whose results vary widely across conditions need further checks of their applicable boundaries.
A simplified scoring idea is:
candidate score =estimated historical return+ uncertainty bonus- resource-consumption penalty- repeated-failure penalty
This is not a requirement that the model mechanically apply a fixed formula. It provides a stable framework for strategy decisions. A practical system can also adjust the weights by stage: raise the exploration share early to learn which directions are feasible, then exploit existing results more heavily later and concentrate on the most promising paths.
5. Strategy memory: reusable knowledge from results
Saving experiment logs is not enough. Logs answer what happened; strategy memory must answer what to do next time.
Strategy memory can include:
- Which algorithm structure suits a given class of task;
- Which approaches tend to fail at particular data scales;
- Which causes commonly produce a given class of error;
- Which changes improve a local metric but damage overall stability;
- Which preconditions an optimization requires;
- When local repair should give way to a broader redesign.
Memory should carry a scope and a confidence level. One accidental success should not become a general rule. Each item can be linked to its source experiments, validation count, and most recent update. New experiments that support a conclusion raise its confidence. Conflicting results add constraints or lower its priority. Experience that cannot be reproduced over time should be marked outdated.
This resembles an engineering team’s technical knowledge base, but it is not a static document. It is a dynamic strategy layer updated by ongoing experiments.
6. A research workflow from problem framing to validation
To avoid mechanical repair, the workflow can be split into proposer and executor stages.
1. Proposer stage
The proposer combines the task goal, existing code, historical results, and resource constraints to identify the main bottleneck. For example:
- Whether a low metric comes from an unsuitable model structure or from data preprocessing;
- Whether the performance bottleneck is algorithmic complexity or engineering efficiency;
- Whether the current approach is already near its ceiling;
- Whether a completely different idea is necessary.
The output should not be merely “change this line.” It should include the problem judgment, candidate approaches, expected gains, potential risks, and a validation method.
2. Executor stage
The executor turns a candidate into a runnable experiment. Its work includes:
- Reading the current version and relevant history;
- Changing the code according to the strategy;
- Adding necessary tests and monitoring;
- Running the experiment in an isolated environment;
- Collecting metrics, logs, and error information;
- Producing a structured experiment report.
The executor should not return only “the run succeeded” or “the run failed.” It should state what changed, under what conditions it ran, how the results changed, and why anomalies occurred. The next strategy round can then decide whether to continue optimizing or abandon the direction.
7. Workspace design that makes success reusable
The workspace is the layer connecting code, experience, and the experiment environment. A practical workspace needs at least four areas:
- Code area: current implementation and historical versions;
- Experiment area: run scripts, configuration, test results, and logs;
- Skill area: reusable operating procedures such as performance analysis, error localization, and test design;
- Memory area: reusable strategy experience and the conditions under which it applies.
The workspace should also provide isolation. Different experiments should use separate directories, separate configuration, and traceable dependency environments so one experiment does not contaminate another branch. High-risk operations should have permission limits and human confirmation, especially when they involve data deletion, calls to external systems, or large resource consumption.
8. Evaluation: judging whether the system is actually improving
A common mistake in RSI is treating more rounds of edits as self-improvement. Evaluation cannot look only at the final score; it must also examine the quality of the improvement process.
Useful dimensions include:
Whether task metrics improve
For example, accuracy, pass rate, response time, or resource usage.Whether experiment efficiency improves
Whether, under the same budget, the system finds high-quality approaches faster.Whether repeated failures decrease
Whether the system recognizes low-value paths that have already been tested.Whether strategy transfer improves
Whether historical experience helps similar tasks converge faster.Whether results are stable and reproducible
Whether an improvement appears only once or continues to hold under different conditions.Whether risk stays under control
Whether the system avoids breaking existing functionality and can roll back to a stable version when something goes wrong.
Optimizing a single metric can create false progress through higher resource use, reduced stability, or overfitting to test samples. Evaluation should therefore consider effectiveness, cost, robustness, and explainability together.
9. Practical engineering considerations
First, keep a rollback path. Automatically generated changes should be validated on an isolated branch and enter the stable version only after tests and quality gates pass.
Second, constrain the experiment space. The strategy model may propose new directions, but it should not generate candidates without limits. Allowed operations should be defined by task type to avoid useless search and uncontrolled resource use.
Third, observe the system well. Logs, runtime metrics, error categories, and version differences are the basis for later decisions. Without high-quality feedback, online learning degenerates into random trial and error.
Fourth, distinguish code errors from directional errors. Code errors can be sent to the execution model for rapid repair. Directional errors should trigger replanning and, when necessary, abandonment of the current branch.
Fifth, strategy memory must support correction. Incorrect experience that remains in place will keep misleading later decisions, so the system needs validation, decay, and retirement mechanisms.
Conclusion
The core of recursive self-improvement is not a large model repeatedly generating code. It is a closed loop that can observe, decide, execute, evaluate, and remember. A small model searches the experiment space for direction, a large model carries out complex implementation, the workspace preserves the process, and the evaluation mechanism determines whether improvement is real.
The value of this architecture is that it moves intelligent programming from answering a problem immediately to continuously managing the process of solving it. When a system can recognize the limits of local patching, actively try new algorithm paths, and turn both success and failure into reusable knowledge, it has a foundation for continued evolution on complex engineering tasks.
