Recursive Self-Improvement for AI Agents: A Practical Guide to Cross-Model Experience Transfer

    This article breaks down how recursive self-improvement (RSI) enables experience to carry across different models. It covers the three core layers—structured execution trace collection, distilling traces into transferable experience entries, and injecting that experience through in-context prompts, fine-tuning, or an external controller—along with the closed-loop execute/evaluate/distill/transfer flywheel, stability controls such as confidence decay and evaluation gates, infrastructure requirements, and a step-by-step path for teams to get started.

    1. The Starting Problem: Why Agent Optimization Results Don’t Carry Over

    Over the past two years, engineering work on AI agent frameworks has repeatedly run into a structural problem: prompt structures, tool-calling strategies, and planning/reflection workflows tuned for one large model tend to be tightly coupled to that model’s behavioral traits. A framework configuration that a team iterates on against one model loses almost all of its accumulated value the moment it is switched to another model, forcing the team to invest substantial manual effort in re-adaptation.

    The root cause is that experience is implicitly encoded at two levels. The first is the prompt text itself, which depends heavily on a specific model’s instruction-following style. The second is capability inside the weights, which cannot be migrated through a configuration file. As a result, “agent experience” is effectively a private asset that cannot be exported or reused.

    Recursive Self-Improvement (RSI) research aims to solve exactly this: making the experience produced by agent A during optimization directly inheritable and reusable by agent B, so that improvement stays continuous even when models are heterogeneous or versions keep changing.

    2. Core Mechanism Breakdown: How Experience Is Inherited Across Models

    2.1 Layer One: Structured Collection of Execution Traces

    Every form of experience inheritance starts with recording an agent’s full execution process on a task. This typically includes:

    1. # Illustration: trace structure of a single task execution
    2. trace = {
    3. "task_input": task.description,
    4. "thought_steps": [
    5. {"step": 1, "reasoning": "...", "action": "...", "observation": "..."},
    6. {"step": 2, "reasoning": "...", "action": "...", "observation": "..."},
    7. # ...
    8. ],
    9. "final_output": result,
    10. "evaluation": {"score": 0.87, "pass": True},
    11. "model_meta": {"version": "v-X", "config_hash": "a3f9..."}
    12. }

    The key design principle is that traces must be decoupled from a specific model’s version and parameters. The collection layer records only three kinds of information—what was done, why it was done, and how the result turned out—and nothing tied to a particular model architecture’s internal state.

    2.2 Layer Two: Abstracting and Distilling Traces into Experience

    Raw trace data is large and noisy, and cannot be used directly as experience. It has to go through a distillation process that abstracts concrete execution details into transferable, strategic knowledge:

    1. Denoising and clustering: semantically cluster the execution steps across many traces to identify “effective action patterns” and “ineffective/redundant steps”;
    2. Attribution analysis: attribute each task outcome—was the planning strategy effective, was the tool selection appropriate, or was the problem simply easy;
    3. Experience abstraction: compress the attribution conclusions into structured experience entries, for example:
    1. # Example experience entry
    2. experience_id: exp_00217
    3. applicable_scenario: "Tasks requiring multi-step reasoning and external data lookup"
    4. effective_patterns:
    5. - pattern: "Break down subgoals first, then call tools item by item"
    6. confidence: 0.92
    7. - pattern: "Prioritize verification queries for subtasks with high uncertainty"
    8. confidence: 0.85
    9. negative_patterns:
    10. - pattern: "Call all tools in parallel at once, then aggregate results"
    11. confidence_failure: 0.78

    This layer is the key hub of RSI: the more expressive and abstract an experience entry is, the higher the success rate of transferring it across models.

    2.3 Layer Three: Experience Injection—Making Another Model “Inherit Memory”

    Once experience is structured, a new model needs to internalize it in some way. Three paths are commonly explored in the industry today:

    Path A: In-Context Injection
    Inject experience entries into the new model’s system prompt as natural language or structured text. This is the simplest and most direct approach, with the advantages of zero training cost and immediate effect; the limitation is the context window, and how closely the model follows the experience depends on its instruction-following ability.

    1. # Illustration: injecting experience into the system prompt
    2. system_prompt = f"""
    3. You are a task-execution agent. The following historical experience is provided for your reference during planning:
    4. [Effective strategies]
    5. - {exp['effective_patterns'][0]['pattern']}
    6. - {exp['effective_patterns'][1]['pattern']}
    7. [Practices to avoid]
    8. - {exp['negative_patterns'][0]['pattern']}
    9. """

    Path B: Parameter-Level Fine-Tuning
    Convert experience entries into training data (such as preference pairs or instruction samples) and lightly fine-tune the new model. This internalizes experience into the weights, making the transfer more durable, but it requires training resources and time, and updates carry a lag.

    Path C: Outer Controller Memory
    Store experience in the agent framework’s outer control logic (for example, a standalone policy library module), with the controller retrieving it at runtime and applying it to the new model. The model itself stays completely unchanged, and experience is carried entirely by the framework layer—this is also the most engineering-friendly implementation of “framework-level experience inheritance.”

    1. # Illustration: outer controller retrieving experience
    2. class ExperienceController:
    3. def __init__(self):
    4. self.exp_store = load_experience_base()
    5. def retrieve(self, task_context):
    6. # Match relevant experience based on task semantics
    7. return self.exp_store.search(task_context.embedding)
    8. def apply(self, plan_step, experiences):
    9. # Inject experience as constraints into the plan
    10. for exp in experiences:
    11. plan_step.add_constraint(exp.pattern)
    12. return plan_step

    The three paths are not mutually exclusive; real systems usually combine them: the outer controller handles experience storage, retrieval, and matching, in-context injection provides immediate guidance, and fine-tuning handles long-term internalization.

    3. Closed-Loop Control: The RSI Self-Evolution Flywheel

    Experience inheritance is only a single transfer. The essence of RSI is turning it into a closed loop. A complete loop has four stages:

    1. Execute: the current agent performs the task and produces traces;
    2. Evaluate: assess the quality of the execution result and determine the direction of improvement;
    3. Distill: distill traces into experience entries and update the experience base;
    4. Transfer: inject the updated experience base into the agent for the next iteration (which can be the next version of the same model, or a heterogeneous model).

    Once this flywheel is spinning, the system gains the property of “getting stronger with use”: the output of each iteration becomes the input of the next, and improvement no longer depends on a single major version upgrade.

    The key engineering challenge is keeping the flywheel stable:

    • Experience degradation: wrong experience gets reinforced continuously (runaway positive feedback), which requires a confidence decay mechanism and a human review gate;
    • Evaluation bias: the evaluator’s own capability ceiling limits the improvement ceiling, so evaluation criteria need periodic recalibration;
    • Context pollution: injecting too many experience entries bloats the prompt, so a Top-K cutoff for experience retrieval is needed.

    4. Practical Recommendations: How to Land This in Your Own System

    For teams that want to build RSI capability, the recommended order is:

    Step one, complete trace collection. Without high-quality execution traces, none of the downstream work is possible. The collection layer is the infrastructure investment with the highest return.

    Step two, establish an experience format specification. Experience entries need a unified schema (such as the YAML format above) and must be sufficiently abstract—the more abstract, the more transferable; the more concrete, the more likely to overfit to a specific model’s behavior.

    Step three, start with in-context injection. First use the lightest path, Path A, to validate that the loop works and confirm that experience brings measurable improvement, then gradually introduce fine-tuning and the controller module.

    Step four, set up evaluation gates. Add automated evaluation and threshold control into the loop to prevent wrong experience from being amplified:

    1. # Illustration: quality gate before an experience entry is accepted
    2. def accept_experience(new_exp, exp_db):
    3. if new_exp.confidence < MIN_CONFIDENCE:
    4. return False
    5. # Conflict detection against existing experience
    6. conflicts = exp_db.find_conflicts(new_exp)
    7. if len(conflicts) > MAX_CONFLICTS:
    8. return requires_human_review(new_exp)
    9. return exp_db.add(new_exp)

    5. Working With Infrastructure

    RSI systems place several clear demands on infrastructure:

    • Storage layer: the experience base and trace base need persistent storage and efficient semantic retrieval (usually via vector search, which can be provided by a general retrieval service in the cloud or a self-hosted vector database);
    • Compute layer: the evaluation and distillation stages need batch compute resources, which can be scheduled elastically on a general container platform;
    • Observability: every flywheel iteration needs complete logging and metrics so that experience degradation or evaluation bias can be traced.

    In related technical practice at Baidu AI Cloud, such needs are typically met by combining object storage (holding trace and experience data), a message queue (decoupling execution from the distillation pipeline), a container platform (running evaluation jobs), and log monitoring services; the specific choices need to be assessed against business scale and data volume.

    6. Conclusion

    The technical essence of RSI is not “giving AI memory,” but building an engineering system for producing, abstracting, storing, transferring, and validating experience. Cross-model inheritance is just a natural outcome of that system—when experience exists in a structured, model-agnostic form, which model executes it is no longer a key variable. For developers, the most pragmatic entry point at this stage is to get trace collection and the experience format specification right first, so the flywheel can complete its first turn.