Designing a Small-Model-Driven Framework for Recursive Self-Improvement

    This article explains how to design a recursive self-improvement (RSI) framework in which a small-parameter model proposes strategies and a large code model implements them. It covers the separation of strategy and implementation, shared search state, the online decision flow, strategy learning, evaluation methods, and engineering considerations.

    Recursive self-improvement (RSI) asks whether a system can use the results of its own execution to improve later decisions across a sequence of tasks. It is not limited to one code generation or one bug fix.

    A common misconception equates self-improvement with repeatedly fixing bugs. If the code fails, the system patches it. If the patch fails, it tries another patch. This can produce local gains, but it tends to lock the system into one way of thinking. The system rarely stops to check whether the original algorithm, level of abstraction, or technical route was sound.

    A more effective approach decouples strategy exploration from code implementation. A small-parameter model proposes high-level strategies, experiment directions, and decisions to abandon a path. A large-parameter code model handles the concrete implementation, debugging, and testing. A shared state and an evaluation loop feed the result of each round back to the strategy layer. This article covers the framework design, the online decision process, strategy learning mechanisms, evaluation methods, and key points for engineering deployment.

    1. Problem Background: Why Local Repair Struggles to Produce Sustained Improvement

    In code tasks, the typical failure mode of a model is not that it cannot write code. The problem is that it locks into an implementation path too early. When a test fails, the model tends to keep patching the current version. As the number of patches grows, sunk cost pushes it to keep spending budget in the same direction. The result is many experiment rounds, few useful explorations, and a high rate of repeated failures. For an RSI system, this is a decision quality problem as well as a generation quality problem. The system must decide when to improve the existing version, when to roll back, when to explore a new approach, and when to stop a direction.

    The first principle of the framework, therefore, is to keep comparable historical states. Each experiment round should record the baseline version, the candidate strategy, the implementation patch, the evaluation result, the failure cause, and the remaining budget. Only traceable states let the strategy layer learn which types of directions are worth trying. Without them, the system learns only from individual code snippets.

    2. Overall Architecture: Decoupling the Strategy, Implementation, and Evaluation Layers

    A practical RSI framework has three core parts.

    1. Core controller and online strategy learning. The controller maintains the shared search state. It selects the baseline version, decides between exploration and exploitation, generates action plans, schedules implementation and evaluation, and updates strategy preferences based on results. The controller does not write business code directly. It manages what to do next and why.

    2. Workspace and experience management. The workspace stores code versions, experiment records, skill entries, and experience summaries. A skill entry should be more than a natural language hint. It should include applicable conditions, a strategy description, implementation essentials, validation results, and the boundaries where it stops being valid. Experience management needs confidence scores, expiration mechanisms, and rollback capability, so that an accidental success does not become general experience.

    3. Independent evaluation environment. The evaluation environment runs candidate implementations, records metrics, isolates side effects, and keeps results reproducible. It looks at more than the final success rate. It also tracks learning curves, budget utilization, repeated failure rates, and cross-task transfer. The more independent the evaluation environment is, the less strategy learning gets misled by implementation details or evaluation noise.

    3. Shared Search State and the Online Decision Process

    The shared search state is a traceable snapshot of the experiment. At a minimum, it contains the historical code versions and how they relate to each other, the success or failure of each round, the cause of each failure, directions not yet explored, current strategy preferences, the remaining experiment budget, and safety constraints.

    Using this information, the core controller makes the following decisions in each round. It selects a historical version worth optimizing further. It decides whether to explore a new approach or improve an existing one. It chooses the candidate action with the highest combination of potential and feasibility. It calls the implementation layer to generate code, calls the evaluation layer to run the experiment, and records the results to update the strategies and experiences.

    The pseudocode below shows the flow:

    1. def run_rsi(budget, workspace, policy, proposer, coder, evaluator):
    2. state = workspace.load_state()
    3. for step in range(budget):
    4. base = select_base_version(state)
    5. mode = decide_mode(state, base) # explore or exploit
    6. strategy = proposer.propose(state, base, mode)
    7. patch = coder.implement(strategy)
    8. outcome = evaluator.run(patch)
    9. state = state.record(base, strategy, patch, outcome)
    10. policy.update(strategy, outcome, state)
    11. workspace.update_skills(outcome, state)
    12. return state

    The key point is the loop, not the function names. Strategy proposals must be structured. Implementation results must be evaluable. Evaluation results must be written back into the state and the policy. If any step is missing, the system degrades into one-off suggestions or blind trial and error.

    4. Two Complementary Strategy Learning Mechanisms

    Two complementary mechanisms make decisions more accurate over time.

    The first is result-driven strategy scoring. The system tracks the historical success rate, average cost, and failure distribution for action types such as exploring a new approach, improving an existing version, and rolling back to retry. A multi-armed bandit or heuristic scoring method estimates the value of each action type and allocates budget between exploration and exploitation.

    The second is failure-attribution-driven strategy correction. Failures are classified as implementation errors, strategy errors, evaluation noise, or resource shortages. Implementation errors go back to the code model. Strategy errors lower the priority of similar directions. Evaluation noise calls for repeated validation or a more isolated environment. Resource shortages trigger budget reallocation.

    Both mechanisms aim to teach the system which directions are worth continuing and which methods should be abandoned. Strategy learning does not need a stack of complex algorithms. It needs clean feedback signals, explainable attribution, and rollbacks that can actually be executed.

    5. Division of Labor Between Small and Large Models

    The strategy layer does not necessarily need the largest model. Within a constrained context, a small model is easier to constrain to structured strategy output, and it is less likely to be pulled into implementation details. A large code model is better suited to code generation, debugging, and writing tests.

    A sensible split is as follows. The small model handles algorithm selection, experiment design, stop decisions, and suggestions for failure attribution. The large model turns strategies into executable implementations and completes local debugging. A validator should sit between them. It checks that each strategy satisfies budget, safety, and testability constraints, which keeps strategy hallucinations from reaching the implementation layer.

    6. The Evaluation Loop: How to Tell Whether the System Is Actually Improving

    A single passing task does not show that an RSI system is improving. More meaningful metrics include the improvement rate per round, the share of useful exploration within budget, the repeated failure rate, the rollback success rate, cross-task transfer performance, and the explainability of strategies.

    The evaluation environment should isolate side effects, fix random seeds, keep complete logs, and rerun key results to confirm them. Only under independent evaluation can a gain in performance be credited to strategy learning rather than to evaluation leakage or random variation.

    7. Engineering Deployment and Risk Control

    In engineering, the first priorities are state storage, version rollback, experiment isolation, and log tracing. When running experiment environments in the cloud, Baidu AI Cloud’s general infrastructure, such as object storage, a container platform, log service, and monitoring and alerting, can store experiment artifacts, isolate runtime environments, track state changes, and detect anomalies. These are general infrastructure services. They do not change the core logic of the framework.

    Cost control also matters. Set a budget cap for each round, a retry limit for failures, and manual review checkpoints. Run high-risk code in a sandbox. Give the experience store confidence scores and expiration mechanisms so that incorrect experience does not become fixed.

    8. Conclusion

    The idea of a small model driving strategy exploration while a large model implements the code separates deciding what to do from getting it done. A shared state and an evaluation loop connect the two. The value of this design does not come from the size of any one model. It comes from giving the system traceable experiment memory, comparable strategy choices, and verifiable learning effects. For teams building code agents that improve over time, investing first in state management, failure attribution, and independent evaluation matters more than simply adding more generation rounds.