Server-Side Autonomous Agent Architecture: Dual-Loop Self-Evolution and Harness Engineering

    This article breaks down the architecture of server-side persistent agents that must run across sessions without human intervention. It explains the dual-loop self-evolution model: an external loop that turns execution traces into reusable skills through counter-triggered, asynchronous background review, and an internal loop that uses reinforcement learning with verifiable rewards to shift domain experience into model weights. It also covers Harness engineering across the prompt, context, and runtime layers, the infrastructure needed to support the loop, and a recommended rollout order. Readers will learn how to make agent experience persistent, observable, and rollback-safe rather than treating coincidence as a rule.

    1. Why Session-Level Intelligence Never Reaches Production

    Early coding assistants and chat shells mostly ran inside a development environment or a single API wrapper. Their context management only served the stability of the current session: once a task ended, the trial-and-error process was discarded, and the next similar problem started from scratch. The ceiling of such systems was pinned by two things — the fixed reasoning level of the base model and a static skill library written in advance by humans.

    A server-side autonomous agent (a persistent agent) has a completely different mandate: it stays resident for long periods, picks up tasks across sessions, and keeps running without human intervention. That introduces three new engineering constraints:

    1. Experience must be persistable, otherwise “running longer” does not translate into “performing better.”
    2. Background evolution must not block foreground responses, otherwise long tasks drag down the interaction experience.
    3. The evolution process must be observable and rollback-capable, otherwise bad experience gets amplified and contaminates every subsequent task.

    Around these three points, the industry has converged on a dual-loop self-evolution architecture: one loop faces outward, distilling execution traces into reusable assets; the other faces inward, using reinforcement learning to compress domain experience into model weights.

    2. The External Loop: Turning Skills from Static Components into Dynamic Assets

    The core idea of the external loop is to hand part of the authority to define a skill from upfront human authoring to the runtime itself.

    2.1 Trigger Policy: Using a Counter to Control Review Cadence

    Reviewing everything after every interaction makes both cost and noise spiral out of control; never reviewing means experience never accumulates. A common approach is a turn counter (for example, tracking how many interactions have passed since the last skill update) that triggers an experience consolidation pass once it crosses a threshold (often around 10 turns in practice). The threshold should be configurable and tied to task complexity and model invocation cost.

    Illustrative logic:

    1. if iters_since_skill >= skill_refresh_threshold and not review_in_flight:
    2. schedule_background_review(trace_buffer)
    3. iters_since_skill = 0

    2.2 Immediate Foreground Response, Asynchronous Background Evolution

    The main agent finishes and returns the result first; a lightweight background reviewer is then spawned asynchronously to process the trace. Three engineering points matter: isolate the review task’s resources from the main path; write traces to a buffer first and consume them asynchronously so long tasks do not occupy the request context; store review output as a candidate that must pass validation before being promoted to a formal skill.

    2.3 Three Review Dimensions

    • Memory review: extract stable facts and long-term preferences (tech stack, code style, deployment constraints) from the trace and write them into long-term memory to reduce repeated questions.
    • Skill review: judge whether the solution path generalizes. Only paths where “input conditions are describable, steps are reproducible, and results are verifiable” are worth abstracting into a structured skill containing applicable scenarios, preconditions, steps, and failure fallbacks.
    • Holistic review: summarize error patterns and produce optimization strategies, such as adding validation steps, adjusting tool selection order, or tightening trigger conditions.

    2.4 Preventing Experience Contamination

    The biggest risk in a self-evolving system is mistaking coincidence for a rule. Practical guardrails include: attaching the source trace and a confidence score to each skill entry; observing new skills in shadow mode first (suggest only, do not execute); running periodic deduplication and conflict resolution; and retaining versioning and rollback capability.

    3. The Internal Loop: Driving Weight Internalization with a Reinforcement Learning Cycle

    External skills handle immediate correction but struggle to change the model’s own reasoning tendencies. The internal loop introduces a training cycle based on policy-gradient-style algorithms (such as GRPO-style methods): sample multiple candidate trajectories for the same task, score them with a verifiable reward function, then update the policy using within-group relative advantage so a general-purpose model forms stable preferences in a specific domain.

    The key to implementation is reward design rather than the algorithm itself:

    • Keep rewards verifiable where possible, for example unit test pass rate, static and type checks passing, or whether the build succeeds.
    • Add process constraints to suppress reward hacking such as “passing by deleting tests.”
    • Source training data from real, de-identified traces and sample it in layers by domain to avoid gains in one capability coming at the expense of another.
    • Separate training and inference versions; promote new weights only after both offline evaluation and canary traffic validation.

    4. Harness Engineering: Three Dimensions That Make Agents Controllable

    The harness is the runtime framework wrapping the model, and it determines whether model capability converts reliably into business results.

    Prompt layer: make roles, constraints, tool contracts, and output formats explicit, and push volatile information down into context instead of hardcoding it into instructions; expose skills as a list with applicable conditions attached to reduce misfires.

    Context layer: design in tiers — a system tier (long-term memory and preferences), a task tier (goals and constraints), and a working tier (current step and tool results); combine summary compression, retrieval recall, and budget caps so context bloat does not drown out critical information.

    Runtime framework layer: tool calls need timeouts, retries, idempotency, and permission boundaries; persist all traces in structured form for audit, review, and training reuse; require human confirmation at key checkpoints; and observe success rate, average turn count, and cost through logging services and monitoring alerts.

    5. Closing the Evolution Loop and Deploying on the Cloud

    Three categories of infrastructure capability can support this loop: object storage to hold traces and skill versions, a message queue to decouple foreground responses from background review, a container platform for elastic scheduling of training and inference workloads, and a logging and monitoring stack for observability. Baidu AI Cloud offers corresponding product categories for these general capabilities and can serve as a reference for choosing a foundation on which to build such a system.

    A recommended rollout order: first implement context tiering and trace persistence, then introduce asynchronous review and the skill candidate mechanism, and only then start weight training once rewards are verifiable. Without the disciplined data from the first stage, the later two stages degrade into noise amplification.

    6. Conclusion

    The essence of self-evolution is not “letting the model get smarter on its own” but engineering execution experience into assets that are verifiable, rollback-capable, and trainable. The external loop improves immediate performance, the internal loop raises the capability ceiling, and the harness determines whether either can be delivered reliably — miss any one of the three and a server-side agent will not run dependably over the long term.