Why Agent Improvement Experience Gets Lost: A Guide to Designing Cross-Model Memory
When an AI agent moves to a different foundation model, carefully optimized prompts, tool descriptions, validation rules, and retry strategies may no longer work as expected. This guide explains why model-specific experience is difficult to transfer and presents a practical memory design based on hypotheses, constraints, evaluation evidence, versioning, and rollback. It also includes a lightweight Python implementation and a step-by-step migration process.
Why Model Changes Can Break Existing Configurations
In an AI agent system, the underlying large language model determines much of the reasoning capability, while the surrounding framework determines how that model is used. This framework may include prompt templates, tool descriptions, call sequences, output-parsing rules, and various interception and validation mechanisms.
Developers typically refine these components through repeated iteration. As a result, their effectiveness often depends on the behavioral patterns of a particular model.
When the underlying model changes, the existing framework may no longer be well suited to it. A configuration that achieved strong evaluation results after extensive trial and error on one model may perform worse after being migrated to another model—possibly even underperforming the new model’s initial configuration.
What Recursive Self-Improvement Means
Recursive self-improvement refers to a system continuously using its own feedback to modify part of itself and then running with the improved version. In agent engineering, the component being improved is usually outside the model itself.
Changing model weights is expensive and technically demanding. Teams therefore more commonly optimize the surrounding framework by revising prompts, adding tool instructions, introducing validation rules, or adjusting retry strategies.
The core process is a feedback loop:
- Run a task.
- Collect evaluation results.
- Analyze the failure.
- Propose a change.
- Evaluate again.
- Decide whether to keep or roll back the change.
Why Experience Is Difficult to Transfer Across Models
Only the Result Is Preserved, Not the Reason
Most teams save the final version of their configuration. The rules in the file are visible, but the reasons behind them are often missing. It may be unclear what type of failure led to a rule, what problem it solved, or whether it was intended to correct a bias specific to one model.
When an optimizer encounters a complex configuration with little documentation, it cannot easily distinguish between essential constraints and patches left over from an older model. The result is often arbitrary deletion or modification, or the continued accumulation of patches on top of existing ones, making the configuration increasingly difficult to understand.
Rules Are Interdependent
Interception rules and prompts often work together. For example, an interception rule may compensate for an edge case that is not covered by a prompt. Viewed in isolation, the rule may appear unnecessary, but removing it can cause errors.
Without recorded dependencies, migration becomes a cycle of repeated trial and error.
Experience Reflects Model Preferences
Some changes are actually corrections for the tendencies of a particular model, such as being overly conservative, producing unstable output formats, or preferring certain wording.
When these corrections are moved to a model with different behavior, they may mislead the new model instead of improving it.
Designing Experience Memory That Transfers Across Models
For experience to be reusable across models, each record should include the reason for the change, its constraints, and the validation results. The following structure is practical for this purpose.
Record Structure
Each effective improvement should include at least these fields:
- Component: The module being changed, such as a prompt, tool description, or interception rule
- Problem: The specific failure observed during evaluation
- Hypothesis: Why the proposed change is expected to solve the problem
- Change summary: A brief description of the modification
- Evaluation change: Metric values before and after the modification
- Constraints: Behaviors or boundaries that must be preserved
- Model tag: The model from which the experience originated and whether the change includes a model-specific correction
The hypothesis and constraints are especially important. They tell future optimizers why the change was introduced and which parts must not be modified casually.
Separate General Principles from Model-Specific Fixes
Experience should be divided into two categories.
The first consists of general principles, such as: “When a tool returns an empty result, explicitly tell the model instead of allowing it to guess.” These principles are usually more portable across models.
The second consists of model-specific fixes, such as a patch for a particular model’s output format. These should be labeled separately and revalidated first during migration.
Use Evaluation as Evidence
Every piece of experience stored in memory should have reproducible evaluation evidence. The evaluation set should cover normal execution paths, edge cases, and historical failure cases.
Without evaluation support, an experience record is only a hypothesis. Evaluation itself can also contain noise. Running multiple trials, calculating an average, or estimating a confidence interval can help prevent accidental variation from being mistaken for a genuine improvement.
Versioning and Rollback
Every change to the surrounding framework should have a version number. Experience records should be appended rather than overwriting historical records.
If a new version performs worse, the team should be able to roll back precisely to an earlier version and inspect the corresponding change records.
Example Implementation
The following simplified data structure illustrates the field design. It is only an example and does not correspond to any specific product interface.
from dataclasses import dataclass, field, asdictfrom datetime import datetimeimport json@dataclassclass ImprovementRecord:component: str # The module being modifiedproblem: str # The observed failurehypothesis: str # The reason for making the changechange_summary: str # A brief description of the changemetric_before: float # Evaluation metric before the changemetric_after: float # Evaluation metric after the changemodel_tag: str # Identifier of the source modelconstraints: list[str] = field(default_factory=list)created_at: str = field(default_factory=lambda: datetime.now().isoformat())def append_record(record: ImprovementRecord, path: str) -> None:"""Append a record without overwriting historical experience."""with open(path, "a", encoding="utf-8") as f:f.write(json.dumps(asdict(record), ensure_ascii=False) + "\n")
During migration, teams can first select potentially general experience and then validate each item on the new model:
def should_adopt(candidate_score: float, baseline_score: float,min_gain: float = 0.0) -> bool:"""Adopt a candidate only when it clearly outperforms the baseline."""return candidate_score >= baseline_score + min_gaindef filter_portable(records: list[ImprovementRecord]) -> list[ImprovementRecord]:"""Keep experience not marked as model-specific for initial migration."""return [r for r in records if "model-specific" not in r.constraints]
A Practical Engineering Workflow
- Establish a baseline: Run the complete evaluation set on the new model with the existing framework and record the initial score.
- Migrate in batches: Move general experience first. Evaluate each batch separately to avoid introducing too many changes at once.
- Run ablation checks: Remove changes one by one to confirm that each rule contributes value, and eliminate ineffective patches.
- Write every decision to memory: Record whether each change was adopted or rejected so that it remains available for future reference.
- Set release gates: Publish a candidate version only when its key metrics are no worse than the baseline and all safety-related cases pass.
Security and Privacy Considerations
Because experience memory is retained over time, it must not contain secrets, personally identifiable information, or other sensitive internal data. Failure samples should be anonymized.
Changes to interception rules that affect permissions or trigger external operations should undergo human review. They should not be delegated entirely to an automated optimization process.
Common Pitfall
One common mistake is treating memory as a place to accumulate prompts and rules. Experience memory should preserve the reasoning, constraints, and evaluation evidence behind a change—not simply become a growing collection of configuration fragments.
