Small-Model-Driven Recursive Self-Improvement Framework for Large Code Models

    This article examines a recursive self-improvement (RSI) framework that separates strategy proposal from code implementation. A small model of roughly 9B parameters acts as the policy proposer, while a larger code-generation model implements, debugs, and tests candidate solutions. The article explains why continuous bug fixing tends to fall into local repair loops, then describes the architecture: a policy core with shared search state and online decision-making, UCB-style and memory-based policy learning, a Proposer–Worker research workflow, a workspace for reusable skills and experience, and an RSI evaluation arena for measuring real progress. It also covers engineering considerations and risk boundaries such as reward hacking, memory contamination, evaluation leakage, budget control, sandboxing, and human spot checks.

    Small-Model-Driven Recursive Self-Improvement Framework for Large Code Models

    In recursive self-improvement (RSI), a common misconception is that a large model will naturally become stronger if it keeps fixing bugs and retrying. In real engineering practice, code-generation models can easily fall into a local-repair mindset: after the current implementation fails, they continue adjusting parameters, adding boundary conditions, or trying another variation under the same line of thinking, but rarely stop to judge whether the original algorithm or architecture is already wrong. When the method itself has structural flaws, continuing to patch the code often yields only limited gains.

    One design worth attention is to separate “proposing strategy” from “implementing code.” A small model with about 9B parameters handles strategy exploration and decision-making, while a larger code-generation model handles concrete implementation, debugging, and testing. The small model does not need to write high-quality code directly. Instead, based on each round of experimental results, it judges which directions are worth continuing and which methods should be abandoned, and chooses whether to explore a new idea or improve an existing version. This division of labor may seem counterintuitive, but it can reduce the cost of strategy exploration and give the system a chance to escape local repair loops.

    1. Core Problem: Why Continuous Bug Fixing Is Not Enough

    Large models usually have strong code completion and error-fixing capabilities in programming tasks, but recursive self-improvement requires the system not only to fix code, but also to “choose directions.” If every failed sample is handed directly back to the same model for further fixing, the system is prone to three problems.

    First, the search space becomes localized. The model tends to make small modifications near existing code, making it difficult for new algorithms, data structures, or workflows to be proposed. Second, the experimental budget is consumed inefficiently. A large number of retries concentrate on low-potential branches, while directions truly worth exploring do not receive enough budget. Third, experience cannot accumulate. If a success or failure is not recorded in a structured way, the next round may repeat the same mistake.

    Therefore, the key to an RSI framework is not only “generating code,” but maintaining a search process that is traceable, evaluable, and updatable. The system needs to know what has been tried, how versions evolved, which directions remain unexplored, how much budget is left, and why each experiment succeeded or failed.

    2. Dual-Model Division of Labor: Decoupling Strategy Proposal and Code Implementation

    The framework divides roles into two categories. The small model acts as the strategy proposer. It analyzes the current task, existing implementations, and historical experimental results, identifies capability gaps, and proposes new solution ideas. The large model acts as the implementer. It turns strategies into code and completes debugging, testing, and result feedback. The small model does not directly pursue code-level optimality; it pursues the rationality of the “next action.”

    This decoupling has three direct benefits. First, exploration costs are lower. The strategy layer can use a smaller model to make multiple direction judgments without invoking the high-cost code model every time. Second, the perspective is more independent. The strategy model is not deeply tied to a specific piece of code, making it easier to propose different algorithms based on task goals and failure modes. Third, the feedback loop is clearer. Strategy decisions, code implementations, and experimental results are recorded separately, making it easier to analyze later whether a failure came from a “wrong strategy” or a “wrong implementation.”

    It is important to emphasize that the small model does not give the large model one-time advice. It continuously adjusts decisions based on each round of execution results and gradually learns which directions are worth trying and which methods should be abandoned. In other words, the strategy layer itself also learns online rather than relying on static rules.

    3. Overall Architecture: Policy Core, Workspace, and Evaluation Arena

    The framework can be abstracted into three core parts: a policy core module, a workspace, and an RSI evaluation arena.

    The policy core module is responsible for online policy learning and action selection. It maintains shared search state and decides what to do in the next round based on historical results. The workspace is responsible for skill and experience management, distilling effective practices from experiments into reusable knowledge. The RSI evaluation arena is responsible for evaluating whether the system can actually learn and improve from tasks, avoiding reliance only on single-task success rates.

    The three form a closed loop: the policy core proposes actions, the workspace provides historical skills and experience, and the evaluation arena provides results and diagnostics, which then flow back to the policy core and workspace. Without the evaluation arena, the system can easily become overconfident; without the workspace, experience cannot accumulate; without the policy core, the system degenerates into random retries.

    4. Policy Core: Shared Search State and Online Decision-Making

    The policy core maintains a shared search state, which can be understood as a continuously updated experiment archive. The archive should contain at least the following: previously tried code versions, the evolutionary relationships among versions, the success or failure result of each experiment, unexplored directions, and the remaining experimental budget. Version relationships are suitable for representation as a directed acyclic graph, where nodes are code versions or strategy versions, and edges indicate “evolved from a certain version.”

    Based on these records, the policy core makes three judgments in each round: select a historical version worth continuing to optimize; decide whether to explore a new idea or improve an existing method; and choose the most promising and feasible option from candidate actions. Here, “feasible” depends not only on expected benefit, but also on implementation cost, testing difficulty, and budget constraints.

    To make decisions increasingly accurate, the system can use two complementary policy-learning mechanisms.

    First, UCB-based policy learning, such as KL-UCB-style methods. It considers both the effects of past attempts and current uncertainty, seeking a balance between exploiting existing successful experience and exploring unknown directions. If a direction has good historical performance but few attempts, it should still retain exploration value; if a direction has failed many times and its confidence interval narrows, its priority should be reduced. In engineering practice, there is no need to rely blindly on a single formula. The key is to incorporate benefit estimates, uncertainty, budget constraints, and failure penalties into a unified score.

    Second, memory-based policy learning. The system distills effective experience from past experiments into policy memory. It records not only whether a method succeeded, but also the conditions under which it applies, failure modes, and specific guidance. As new experiments are generated, this experience is reinforced, revised, or eliminated when no longer applicable. For example, “prefer divide-and-conquer for a certain type of task” is an experience, but it must come with applicable conditions; when task scale, dependency relationships, or testing constraints change, that experience should be downweighted.

    5. Research Workflow: From Discovering Problems to Validating Ideas

    If the existing method itself has limitations, patching code alone is unlikely to bring true breakthroughs. Therefore, the policy core also needs a research workflow.

    The Proposer analyzes the current task, existing implementation framework, and historical experimental results, identifies capability gaps in the current system, and proposes new solution ideas. The question it focuses on is not “where is this line of code wrong,” but “why does the current solution fail to meet the goal,” “is an intermediate representation missing,” and “does the search strategy or decomposition method need to be changed.”

    The Worker puts ideas into practice through code implementation, debugging, and testing, then feeds execution results back. The Worker’s output should include not only pass or fail, but also failure type, log summary, performance changes, and reproducible experimental conditions. In this way, the Proposer can determine whether a failure comes from an invalid strategy, a flawed implementation, or an unstable evaluation environment.

    A simplified loop can be represented as:

    1. state = load_search_state()
    2. for step in range(budget):
    3. candidates = propose_actions(state)
    4. action = select_by_policy(candidates, state)
    5. result = execute_in_sandbox(action)
    6. state = update_state(state, action, result)
    7. memory = update_policy_memory(memory, action, result)
    8. if result.success and result.improvement > threshold:
    9. promote_candidate(action)

    6. Workspace: Helping the System Remember Successful Experience

    The workspace is responsible for skill and experience management, addressing the question: “If it worked this time, can it be used again next time?” It should contain at least a skill library, an experience library, and versioned records. The skill library stores reusable implementation patterns, test templates, and debugging strategies; the experience library stores policy memory and its applicable conditions; versioned records ensure that every experiment is traceable.

    The key to the workspace is not simply storing logs, but making them searchable, updatable, and invalidatable. If a skill is effective only on a specific task, it cannot be recommended unconditionally; if an experience repeatedly fails in new experiments, it should be revised or eliminated. In engineering practice, each experience can maintain a confidence score, applicable conditions, last verification time, and failure count to avoid memory contamination.

    7. RSI Evaluation Arena: Verifying Whether the System Is Really Improving

    The RSI evaluation arena is responsible for evaluating whether AI can actually learn and improve from tasks. Evaluation should not rely only on single-run pass rates, but should also examine improvement magnitude after multiple iterations, stability, cost efficiency, and exploration diversity. It is advisable to track at least task success rate, improvement relative to the initial version, variance across repeated experiments, budget required per unit of improvement, proportion of ineffective retries, and whether evaluation leakage or reward hacking occurs.

    The evaluation arena should use independent task sets and isolated environments to prevent the system from overfitting to fixed tests. For high-risk code, execution should also take place in a sandbox, with network and file permissions restricted, and complete audit logs recorded.

    8. Engineering Implementation Points and Risk Boundaries

    During implementation, general-purpose cloud services can be used to host experiments: container platforms to isolate execution environments, object storage to save versions and logs, and logging services and monitoring alerts to track experiment status. When deploying on general-purpose cloud platforms, teams should also use combinations of general capabilities and avoid binding the framework to a specific interface.

    Main risks include reward hacking that inflates metrics, memory contamination that spreads incorrect experience, evaluation leakage that creates false progress, uncontrolled budgets that increase costs, and security risks introduced by automatically generated code. Corresponding measures include independent evaluation, experience invalidation mechanisms, sandboxed execution, hard budget limits, and human spot checks.

    Overall, the core value of small-model-driven recursive self-improvement for large models is not to replace large models in writing code with smaller models, but to decouple “direction selection” from “code implementation,” enabling the system to explore, remember, and validate more effectively under a limited budget. For programming-oriented agents that require continuous iteration, this architecture offers a path worth engineering validation.