Harness Architecture for AI Coding Agents: Configuration and History

    This article breaks down the architecture of a production-grade AI coding runtime, referred to as a Harness, along two orthogonal lines: composition structure and history continuity. It explains why a minimal agent loop is not enough for real products, how declarative configuration is layered and mounted line by line into an observable runtime graph, and how the session layer records history, compresses context, and restores state. The discussion covers model and credential routing, tool policies and approvals, sandbox and remote execution, multi-host access, and sub-agent and plugin lifecycles, offering a reference pattern for building a maintainable Harness.

    1. Introduction: Why “It Runs” Is Not the Same as “Production-Grade”

    When building an AI coding tool, many teams start with a minimal agent loop: assemble a prompt, call the model once, parse the tool calls in the response, execute the tools, feed the results back to the model, and repeat until the task is done. That loop is enough for a demo, but it struggles to support a real product. A production-grade runtime does not face a single ideal path; it faces a large amount of combinatorial complexity: how models and credentials are managed, how to recover after a session is interrupted, how to compress context when it grows too long, whether tool calls need approval, whether code execution runs locally or in a remote sandbox, how the same runtime facts are observed by multiple host interfaces, and how sub-agents are started and stopped and plugins are hot-swapped.

    A mature design approach splits this complexity along two orthogonal main lines. The first line answers “what capabilities make up the system right now” and focuses on the composition of the runtime. The second line answers “what the system has done before” and focuses on the continuity of history. Together, the two lines form the main body of a complete runtime. Using these two lines as its skeleton, this article analyzes the general architecture of a class of AI coding runtimes (hereafter referred to as a Harness), with emphasis on the assembly process from static configuration to a dynamic runtime graph. It does not cover any specific vendor implementation and only discusses layering methods and engineering practices widely accepted in the industry.

    2. Two Main Lines: Composition Structure and History Continuity

    2.1 Composition Structure: The Runtime Graph Is Assembled

    The composition structure line addresses capability orchestration. A production-grade Harness does not construct a hard-coded application at startup. Instead, it first reads a set of declarative configuration, then a loader mounts each entry as a plugin instance, ultimately forming an observable runtime graph. The benefits are clear: capabilities can be composed on demand, hosts can reuse the same kernel, plugins can be started and stopped independently, and failures can be traced to a specific node.

    2.2 History Continuity: Sessions Are Recoverable

    The history continuity line addresses state. A single coding task often spans multiple rounds of tool calls, multiple context compressions, and even multiple process restarts. Without a unified session abstraction, recovery can only rely on temporary files and manual conventions, and there is nowhere for compression policies to live. The session layer records “what has been done” and rebuilds a context view equivalent to the state before interruption when recovery occurs.

    2.3 Why the Agent Loop Alone Is Not Enough

    The minimal loop only covers the closed loop of “single inference and execution,” while a product must additionally handle six categories of problems: credentials and model routing, session recovery and compression, tool policies and approvals, sandbox and remote execution, multi-host access, and sub-agent and plugin lifecycles. Handing the latter group of combinatorial complexity to the composition structure line and history continuity to the session line allows the loop itself to stay minimal. This “thin loop plus thick runtime” layering is key to Harness maintainability.

    3. From Configuration to Runtime Graph: Breaking Down the Assembly Flow

    3.1 Three Layers of Configuration

    At startup, a Harness typically reads three types of configuration and layers them in order: a base Profile describes the default capability set, a Bundle describes a reusable package of capabilities, and a user Patch describes personalized overrides. The layering order determines priority, with later entries overriding earlier ones. A sketch:

    1. Profile(default baseline)
    2. ⊕ Bundle(capability package)
    3. ⊕ Patch(user override)
    4. => resolved list of configuration lines

    3.2 The Loader Mounts Line by Line

    The resolved configuration is not instantiated all at once. Instead, the loader processes it line by line: each line declares a plugin and its parameters, and the loader resolves dependencies, orders them, instantiates them, injects context, and attaches the nodes to the runtime graph. Line-by-line mounting keeps “partial failure” manageable: if one line fails, that line can be rolled back without affecting nodes that are already ready.

    1. for line in resolved_config:
    2. plugin = loader.instantiate(line)
    3. graph.attach(plugin)
    4. if plugin.failed: rollback(line)

    3.3 Observability of the Runtime Graph

    The runtime graph is not only an execution structure but also an observability structure. Every node exposes unified lifecycle events, and logging services, monitoring alerts, and the interface layer subscribe to the same event stream, ensuring that “what the UI shows” and “what the kernel executes” are the same runtime facts. This matters especially in multi-host scenarios: a CLI, a desktop app, and a remote session can share different views of the same runtime graph.

    4. The Session Layer: Engineering History Continuity

    4.1 What a Session Records

    A session records more than conversation text. It also includes the tool call trace, summaries of execution results, the mapping between pre- and post-compression content, and the checkpoints needed for recovery. This makes it possible to rebuild a context consistent with the state before interruption after a process restart or host switch.

    4.2 Compression and Recovery

    Context compression is a must-have for production. A common approach is to keep the raw text of the most recent several rounds and produce structured summaries of earlier content, while retaining an index of summaries and raw text in the session to avoid irreversible information loss. On recovery, the checkpoint is loaded first, plugin state is rebuilt according to the runtime graph, and finally the session view is injected into the loop.

    4.3 Collaboration with the Composition Structure Line

    The session layer is unaware of specific plugin implementations and reads and writes state only through a unified interface; the composition structure line is unaware of historical details and only mounts plugins in place. The two are decoupled through runtime graph nodes and session checkpoints, so the evolution of either side does not require changes to the other.

    5. Where Production-Grade Capabilities Fit

    • Models and credentials: registered as capability packages, supporting multi-model routing and credential isolation, keeping keys from being scattered in prompts.
    • Tool policies and approvals: a policy interceptor is inserted before tool nodes to allow, ask, or deny based on risk level.
    • Sandbox and remote execution: execution nodes are abstracted as local or remote backends, so the loop does not need to be aware of the difference.
    • Multi-host: the same runtime graph exposes different views to different hosts, with a single source of truth in the event stream.
    • Sub-agents and plugins: implemented as subgraphs and hot-swappable nodes, so starting and stopping them does not affect the main loop.

    6. Conclusion

    Governing “what the system is made of” and “what the system has done” separately is the core judgment of Harness architecture. Configuration is layered three times and then mounted line by line by the loader into a runtime graph, while the session layer independently maintains history and recovery; the two meet at runtime graph nodes. For developers, the direct benefits of this layering are a simple loop, pluggable capabilities, recoverable state, and runtime facts that can be observed consistently by multiple parties. In engineering practice on cloud platforms such as Baidu AI Cloud, similar “declarative assembly plus recoverable sessions” approaches are also widely used to govern complex toolchains and can serve as a reference pattern for building your own Harness.