AI Coding Harness Architecture: Composition and History

    This article breaks down the architecture of a production-grade AI coding harness along two main lines: composition and history. It explains why the minimal agent loop is only a skeleton, how declarative configuration layers (Profile, Bundle, Patch) are merged and mounted into a runtime graph, and how a fact-first event history enables compression, recovery, and auditing. It also maps common concerns such as credentials, tool approval, sandboxing, multi-host integration, sub-agents, and plugin lifecycle to the correct layer, and closes with practical recommendations for building a deliverable, recoverable, and auditable harness.

    1. Background: Why an “Agent Loop” Is Not a Product

    In discussions about implementing AI coding tools, the most frequently mentioned concept is the so-called minimal loop: assemble a prompt, call the model once, parse the tool calls returned by the model, execute the tools, feed the results back to the model, and repeat until the task is complete. This loop is indeed necessary; it is the skeleton of any AI coding capability. But treating the skeleton as the product is one of the most common misjudgments in engineering practice.

    A harness that can be delivered for a team to use must answer a series of engineering questions beyond the minimal loop: where models and credentials come from and how they rotate; how to recover after a long task is interrupted; how to compress context when it exceeds limits without losing critical constraints; which tools may run automatically and which require human approval; whether tools run locally or in a remote sandbox; how the same runtime facts are observed simultaneously by a CLI, a GUI, and logging services; how subtasks are spawned and reclaimed; and how plugins start and stop on demand without affecting tasks already in progress.

    These questions share a common trait: combinatorial explosion. They are not logic inside the loop but constraints around it. Stuffing them all into the loop implementation quickly degrades the core logic into a set of hard-to-test conditional branches. A more reasonable approach is to layer the complexity: one layer answers “what the system is composed of right now,” and another answers “what the system has done before.”

    2. Two Main Lines: Composition and History

    The composition line describes a static, assemblable capability map. It is driven by configuration declarations and includes model access, tool sets, policy components, execution environments, host adapters, UI observation, and so on. The output of this layer is a runtime graph: which plugin instances are mounted and how their dependencies and event channels are connected.

    The history line describes a dynamic, replayable stream of facts. It records every user input, every model decision, every tool call and return, and every compression and recovery. The output of this layer is a persistent, searchable, and trimmable event sequence.

    Together the two lines form the body of the harness. The composition line determines “which capabilities are available now,” while the history line determines “how those capabilities were used before.” Without the composition line, history is just a pile of records with no execution power; without the history line, the capability map starts from zero on every launch, making recovery, auditing, and consistent UI presentation impossible.

    3. From Configuration to Runtime Graph: Layering and Mounting

    A production-grade harness should not directly construct a fixed application object at startup. Instead, it should follow a declarative assembly path. A typical order is: first read a base Profile that declares the default model category, default tool set, and default policies; then layer on Bundles that introduce preset capability combinations, such as one for code retrieval and one for command execution; finally layer on a user Patch that allows a team or individual to override local behavior.

    The key constraint of the three-layer stacking is that override semantics must be explicit and predictable. A recommended rule is “path addressing + shallow merge + deduplication of lists by identifier,” which avoids the same configuration item being implicitly appended twice. A sketch:

    1. Profile (base defaults)
    2. └─ Bundle (capability combinations)
    3. └─ Patch (user overrides) → merged configuration lines
    4. └─ Loader mounts each line as a plugin instance → runtime graph

    During the mounting stage, the loader consumes configuration lines one by one. Each line describes a plugin instance’s identifier, implementation kind, dependencies, and initial parameters. The loader maintains a dependency graph, instantiates in topological order, and performs reverse-order rollback if instantiation fails, ensuring no half-started state remains.

    1. # Example: minimal structure of a configuration line
    2. - id: model.default
    3. kind: model-provider
    4. params: { credential_ref: cred.primary }
    5. - id: tools.readonly
    6. kind: tool-set
    7. depends_on: [model.default]
    8. params: { allow: [search, read_file] }
    9. - id: policy.approval
    10. kind: approval-policy
    11. depends_on: [tools.readonly]
    12. params: { require_confirm_for: [write_file, run_command] }

    This assembly approach brings two direct benefits. First, capabilities can be trimmed: scenarios that do not need sandbox execution can skip mounting the sandbox plugin, keeping the runtime graph lighter. Second, observability is unified: all instances register to the same graph, so the UI and logs only need to subscribe to the graph and event stream rather than each maintaining a separate state copy.

    4. The History Line: Recording and Compressing Session Facts

    The core design principle of the history line is “facts first.” What is recorded is not the model’s natural-language summary but structured events: input events, decision events, tool call events, tool return events, policy interception events, compression events, and recovery events. Each event contains at least a stable identifier, a time sequence, the owning session, a payload, and backward/forward references.

    Long tasks inevitably hit the context limit, so a compression mechanism is required. Compression is not simple truncation; it should preserve three kinds of information: the task goal and acceptance criteria, confirmed key facts and constraints, and outstanding items with next-step plans. In engineering terms, this can be done with segmented summarization plus pinning of key points, and the compression action itself is recorded as an event so the replay chain stays complete.

    Recovery capability depends on event persistence. After a session is interrupted, the loader rebuilds the runtime graph, then the history line replays in order up to the interruption point, and finally control is handed back to the loop. Idempotency matters here: tool call events must carry an idempotency identifier so replay does not produce duplicate side effects.

    5. Where the Combinatorial Complexity Lands

    Placing the above complexity onto the two main lines yields a clear responsibility table:

    • Credentials and model access: belong to the composition line; credentials are injected by reference and never written into history payloads.
    • Tool policies and approval: the composition line declares the policies, while runtime interceptions and approvals are recorded in the history line.
    • Sandbox and remote execution: the composition line selects the execution backend; the history line records only summaries of calls and results plus their addressable locations.
    • Multi-host access: adapter plugins on the composition line map the same runtime graph to different host UIs.
    • Sub-agents: the composition line declares spawning capability; the history line maintains hierarchy through parent-child references.
    • Plugin start/stop: controlled by the composition line, with start/stop events written to the history line to ensure auditability.
    • UI observation: holds no independent state; it only subscribes to the runtime graph and event stream.

    6. Practical Recommendations

    First, stabilize the event model before discussing a plugin ecosystem. Once the event structure is published, all subsequent hosts and UIs depend on it. Second, document the configuration merge rules and add tests covering stacking conflict scenarios. Third, keep approval and sandbox defaults strict, and loosen them gradually per scenario. Fourth, make the compression strategy configurable and replay-verifiable to avoid losing critical constraints during compression. Fifth, if team-level sharing and centralized auditing are needed, general cloud capabilities can carry event storage, log search, and monitoring alerts—for example, using object storage for session snapshots, a message queue to decouple event distribution, and a container platform to host sandbox execution environments—keeping the harness itself lightweight.

    Mastering the two main lines of composition and history is what moves an AI coding harness from a demo-level loop to a deliverable, recoverable, and auditable production-grade architecture.