Server-Side Autonomous Agent Architecture: Dual-Engine Self-Evolution and Engineering Practices

    This article breaks down a server-side autonomous agent architecture built around dual-engine self-evolution: an external engine that turns execution trajectories into reusable assets, and an internal engine that uses reinforcement learning to internalize domain capabilities into model weights. It covers trajectory review triggers, three-dimensional trajectory analysis, declarative skill libraries, the data synthesis and training pipeline, and a three-layer Harness spanning prompts, context, and execution. Readers will also find a phased rollout plan and risk controls for experience drift, data compliance, and cost growth.

    1. Background: Why Being Smart Within a Session Is Not Enough

    AI coding tools and conversational assistants have spread quickly over the past two years, yet most solutions still share a structural flaw: their capabilities are anchored to the base model and a static list of skills. Context management only serves the stability of a single session. Once the task ends and the context is cleared, the correct path discovered in that round, the pitfalls encountered, and the user’s long-term preferences are all lost. When the next similar task arrives, the system starts trial and error from scratch.

    A server-side resident autonomous agent (referred to below as a “resident agent”) solves a different class of problem. It needs to run continuously for days or even weeks and take over real business workflows, rather than completing a code snippet inside an IDE. This imposes three hard requirements:

    • Persistence: state is recoverable, and tasks survive process restarts;
    • Auditability: every decision and tool call can be traced;
    • Evolvability: capabilities grow over time instead of staying fixed.

    This article takes the publicly described design of an open-source resident agent project as a reference blueprint, strips away its product-specific attributes, and abstracts it into a general architectural pattern: dual-engine self-evolution made up of “externally driven experience accumulation + internally driven weight optimization,” supported in production by engineering practices across three layers: prompts, context, and the Harness.

    2. External Evolution: Turning Execution Trajectories into Reusable Assets

    The core judgment behind the external route is that a task’s execution trajectory is not log garbage but material for training and optimization. The key design is “instant response in the foreground, asynchronous review in the background,” so that review never slows down user-perceived latency.

    2.1 Trigger Strategy: Counter Plus Threshold

    A simple and effective approach is to maintain a counter for the number of iterations since the last skill update, and trigger an experience consolidation pass once it reaches a threshold (commonly 8–12 rounds in engineering practice). Illustrative logic:

    1. class EvolutionTrigger:
    2. def __init__(self, threshold=10):
    3. self.threshold = threshold
    4. self.iters_since_skill = 0
    5. def on_turn_end(self, trajectory, state):
    6. self.iters_since_skill += 1
    7. if self.iters_since_skill >= self.threshold:
    8. self.iters_since_skill = 0
    9. state.enqueue_review(trajectory) # Enqueue asynchronously, do not block the response

    The threshold should not be too small: frequent reviews amplify noise and misjudge a path that succeeded by chance as general experience. It should not be too large either, or error correction lags behind.

    2.2 Background Review: Deconstructing Trajectories Along Three Dimensions

    After the main agent returns a result, the system spawns a lightweight review agent that analyzes the trajectory along three tracks:

    1. Memory review: extract stable facts and long-term preferences (such as output language, code style, and approval habits) and write them into the long-term memory store; explicitly mark one-off information as short-term to avoid contamination.
    2. Skill review: judge the generality of the solution. If a path recurs across multiple similar tasks with a stable success rate, abstract it into a structured skill containing applicable preconditions, steps, failure fallback strategy, and verification method.
    3. Synthesis review: summarize error patterns (such as repeatedly calling the same failing API or skipping a validation step) and generate constraint entries that are injected back into the prompt layer.

    Review outputs must carry a confidence score and the source trajectory ID. Low-confidence content only enters a candidate pool and is promoted after being confirmed by a subsequent successful trajectory. This two-level “candidate–confirmation” mechanism is the key to suppressing experience drift.

    2.3 The Engineering Form of the Skill Library

    Skills should be stored as declarative descriptions to make them easy to retrieve and compose:

    1. skill:
    2. name: batch_report_export
    3. when: A structured report must be exported on a schedule and the field mapping is stable
    4. steps: [pull data source, validate field mapping, write in shards, generate verification summary]
    5. fallback: If fields are missing, degrade to a raw export and raise an alert
    6. confidence: 0.82
    7. evidence: [traj_7f3a, traj_91bd]

    3. Internal Evolution: Internalizing Weights Through Reinforcement Learning

    External skills solve “instant error correction,” but they cannot raise the base model’s native reasoning ceiling. The internal route uses reinforcement learning to compress domain capability into the weights, so a general-purpose model builds a stable advantage in a specific domain. This loop typically consists of three independently deployable microservices:

    • Data synthesis service: select high-quality samples from successful trajectories, then deduplicate, anonymize, and stratify by difficulty to construct “instruction–context–expected behavior” triples;
    • Trajectory compression service: compress long tool-call sequences into semantically equivalent compact representations, reducing training and inference costs while preserving key decision points;
    • Training service: adopt a method such as Group Relative Policy Optimization (GRPO), sampling multiple candidate trajectories from the same prompt and estimating advantage from within-group relative scores, which removes the need for a separate value network and keeps memory usage and engineering complexity more manageable.

    Engineering practice must hold three red lines: training data must be anonymized and traceable; the offline evaluation set must be compared against the online distribution on a regular basis to prevent overfitting to the synthetic distribution; and new weights must be released gradually, with online success rate and human takeover rate as rollback criteria.

    4. Harness Engineering Practices: A Three-Layer Support System

    The Harness is the runtime framework that wraps the model and determines whether the model’s capabilities can be delivered reliably.

    4.1 Prompt Layer

    Split the prompt into four sections: identity and boundaries, the available skill list, the current task, and constraints plus output format. Separate dynamic fragments from static ones for caching. Constraint entries are continuously written back by the synthesis review, forming a closed loop.

    4.2 Context Layer

    Context governance matters more than context stacking. A four-part budget is recommended: system constraints take a small share; long-term memory is retrieved and injected on demand; recent dialogue is kept in its original form; and history is compressed into summaries. Combined with a sliding window and relevance retrieval, this prevents irrelevant content from crowding out attention.

    4.3 Execution and Harness Layer

    Tool calls need a unified gateway: timeouts, retries, idempotency, quotas, and auditing are all consolidated in one place; dangerous operations require a second confirmation. State is persisted to external storage so the agent can recover from a checkpoint after a crash. For observability, feed trajectories, token consumption, and tool failure rates into logging services and monitoring alerts, giving both a capacity view and a quality view.

    5. Rollout Roadmap and Risk Control

    A four-stage rollout is recommended: first persistence and observability, then external skill accumulation, then offline evaluation, and finally internal training. Risk control focuses on three points: suppress experience drift with the candidate–confirmation mechanism; ensure data compliance through anonymization and least privilege; and contain cost growth with context budgets and trajectory compression. The essence of dual-engine self-evolution is to turn “running” itself into a data source, so the agent keeps getting stronger in real business work while capability growth always stays within measurable, rollback-safe engineering boundaries.