Agent Self-Evolution: A Dual-Track Architecture for Environment-Aware Updates

    Why does an AI agent fail when you switch files or change a directory, even with the same model and tools? The issue is usually not reasoning power, but that recursive self-improvement updates only "how to do it" while ignoring "what the environment looks like." This article splits agent self-evolution into two tracks: a method track for execution strategies and a cognition track for environment models and experience applicability. It presents a practical framework covering environment fingerprints, skill sharding, applicability scoring, failure attribution, and safe rollback. You will get a decision workflow for choosing between updating methods and updating cognition, plus a module breakdown and sample code that map directly to engineering implementation.

    An agent runs on the same model and the same tool chain, yet it fails frequently as soon as you swap in a different file or change the directory structure. The problem is rarely reasoning ability. More often, recursive self-improvement has updated only “how to do it” and never updated “what the environment is like.” This article splits agent self-evolution into two tracks: a method track that optimizes execution strategies, and a cognition track that maintains the environment model and the applicability boundaries of experience. It also provides a practical implementation framework with environment fingerprints, skill sharding, applicability scoring, failure attribution, and safe rollback. By the end, you will have a decision workflow for judging whether to change the method or change the cognition, along with a module breakdown and sample code that map directly to engineering work.

    1. Symptom Breakdown: Same Model, Degraded Performance

    A typical case: a colleague uses an AI coding tool to organize reports and it works on the first run. You reuse the same model, the same tool descriptions, and the same prompt flow, but after switching to your own files the agent starts repeatedly reading files, re-parsing the same data, and reworking its output. The only variable is the environment, yet the result is completely different.

    The cause usually falls into three types of environment drift:

    • Spatial structure drift: files are not in the expected directory, naming conventions differ, or there are multiple levels of nesting and temporary copies.
    • Data shape drift: delimiters, encodings, header levels, null representations, and date formats are inconsistent, and a single file may even mix several formats.
    • Constraint drift: output templates, field definitions, validation rules, and permission boundaries change, so results that were previously “good enough” are no longer compliant.

    The model supplies reasoning ability, and the execution framework (harness) organizes the flow and tool calls, but neither inherently knows “why the environment here is the way it is.” What really needs to be determined is: what are the current environment characteristics, and does historical experience still apply. When that judgment is missing, a blind spot forms in self-evolution.

    2. Root Cause: Single-Track Updates in Recursive Self-Improvement

    The usual practice of recursive self-improvement (RSI) is to collect task feedback, generalize reusable experience, and reuse it in the next task. The problem is that it assumes the environment is a stable constant, so it attributes every task failure to a poor method.

    This leads to two typical errors:

    • Overfitting the method: the interface conditions have changed, but the system keeps retrying the old call; the data format has changed, but it keeps applying old parsing rules. The method track is repeatedly fine-tuned, and noise is treated as signal.
    • Frozen cognitive lag: the environment model is not updated for a long time, wrong beliefs are written into long-term memory, and later tasks inherit and amplify the bias.

    When a run fails, should you change the method or correct your understanding of the environment? This is the attribution question a self-evolving system must answer first; otherwise improvement turns into oscillation.

    3. The Dual-Track Architecture: Method Track and Cognition Track Evolving in Parallel

    Make self-evolution explicitly two tracks, each with its own state, update cadence, and validation approach.

    • Method track (How): accumulates executable strategy units such as parsing steps, retry policies, validation order, and tool orchestration. Updates are driven by task success rate and cost.
    • Cognition track (Where/What): maintains the environment model, including directory layout, data schemas, constraint sets, permissions, and quotas. Updates are driven by newly observed environment characteristics and conflict signals.

    The two tracks are coupled through an “applicability check”: every piece of experience produced by the method track is bound to the conditions under which it holds, and the cognition track decides whether the current conditions are met. In engineering terms, an experience entry can be expressed as:

    1. {
    2. "skill_id": "parse_tabular_v3",
    3. "steps": ["locate", "sniff_schema", "normalize", "validate"],
    4. "preconditions": {
    5. "layout": "flat_or_one_level",
    6. "encoding": ["utf-8", "gbk"],
    7. "delimiter": ["comma", "tab"],
    8. "header_rows": [1, 2]
    9. },
    10. "env_fingerprint_min": 0.82,
    11. "fallback": "parse_tabular_v2_with_mapping"
    12. }

    The key is preconditions and fallback: experience is no longer a rule that is “always correct,” but a strategy with conditions that can be degraded and rolled back.

    4. Environment Modeling: Let the Agent See Clearly Before Acting

    Environment cognition needs to be computable, comparable, and versionable. Build an environment fingerprint that encodes non-semantic but outcome-determining characteristics into a structured vector or hash set:

    • Layout features: directory depth, file count distribution, naming patterns, and whether multiple versions of copies exist.
    • Schema features: field name sets, type distributions, null rates, enumerated values, and primary key uniqueness.
    • Constraint features: required fields, format templates, validation rule versions, and output definitions.
    • Runtime features: available tool sets, permission scope, rate and quota, and timeout thresholds.

    Sample implementation:

    1. def env_fingerprint(sample_files, constraints):
    2. return {
    3. "layout": {"depth": max_depth(sample_files), "n": len(sample_files)},
    4. "schema": {"fields": sorted(field_names(sample_files)),
    5. "null_ratio": null_ratio(sample_files)},
    6. "constraints": {"template_ver": constraints.version,
    7. "required": constraints.required_fields},
    8. "runtime": {"tools": sorted(available_tools()), "quota": quota_snapshot()}
    9. }
    10. def similarity(a, b):
    11. # Simplified: field set Jaccard + weighted constraint version match
    12. jac = jaccard(a["schema"]["fields"], b["schema"]["fields"])
    13. ver = 1.0 if a["constraints"]["template_ver"] == b["constraints"]["template_ver"] else 0.5
    14. return 0.7 * jac + 0.3 * ver

    With fingerprints, experience retrieval upgrades from “semantic similarity” to “condition matching”: first recall candidate strategies by semantics, then filter with fingerprint similarity, and experience below the threshold does not enter the execution path.

    5. Failure Attribution: Change the Method or Change the Cognition

    Attribution is the core of the dual-track system. Use a layered decision flow:

    1. Environment validation layer: does the fingerprint match the experience preconditions? If not, update the cognition track first and add environment observations, without penalizing the method.
    2. Execution layer: conditions match but a step errors out; check whether a tool, permission, or quota changed, which is runtime environment drift.
    3. Result layer: execution succeeds but validation fails; decide whether it is a method defect or a constraint version change; the latter is written to the cognition track.
    4. Stability layer: the same method has a success rate significantly below the historical baseline in similar environments, which triggers a method track rollback and retraining.

    The decision can be fixed with pseudocode:

    1. def attribute(failure, env_fp, skill):
    2. if similarity(env_fp, skill.env_ref) < skill.env_fingerprint_min:
    3. return "update_cognition" # fix the environment model first
    4. if failure.kind in {"tool_missing", "permission", "quota"}:
    5. return "update_cognition" # runtime environment changed
    6. if failure.kind == "validation" and failure.constraint_ver != env_fp["constraints"]["template_ver"]:
    7. return "update_cognition" # constraint drift
    8. return "update_method" # a real strategy defect

    The value of this flow is suppressing oscillation caused by wrong attribution: touch the method only when the environment is unchanged and the method fails; when the environment changes, fix the cognition first.

    6. Skill Sharding and Applicability Boundaries

    Making “experience” into large monolithic rules is naturally fragile. A more stable approach is skill sharding: split strategy families by environment intervals, with each shard maintaining its own success rate and confidence.

    • Sharding dimensions: layout type × schema family × constraint version.
    • Confidence update: use sliding-window success rate with Bayesian smoothing to avoid misjudgment from small samples.
    • Conflict resolution: when multiple shards match at once, choose by weighting “last validation time + similarity + historical success rate.”
    • Elimination: shards continuously below the threshold move to a quarantine zone, serving only as fallback and not participating in active recommendation.

    This way, an environment change affects only the relevant shards and does not pollute the global strategy library.

    7. Observability and Safe Rollback

    Dual-track evolution must be observable and rollback-capable; otherwise “self-improvement” becomes uncontrolled drift.

    • Metrics: shard success rate, attribution distribution (cognition vs. method share), fingerprint drift magnitude, rollback count, average rework steps, and cost per task.
    • Tracing: record each task’s fingerprint snapshot, matched experience, attribution conclusion, and final validation result to form an auditable chain.
    • Rollback: both experience entries and the cognition model are versioned and support one-click reversion to the last stable version; release new strategies gradually and validate them on shadow traffic first.
    • Guardrails: high-risk actions (delete, overwrite, external send) require explicit confirmation; permissions and quotas act as hard constraints and do not participate in “experience optimization.”

    For cloud deployment, object storage can hold experience and fingerprint versions, a message queue can decouple the attribution pipeline, a container platform can host parallel validation, and logging plus monitoring with alerting can provide drift warnings. These are all general capability categories and do not depend on a specific implementation.

    8. Suggested Rollout Path

    1. Build observability first: collect fingerprints and failure types, hold off on automatic updates, and verify attribution accuracy.
    2. Then enable the dual tracks: update the method track in small steps, version the cognition track independently, and set applicability thresholds.
    3. Introduce sharding and gradual rollout: split strategies by environment interval and scale up after shadow validation.
    4. Close the loop with guardrails: complete rollback, audit, and hard constraints, and only then open up higher-frequency automatic evolution.

    Conclusion

    The premise for an agent to get stronger with use is that it knows “where it is right now and whether old experience still holds.” Moving self-evolution from a single track to a method track and a cognition track in parallel, using environment fingerprints for condition matching, using layered attribution to decide whether to change the method or the cognition, and using sharding, gradual rollout, and rollback to control risk is what prevents the repeated rework of “it breaks as soon as the environment changes” and makes the agent’s continuous improvement genuinely compound in a stable way.