Small Model-Led Strategy: Inside a Recursive Self-Improvement Agent Framework
This article breaks down a recursive self-improvement (RSI) agent framework in which small models handle high-frequency strategy decisions while large models handle high-quality code implementation. It explains the shared search state, dual-path strategy learning based on upper confidence bounds and memory, the layered research workflow that moves agents beyond local bug fixing, and the evaluation system needed to separate real progress from wasted activity. Readers will also find practical engineering notes on state persistence, concurrency, cost control, reproducibility, and safety boundaries.
1. The Starting Problem: Why Fixing Bugs Is Not the Same as Doing Research
In automated development workflows, the most common agent behavior pattern is local patching: run the tests, see a failure, change a few lines of code, and run again. If it still fails, the agent keeps making incremental adjustments along the same line of thinking. This behavior is stable from an engineering standpoint, but it has a structural flaw: it assumes the current approach itself is correct and only looks for deviations at the implementation level.
Real research tasks are often not implementation errors but wrong approach choices. In that case, no amount of patching will converge, because the search space is confined to a single wrong path. To break out of this, an agent needs two capabilities: judging whether the current method is worth continuing, and proposing new solutions at a different level from the current one.
A counterintuitive but sound engineering conclusion follows: strategy decisions and code implementation should be handled by models of different sizes. Small-parameter models have low inference cost and fast iteration, making them suitable for high-frequency decisions across many candidate directions; large-parameter models have strong coding ability, making them suitable for turning a selected approach into high-quality implementation. This yields a recursive self-improvement (RSI) framework: the small model produces strategy, the large model writes code, and execution results flow back as the basis for strategy.
2. Overall Architecture: Three Separable Core Components
Splitting the system into three layers with clear responsibilities is the prerequisite for maintainability in this kind of framework.
- Policy kernel: responsible for online decision-making and policy learning. Its input is the historical experiment archive, and its output is “what to do next.”
- Workspace: responsible for skill accumulation and experience management, turning one-off attempts into reusable assets.
- Evaluation arena: responsible for measuring whether the system is actually getting stronger, rather than merely getting busier.
The three are decoupled through a unified state object, and any layer can be replaced independently or scaled horizontally.
Execution results (metrics/logs/failure reasons)│ flow back▼┌─────────────────┐ decision directives ┌──────────────────┐│ Policy kernel │ ─────────────────────▶ │ Workspace(skills)││ shared search │ ◀───────────────────── │ code/patches/tests││ state + learning│ feedback signals └──────────────────┘└─────────────────┘▲ ││ evaluation metrics and ▼│ regression results Evaluation arena└────────────────────────────
3. Shared Search State: Making Decisions Evidence-Based
The core data structure of the framework is a continuously updated experiment archive. It contains at least five kinds of information: the code versions already tried and their snapshots, the parent-child evolution relationships between versions, the quantitative results and failure reasons of each experiment, directions not yet explored, and the remaining experiment budget.
Formally, it can be approximated as a scored search tree:
class SearchState:def __init__(self, budget: int):self.nodes = {} # node_id -> {code, parent, score, meta}self.frontier = set() # directions to exploreself.budget = budget # remaining experimentsdef record(self, node_id, code, parent, score, meta):self.nodes[node_id] = {"code": code, "parent": parent,"score": score, "meta": meta}self.budget -= 1def best-so-far(self):return max(self.nodes.items(), key=lambda kv: kv[1]["score"])
With parent-child relationships, the system can distinguish “this whole route does not work” from “a particular implementation on this route does not work.” With a budget constraint, the policy layer is forced to make trade-offs instead of enumerating endlessly.
4. Dual-Path Policy Learning: Balancing Exploitation and Exploration
Relying on heuristic rules alone makes decision quality fluctuate sharply across tasks, so an explicit learning mechanism is needed.
The first path is upper-confidence-bound-based policy learning. For each candidate direction, it maintains the number of attempts and the average payoff, uses an exploration bonus to compensate for uncertainty caused by insufficient samples, and selects the one with the highest upper bound. A common implementation is a KL-UCB style method, whose payoff estimation makes looser assumptions about the reward distribution and is therefore suited to experiments with high result variance and low success rates.
import mathdef kl_ucb_pick(stats, t, c=1.0):# stats: {action: [n, mean_reward]}best, best_i = None, -1.0for a, (n, mean) in stats.items():if n == 0:return abonus = math.sqrt(c * math.log(t) / n)idx = mean + bonusif idx > best_i:best, best_i = a, idxreturn best
The second path is memory-based policy learning. It distills successful experience into policy memory entries that record not only “success/failure” but also applicable conditions and concrete guidance, such as the applicable task type, data scale range, and whether prerequisites are met. When a new experiment arrives, entries whose conditions match are reinforced, entries whose conditions have drifted are revised, and entries that are ineffective over the long term are discarded. This is effectively a self-updating experience handbook for the agent.
The two paths complement each other: the confidence bound addresses “what if we have not seen it,” while the memory mechanism addresses “if we have seen it, we should remember it.”
5. Breaking the Patching Habit: A Layered Research Workflow
When the capability gap comes from the approach itself, a higher-level generation step must be introduced. A two-role collaboration can be used:
- Proposer: analyzes the task definition, the existing execution scaffolding, and historical experiment results, locates the capability gap, and produces several new ideas at a different level from the current route.
- Implementer: turns the ideas into code, completes debugging and testing, and returns structured results (metrics, failure stack traces, elapsed time).
The key design is to constrain the proposer’s output format so that it can be automatically parsed and validated:
{"hypothesis": "The current approach is limited to single-round retrieval; switch to multi-round iterative retrieval","expected_gain": "Higher recall","risk": "Increased latency","changed_modules": ["retrieval", "prompt"],"rollback_plan": "Keep a snapshot of the previous version"}
Guardrails are also mandatory: new approaches run in a sandbox with limited resources and time limits; any regression triggers an immediate rollback; and all changes are logged to ensure auditability.
6. Evaluation System: Distinguishing Real Evolution from Fake Busyness
The biggest risk of a self-improvement framework is self-deception: a metric improves by chance on a small sample and is mistaken for a capability gain. The evaluation layer should include at least three kinds of benchmarks: a training task set for generating experience, a held-out task set for testing generalization, and a cross-stage regression set for confirming that old capabilities have not degraded.
What should be recorded is not only the final score but also the number of experiments required to reach the same score. If the score stays flat while consumption drops significantly, that also counts as evolution; if the score rises but variance widens and failure modes become more concentrated, overfitting to the evaluation set should be suspected.
7. Engineering Implementation Notes
- State persistence: persist the search state and skill library to disk to support resuming after interruption; object storage can hold version snapshots, while logging services and monitoring alerts track long-running tasks.
- Concurrency and isolation: run experiments in parallel on a container platform to avoid cross-contamination.
- Cost control: the small model handles high-frequency decisions and the large model is called only after an approach is settled, significantly reducing overall inference overhead.
- Reproducibility: fix random seeds and record dependency versions and data snapshot identifiers.
- Safety boundaries: restrict external network access and file system permissions to prevent side effects from automatically generated code.
8. Conclusion
The value of this kind of framework lies not in having a stronger model, but in engineering the “decide-implement-evaluate-remember” loop: the small model handles high-frequency strategy selection, the large model handles high-quality implementation, the shared search state and policy memory keep experience from being lost, and layered evaluation makes progress verifiable. For teams that want to build automated development capabilities, prioritizing state management, evaluation benchmarks, and rollback mechanisms usually delivers more stable returns than rushing to swap in a stronger model.
