Agent Self-Evolution Framework Explained: Continuous Learning Driven by Small Models

    This article breaks down how a self-evolving AI agent framework enables continuous learning, moving beyond local bug fixing toward genuine progress. It explains the three core components—an online policy scheduler, a workspace for reusable skills and memory, and a competitive evaluation environment—and details uncertainty-based exploration with KL-UCB, structured policy memory that can be revised and retired, and a research-style workflow. It also covers workspace organization, evaluation design for proving real improvement, and practical deployment tips and common pitfalls. Readers will learn how pairing a small model as proposer with a large model as implementer creates a sustainable diverge-then-converge improvement loop.

    1. The Starting Problem: Why “Fixing Bugs” Is Not the Same as “Making Progress”

    In practice, when agents take part in algorithm and code optimization, the most common failure mode is not a lack of capability. It is a way of thinking that gets locked in by local feedback: when a run throws an error, add a guard clause; when a test fails, swap in another patch; when a metric dips slightly, tweak a parameter. Every round looks diligent, but the whole search stays inside the same family of methods, with no meta-level judgment about whether the current paradigm itself is wrong.

    The root cause is degraded search strategy: the agent treats “it runs” as “it is correct,” and treats “short-term feedback improved” as “the long-term direction is right.” To escape this trap, the system needs three capabilities. First, it must look back at history and identify bottlenecks at the level of whole method families. Second, it must make a controlled trade-off between exploiting proven successes and exploring entirely new directions. Third, it must distill effective experience into knowledge that is reusable, revisable, and retireable, rather than a one-off prompt.

    A counterintuitive but sound engineering choice is to let a smaller, lower-inference-cost model act as the “strategy proposer,” while a stronger model with better coding ability acts as the “implementer.” The small model is cheaper in token budget and sampling, which suits high-frequency trial and error and divergent thinking. It is also less easily pulled by the local goal of “just fix the current code,” so it is more likely to propose a change-of-track solution. The large model, meanwhile, focuses on turning ideas into runnable, testable implementations. Together they form a diverge-then-converge division of labor, iterating into a closed loop of sustainable self-improvement.

    2. Overall Architecture: Three Core Components Working Together

    A mature self-evolution framework can be split into three parts: a core scheduler responsible for online policy learning, a workspace responsible for managing skills and experience, and a competitive evaluation environment responsible for assessing “whether real progress is being made.”

    • Core scheduler: maintains the shared search state and decides “what to try next.”
    • Workspace: manages code versions, skill snippets, experience entries, and the runtime environment, ensuring reproducibility and rollback.
    • Competitive evaluation environment: uses a unified benchmark and a fixed budget to test whether the system can learn and transfer across tasks, rather than overfitting to a single task.

    The relationship among the three can be likened to this: the scheduler is the brain, the workspace is the memory and the hands and feet, and the competitive environment is the medical checkup and the exam.

    3. Online Policy Learning: Making Decisions More Accurate Over Time

    3.1 Shared Search State: A Continuously Updated Experiment Log

    The scheduler needs a structured record that contains at least: historical code versions and their lineage (which version was derived from which), the result and failure reason of each experiment, directions not yet explored, and the remaining experiment budget. With it, decisions shift from “going by feel” to “based on evidence.”

    Illustrative data structure (pseudocode):

    1. SearchState = {
    2. "budget": 120,
    3. "nodes": {
    4. "v1": {"parent": None, "score": 0.41, "visits": 3, "tags": ["baseline"]},
    5. "v2": {"parent": "v1", "score": 0.47, "visits": 1, "tags": ["cache"]},
    6. },
    7. "frontier": ["v2", "v5"], # directions not yet fully explored
    8. "policy_memory": [] # reusable policy experience
    9. }

    3.2 Uncertainty-Based Exploration: The Intuition Behind KL-UCB

    The scheduler weighs “keep drilling into the best historical version” against “try a low-visit direction.” A common industry approach is upper-confidence-bound methods: score = average reward + exploration bonus, where fewer visits mean a higher bonus. What makes KL-UCB special is that it uses KL divergence to build a confidence interval that better fits bounded rewards (such as success rate or normalized metrics), which is usually more robust than a simple mean plus variance.

    Illustration:

    1. def kl_ucb(score, visits, total, c=0.2):
    2. # Fewer visits mean a larger exploration bonus; c controls exploration strength
    3. return score + math.sqrt(c * math.log(total + 1) / (visits + 1))

    In engineering, it is advisable to make exploration strength an annealable parameter: encourage divergence early, then converge to high-value directions later.

    3.3 Memory-Based Policy Learning: Experience Must Be Revisable and Retireable

    Recording only “success/failure” carries too little information. A more effective approach is to write experience as structured policy entries: applicable condition, action suggestion, expected benefit, evidence source, and confidence. New experiments reinforce, revise, or retire old entries, preventing memory from becoming a noise dump.

    1. {
    2. "condition": "The task bottleneck is data coverage rather than model capacity",
    3. "action": "Prioritize expanding evaluation samples and edge cases before considering a different algorithm",
    4. "evidence": ["exp_17", "exp_23"],
    5. "confidence": 0.72
    6. }

    3.4 Research-Style Workflow: Breaking Out of the Patching Habit

    When historical data shows “diminishing returns from patches in the same family,” the scheduler should trigger research mode: the proposer analyzes the task, the existing execution framework, and historical results, pinpoints capability gaps, and offers new ideas; the implementer handles coding, debugging, testing, and reporting results back. Only then does the system have a chance to leap from “fixing code” to “changing methods.”

    4. Workspace: Turning Successful Experience into Reusable Assets

    The core of the workspace is not storing code, but storing “reproducible context”: version lineage, runtime environment dependencies, test commands, logs and metrics, and a minimal reproduction of failures. A directory-based organization is recommended:

    1. /workspace
    2. /versions/v3/...
    3. /skills/parse_table.py
    4. /memory/policy.jsonl
    5. /runs/exp_23/{logs,metrics.json}

    The skill library should support retrieval and composition, and the experience library should support conflict detection (contradictory entries under the same condition need arbitration). All experiments should be bound to a fixed random seed and resource limits to ensure comparability and cost control.

    5. Evaluation: How to Prove “Real Progress”

    The evaluation environment must answer one question: can the system learn from tasks and transfer that learning? Design points include a unified benchmark with hidden tests, a fixed experiment budget, a cross-task holdout set, and a “history dependency” check (whether a later round actually used experience from an earlier round). On metrics, look simultaneously at final performance, the budget required to reach the same performance, and the degree to which the diversity of failure modes decreases.

    6. Deployment Advice and Common Pitfalls

    • Keep role division clear: the small model diverges, the large model converges, avoiding cross-contamination of context.
    • Budget and annealing: more exploration is not always better; convergence should tighten as the budget is consumed.
    • Memory governance: periodically merge entries, arbitrate conflicts, and retire outdated ones.
    • Reproducibility first: the trio of environment, seed, and command is all indispensable.
    • Safety boundaries: run code execution in an isolated sandbox, and restrict network and file permissions.

    Overall, the key to continuous self-evolution is not “being better at writing code,” but “being better at deciding what to write next.” When policy learning, experience memory, and rigorous evaluation form a closed loop, an agent can move from local patching toward genuine continuous progress.