A Dual-Drive Self-Evolution Architecture for Server-Side Autonomous Agents

    Session-centric agents often discard execution traces after a task ends, so trial-and-error experience is hard to reuse and capability stays tied to the base model and a static skill library. This article describes a dual-drive architecture for persistent server-side agents: an external path that turns trajectories into versioned skills and memory, and an internal path that internalizes domain experience into model weights through reinforcement learning, with Prompt, Context, and Harness as the engineering layers that close the loop.

    1. Background: Why Session-Centric Agents Struggle to Keep Improving

    Common agent forms fall into two broad categories: coding assistants embedded in a development environment, and chat shells wrapped around a single model API. Both are usually centered on the current session. Context management, tool calls, and result generation all serve one task. When the task ends, the execution trace is often discarded. Trial-and-error experience is hard to retain, and the system’s ceiling stays anchored to the base model and a static skill library.

    Server-side autonomous agents differ in two ways: persistent operation and self-evolution. Persistent operation means the agent is not a one-shot request-response handler. It is a running entity with long-lived state, a task queue, a memory store, a skill library, and an evaluation system. Self-evolution means the system can turn successful paths, failure modes, and preference facts from task execution into reusable assets, and in some cases further internalize them into model weights. Longer prompts or larger context windows are not enough. The architecture needs a closed loop of execution, review, retention, training, and evaluation.

    The dual-drive architecture discussed here has two paths. External evolution handles dynamic skill generation and experience retention, addressing immediate correction and reuse. Internal evolution uses reinforcement learning to internalize experience into weights and push past the base model’s reasoning ceiling in a specific domain. The two paths meet through shared trajectory data and a shared evaluation system, and they are carried by three engineering dimensions: Prompt, Context, and Harness.

    2. External Evolution: Dynamic Skill Generation and Experience Retention

    2.1 From a Static Skill Library to Evolving Assets

    A traditional skill library is usually a set of hand-written, static callable components. It is controllable, but coverage and adaptability are limited. The idea behind dynamic skill generation is to treat each complex task’s execution trace as candidate experience. A background review abstracts that trace into a structured skill, including applicable scenarios, preconditions, step orchestration, tool selection, exception handling, and verification methods. A skill is no longer a hard-coded function. It is a versioned, evaluable, and rollback-capable asset.

    To keep review work off the main path, the system can use a “foreground response, background asynchronous evolution” design. After the primary agent finishes the user response, it writes the trajectory to an archive queue. A background review agent processes it asynchronously. Interaction latency stays low, while experience organization continues.

    2.2 Triggers: Idle Rounds and Value Signals to Control Review Cost

    More review is not always better. Triggers are required. A common approach is a “skill idle rounds” counter: when the agent completes several consecutive task rounds without a skill-library update, experience organization is triggered. High-value signals—success after multiple retries, an explicit user correction, or recovery from a tool-chain failure—can also raise review priority. Thresholds should be configurable, and sampling, deduplication, and budget controls should prevent background review from becoming a cost sink.

    Illustrative pseudocode:

    1. def on_task_finished(task):
    2. archive_trajectory(task)
    3. if task.skill_idle_rounds >= SKILL_REVIEW_THRESHOLD:
    4. enqueue_background_review(task.trajectory, priority="normal")
    5. if task.has_high_value_signal():
    6. enqueue_background_review(task.trajectory, priority="high")

    2.3 Background Review Agent: Memory, Skill, and Synthesis Reviews

    The background review agent can use a lightweight model or a mix of rules and a model, and break a trajectory down along three dimensions:

    1. Memory review. Extract key facts, long-term user preferences, environment constraints, and domain knowledge, and write them to the system memory store. Each memory should carry source, time, confidence, and an expiry or invalidation policy, so one-off context is not treated as a lasting fact.
    2. Skill review. Judge how general the solution path is. If the path can be reused across tasks, abstract it into a structured skill. If it is a one-off operation, keep it only as a case. A skill entry should include input and output constraints, tool dependencies, failure fallbacks, and verification steps.
    3. Synthesis review. Reflect on error patterns. Identify whether the issue was prompt ambiguity, missing context, a wrong tool choice, or insufficient verification, and produce an optimization strategy that feeds back into prompt templates, context assembly rules, or Harness policy.

    2.4 Data Governance and Guardrails Against Regression

    Dynamic evolution must prevent experience pollution. Each retained asset should pass a quality gate: traceable source, deduplication, conflict checks against existing skills, offline evaluation, staged rollout, and fast rollback. The skill library should be versioned. The memory store should support expiry and correction. Only verified experience should enter the production skill library, so an accidental success is not frozen as a general strategy.

    3. Internal Evolution: A Reinforcement-Learning Loop for Weight Internalization

    External skill retention handles immediate correction and reuse, but it does not change the base model’s native reasoning distribution. Internal evolution uses reinforcement learning to internalize domain experience into model weights so a general model can go further in a specific domain.

    The loop usually has three core stages: high-quality data synthesis, trajectory compression and quality checks, and reinforcement-learning training.

    3.1 Trajectory Synthesis and Quality Checks

    A stronger teacher model, running in parallel executors, generates multi-turn dialogue samples for specific prompts or evaluation sets. Samples should cover successful paths, failure recovery, tool calls, and verification. After synthesis, quality checks are required: format validation, factual consistency, tool-call validity, answer verifiability, and deduplication. Low-quality samples in training amplify hallucinations and bad strategies, so the quality gate cannot be skipped.

    3.2 Trajectory Compression

    Raw trajectories are often long and full of irrelevant observations and repeated attempts. Compression keeps decision-critical points—state, action, observation, reward, and final outcome—drops noisy steps, and normalizes the result into a trainable format. Compression is not simple truncation. It uses importance scoring and causal-chain extraction so the training signal stays on effective decisions.

    3.3 Reinforcement Learning Training and Evaluation

    Reward design can combine outcome rewards, process rewards, and constraint penalties: whether the result is correct, whether tool calls comply with policy, whether the steps are economical, and whether safety policy is met. Algorithms such as Group Relative Policy Optimization (GRPO) can compare relative quality within groups of samples and reduce dependence on an absolute reward scale. After training, offline evaluation, regression tests, and staged online rollout are required, watching capability gains, general-capability regression, latency, and cost.

    Illustrative flow:

    1. samples = synthesize_with_teacher(prompts, parallel_workers)
    2. clean = quality_gate(samples)
    3. compressed = compress_trajectory(clean)
    4. policy = train_policy(compressed, reward_model)
    5. evaluate(policy, regression_suite)

    4. Prompt, Context, and Harness: Three Engineering Dimensions

    4.1 Prompt Engineering: From Static Templates to Policy Carriers

    A prompt should not be only a task description. It should carry skill selection, tool-use rules, verification requirements, and failure fallbacks. As the skill library evolves, prompt templates need parameterization and versioning, with A/B evaluation of their effect. The prompt’s job is to constrain the decision space, not to stack all knowledge. Knowledge belongs in the memory store and skill library and should be assembled on demand.

    4.2 Context Engineering: From a Session Window to Layered Context

    Context should be layered: system instructions, task state, long-term memory, skill fragments, tool observations, and temporary drafts. Assembly should include relevance retrieval, budget allocation, and conflict resolution to avoid context pollution. Persistent operation also has to handle cross-session state, task recovery, and memory expiry. The goal is not to fill the window. It is to show the model the right information at the right time.

    4.3 Harness Engineering: The Runtime Shell for a Production Agent

    The Harness is the engineering shell around the agent runtime. It includes tool registration and permissions, sandboxed execution, state management, retries and timeouts, observability, trajectory archival, evaluation replay, and safety policy. Without a Harness, the self-evolution loop cannot run stably. Without observability, review and training lack trustworthy data. The Harness should treat the execution trajectory as a first-class data asset, with a unified schema, sampling, and redaction, and with support for offline replay and regression tests.

    In a cloud deployment, general object storage, message queues, a container platform, logging, and monitoring and alerting can carry trajectory archival, asynchronous review, and training-job orchestration. General cloud product categories from Baidu AI Cloud can also be considered as infrastructure options of this kind. The architecture should stay neutral and combine capabilities according to the data loop and engineering-governance needs.

    5. Rollout Guidance and Evaluation Metrics

    A practical rollout should proceed in stages: first trajectory archival and background review, then quality gates for the skill library, and finally the reinforcement-learning loop. Metrics should cover task success rate, average step count, tool-call compliance rate, review-output adoption rate, skill reuse rate, regression rate, end-to-end latency, and cost per task. Every evolution action should be rollback-capable, and every training record should be traceable. Only when self-evolution is brought under engineering governance can the dual-drive architecture move from a concept to production use.