Agent Experience Transfer Across Models and Tasks: Building a Harness That Self-Improves
This article explains why an AI agent's behavior is shaped by its external harness rather than model weights alone, and why copying an optimized harness to a new model or task usually fails. It shows how to capture each change as a structured experience record, run a three-stage migration loop of experience retrieval, hypothesis replay, and controlled adoption, and enforce evaluation gates with layered metrics, dual-environment validation, and holdout isolation. Readers will also find engineering notes on observability, canary rollout, cost control, and common pitfalls such as overfitting the evaluation set.
1. Where the Problem Starts: Agent Capability Lives Outside the Model
An agent’s behavior is often not determined by the parameters of its underlying task model alone. How prompts are organized, which tools are callable, how tool results are parsed and compressed, what retry strategy applies after a failure, and when the task is judged complete and execution stops — all of this happens outside the model, orchestrated by an external program. The industry commonly calls this external orchestration layer the harness.
The harness determines what the model “sees, what it can do, and how its output is judged afterward.” This is exactly why recursive self-improvement (RSI) can happen at this layer: run the current version of the harness, collect execution feedback, propose candidate modifications, then use evaluation to select a better version, and repeat. Throughout this loop, the task model’s weights can stay frozen; what actually gets iterated is the external program and its configuration.
In the example from the source material, the score in the workspace corresponds to a single experimental setup. That points to a key fact: the benefit of a change is environment-dependent, not intrinsic to the change itself.
2. Why Migrating an Optimized Harness Often Fails
Moving a harness tuned in the source environment to a new model or task, unchanged, tends to run into four recurring problems:
- Distribution shift: the new task differs in data distribution, input length, and noise level, so existing thresholds and branch conditions no longer match.
- Capability boundary changes: after switching models, instruction following, structured output stability, and long-context utilization all change. Heavy validation designed for a “weakly constrained model” may become redundant overhead.
- Distorted feedback signals: with a different evaluation set, metrics that once separated good from bad may saturate or lose discriminative power.
- Overfitting the source environment: repeatedly tuning against the same batch of samples means the change effectively memorizes surface features of the source evaluation set.
The conclusion is straightforward: what should be migrated is not just the modified code, but the experience that produced those modifications.
3. The Core Idea: Keep the Rationale, Not Just the Code
The smallest transferable unit is not the diff, but the causal explanation behind the diff. Each change should be recorded as a structured experience entry:
{"change_id": "c-2024-07-11-003","symptom": "model ignores key fields when a tool returns overly long text","hypothesis": "context noise dilutes critical information","action": "apply field-level trimming and summarization to tool results","evidence": {"before": 0.61, "after": 0.78, "sample_size": 240},"scope": {"task_type": "retrieval QA", "model_class": "medium context"},"risk": "aggressive trimming may drop necessary evidence","rollback": "ratio switch that keeps a share of raw results"}
What is genuinely transferable here is symptom, hypothesis, risk, and scope; action is only one instantiation valid in the current environment. During migration, match on scope first, then treat action as a candidate to be validated rather than a settled conclusion.
4. The Migration Loop: A Three-Stage Cycle
- Experience retrieval: based on the new task type, the model capability profile, and the evaluation metrics, retrieve entries from the experience library whose scope is close.
- Hypothesis replay: validate on a tiny sample in the new environment whether the hypothesis still holds; if it does not, discard the entry and record a counterexample.
- Controlled adoption: merge the change only after the evaluation gate passes, and keep a switch in place for fast rollback.
Illustrative scheduling logic:
def migrate(exp, new_env):if not scope_match(exp.scope, new_env.profile):return "skip"if not cheap_validate(exp.hypothesis, new_env, n=32):return "reject" # counterexamples are written back to the library toocand = instantiate(exp.action, new_env)return "accept" if gate_pass(cand, new_env) else "rollback"
5. Evaluation Gates: Avoiding the Cross-Environment Gain Illusion
- Layered evaluation: separate the capability layer (did it complete), the efficiency layer (steps, latency, call volume), and the stability layer (variance across repeated runs).
- Dual-environment validation: run once in the source environment and once in the target environment; a change counts as transferable only if neither side regresses.
- Holdout isolation: tuning uses only the development set, while the final decision uses a holdout set that never participated in any change.
- Significance awareness: gains on small samples may be noise, so report sample size and variation range instead of a single-point score.
6. Engineering Notes
- Separate the experience library from the code repository: experiences are searchable structured data and fit a store with version management; code and configuration go through the normal code review process.
- Observability first: without fine-grained logs and tracing, you cannot localize a symptom, and experience capture has nothing to build on; generic logging services and monitoring/alerting capabilities are enough to establish a baseline.
- Canary and rollback: run the new harness version on a small traffic share first, with automatic rollback when metrics turn abnormal.
- Cost control: recursive iteration naturally multiplies call volume, so set an iteration budget and early-stopping conditions.
- On cloud platforms such as Baidu AI Cloud, the loop can be assembled from generic capabilities — a container platform to host the harness runtime, object storage for experience library snapshots, and a message queue to decouple evaluation jobs — without relying on any proprietary interface.
7. Common Pitfalls
- Treating a score as a conclusion: a score from a single experimental setup is not enough to support a migration decision.
- Migrating code but not the rationale: the result is starting from zero trial and error every time the environment changes.
- Unbounded recursion: self-improvement without evaluation gates and budget constraints quickly degrades into overfitting the evaluation set.
- Ignoring the value of counterexamples: rejected changes and the reasons behind them are an important asset for avoiding repeated mistakes.
8. Summary
Self-improvement across models and data is essentially upgrading a “change” into a “conditional piece of experience.” With frozen model parameters, an iterated external orchestration program, structured experience records, strict evaluation gates, and canary rollback, an agent can reuse past gains in a new environment instead of paying the trial-and-error cost all over again.
