Counterintuitive: Small Models Driving the Continuous Evolution of Large Models

    This article explores a counterintuitive approach in code agent and automated R&D scenarios: using smaller models for strategic decision-making while leveraging large models for code implementation. By decoupling strategy formulation from code execution and maintaining a continuous learning loop, this architecture helps systems escape local optima caused by patch-fixing inertia. It details the system's layered architecture, online policy learning mechanisms, research workflow, and engineering best practices for building self-improving code agents.

    Counterintuitive: Small Models Driving the Continuous Evolution of Large Models

    In code agent and automated R&D scenarios, a common phenomenon occurs: after identifying a problem, the system continuously fixes bugs. If the fixes still do not meet the target, it switches to another approach for patch-style modifications. The model rarely pauses to ask: Was the chosen method wrong from the start? This “local patch-fixing inertia” keeps the search stuck in low-quality directions, consuming a large amount of the experiment budget while making structural breakthroughs difficult.

    A counterintuitive approach is to let a smaller parameter model take charge of “proposing strategies,” while a larger model with stronger coding capabilities is responsible for “implementing code.” The small model does not replace the large model in writing code; instead, it undertakes research decision-making, direction exploration, and experiment selection. The large model translates the strategy into an executable implementation. The two collaborate through shared experimental states and an online learning closed-loop, shifting the system from “continuously fixing bugs” to “continuously judging directions and self-improving.” This article breaks down this pattern from the perspectives of architecture, mechanism, pseudo-code, and engineering implementation.

    1. The Core Problem: Why Code Agents Fall into Local Patching

    The typical workflow of a code agent is “observe—modify—test—modify again.” When a test fails, the model tends to make minimal changes based on the error information. While this strategy is effective for simple defect fixes, in tasks such as algorithm design, performance optimization, and complex system refactoring, minimal changes may merely shift the error from one location to another.

    The root causes are primarily threefold:

    1. Premature convergence to existing implementations. Once a model selects a particular code version, subsequent reasoning is easily anchored by the current structure, making it difficult to propose completely different algorithms.
    2. Lack of cross-round experiment memory. Each round of modification focuses only on the current error, without systematically recording which directions failed, under what conditions they failed, and which directions have not yet been explored.
    3. Coupling of implementation and strategy capabilities. When the same large model has to think about directions and write code simultaneously, it tends to consume its reasoning budget on implementation details, reducing the diversity of strategy exploration.

    Therefore, what truly needs optimization is not just “code patch quality,” but “experiment selection strategy.” If the system can maintain a continuously updated experiment archive and adjust the decision between “exploring new ideas” and “improving old versions” based on results each round, it can break out of the local optimum.

    2. Core Idea: Decoupling Strategy Proposing and Code Implementation

    The key to this architecture is not that the small model’s capabilities comprehensively exceed those of the large model, but that the separation of responsibilities brings search diversity. The small parameter model is responsible for analyzing tasks, historical experiments, and current capability shortcomings, proposing new solutions. The large model is responsible for code implementation, debugging, and test validation. The small model continuously adjusts its decisions based on the results of each round, gradually learning which directions are worth trying and which methods should be abandoned.

    This division of labor brings three direct benefits:

    • Lower strategy exploration cost: The small model can sample different directions multiple times at a lower cost per experiment.
    • Reduced interference from implementation details on strategy: The strategy model does not have to get bogged down in specific syntax and interface details, focusing more on method-level choices.
    • Formation of a learnable closed-loop: The execution result of each round is fed back to the strategy layer, making “what direction to propose” itself an optimizable object.

    It should be emphasized that the small model does not simply give a one-time suggestion to the large model. It needs to maintain a shared search state, judge whether to explore new ideas or improve historical versions, and select the most potential and feasible solution from candidate actions.

    3. System Layering: Decision Core, Workspace, and Evaluation Arena

    The overall system can be abstracted into three core parts.

    1. Decision Core: Online Policy Learning

    The decision core maintains the shared search state and is responsible for selecting the next action. The shared search state can be understood as a continuously updated experiment archive, recording at least:

    • Code versions attempted and the evolutionary relationship between versions;
    • Success or failure results of each experiment;
    • Failure reasons and key log summaries;
    • Directions not yet explored;
    • Remaining experiment budget;
    • Confidence intervals and uncertainty estimates for each direction.

    Based on these records, the decision core selects a historical version worth continuing to optimize, decides whether to explore new ideas or improve existing methods, and then selects the most potential and feasible action plan.

    2. Workspace: Skill and Experience Management

    The workspace is responsible for saving reusable skills, experiment artifacts, and experience entries. Experience should not only record “whether a method succeeded,” but also save applicable conditions, failure boundaries, and specific guidance. For example, an optimization is only effective under a specific data scale; a refactoring introduces extra complexity but yields limited benefits; a certain type of error prompt often corresponds to structural defects rather than syntax issues.

    As new experiments are generated, experiences are reinforced, revised, or eliminated when no longer applicable. This prevents strategy memory from bloating into invalid logs.

    3. Evaluation Arena: Verifying Real Progress

    The evaluation arena is not simply running a test once, but evaluating whether the system can learn and improve from tasks. Four types of evaluations can be designed:

    • Repeated experiments on the same task family: Verify whether multi-round iterations provide stable improvements;
    • Held-out tasks: Verify whether the strategy is overfitting to historical experiments;
    • Transfer tasks: Verify whether experience can be transferred to similar problems;
    • Regression tasks: Verify whether the new strategy destroys existing capabilities.

    Only with a reliable evaluation closed-loop will “self-improvement” not degrade into “self-overfitting.”

    4. Online Policy Learning: Balancing Exploration and Exploitation

    Policy learning can adopt two complementary mechanisms.

    1. UCB-Based Strategy Selection

    Using methods like KL-divergence Upper Confidence Bound (UCB), it comprehensively balances past attempt effects with current uncertainty, seeking a balance between exploiting existing successful experiences and exploring unknown directions. Intuitively, if a direction has high historical returns but few attempts, it should be given exploration opportunities; if a direction has high returns and sufficient samples, it can be prioritized for exploitation; if a direction has failed multiple times and the confidence interval has converged, its priority should be lowered.

    This mechanism is suitable for scenarios with limited experiment budgets and many candidate directions. It does not require predicting the absolute optimum at once, but gradually shrinks uncertainty through round-by-round feedback.

    2. Memory-Based Policy Learning

    Policy memory records structured experiences of “method—condition—result—suggestion.” After new experiments are generated, memory updates are not simple additions, but involve reinforcement, revision, or elimination. For example:

    1. Experience entry example:
    2. Scenario: High-concurrency data aggregation task
    3. Method: Shard first, then merge, avoiding global sorting
    4. Applicable conditions: Data is shardable and merge operation satisfies associativity
    5. Historical result: In three experiments, latency was reduced twice, and failed once due to sharding overhead
    6. Suggestion: Evaluate sharding granularity and merge cost before deciding whether to adopt

    This memory allows the strategy layer to know not only “what succeeded,” but also “why it succeeded and when it is not applicable.”

    5. Research Workflow: The Proposer and Worker Closed-Loop

    To handle situations where existing methods have inherent limitations, the system can design a research workflow.

    • Proposer: Analyzes the current task, existing execution framework, and historical experiment results to identify system capability shortcomings and propose new solutions. It focuses on the method level: whether to change the algorithm, adjust data structures, refactor module boundaries, or alter experimental hypotheses.
    • Worker: Puts ideas into practice, implements, debugs, and tests to validate the effect, and feeds the execution results back to the strategy layer.

    The closed-loop can be abstracted as the following pseudo-code:

    1. state = SharedSearchState()
    2. memory = PolicyMemory()
    3. policy = OnlinePolicy()
    4. for step in range(experiment_budget):
    5. node = policy.select_node(state) # Select a historical version or a new direction
    6. action = policy.decide(node, memory) # Explore a new idea or improve an existing method
    7. if action.type == "explore":
    8. proposal = proposer.analyze(task, state, harness)
    9. else:
    10. proposal = proposer.improve(node, state)
    11. patch = worker.implement(proposal)
    12. result = evaluate(patch, regression_suite, task_suite)
    13. state.record(node, proposal, patch, result)
    14. memory.update(proposal, result)
    15. policy.update(result)

    The key to this process is connecting “strategy—implementation—evaluation—memory” into a closed-loop every round. The strategy layer adjusts subsequent decisions based on results, rather than letting the implementation layer repeatedly trial-and-error alone.

    6. Engineering Implementation Essentials

    1. Reproducible states: Record code snapshots, experiment configurations, random seeds, evaluation metrics, and failure logs to ensure any decision is traceable.
    2. Multi-objective reward design: Do not just look at whether tests pass; consider performance, complexity, maintainability, and experiment cost to prevent the strategy from introducing high-risk changes just to pass tests.
    3. Structured failure attribution: Categorize failures into syntax errors, interface mismatches, algorithmic assumption errors, performance shortfalls, etc., for use in policy memory.
    4. Evaluation leakage prevention: Held-out tasks and regression tasks must not enter policy memory to prevent the system from “memorizing answers” instead of learning methods.
    5. Security sandbox: Code execution, dependency installation, and test runs should be conducted in an isolated environment with restricted resources and network permissions.
    6. Observability: Record candidate directions, confidence intervals, memory hits, and budget consumption for each round to analyze whether the strategy is degrading.
    7. Memory eviction mechanism: Experience entries should have time limits and applicable conditions to prevent outdated experiences from misleading decisions long-term.

    On the deployment side, general container platforms, object storage, logging services, and monitoring alerts can be used to build the experiment closed-loop: container platforms isolate the runtime environment, object storage saves code snapshots and experiment artifacts, and logging and monitoring are used for failure attribution and budget observation. These general capabilities do not change the core architecture but can significantly improve experiment manageability.

    7. Conclusion

    The counterintuitive aspect of “small models driving the continuous evolution of large models” lies in the fact that the small model is not responsible for writing better code, but for proposing directions, selecting experiments, and accumulating experience at a higher frequency. The large model is responsible for turning these directions into executable implementations. Through shared search states, UCB-based exploration, policy memory, and evaluation closed-loops, the system can upgrade the local patch-fixing of “repeatedly fixing bugs” into a recursive self-improvement process of “first judging whether the method is wrong, then deciding to explore or improve.”

    For developers, what is truly worth reusing is not a specific implementation, but this layered philosophy: decouple policy learning from code implementation, make experiment archives first-class citizens, and expand evaluation from a single benchmark run to learning capability verification. Only in this way can code agents continuously evolve within a limited budget, rather than spinning their wheels in local optima.