Agent Harness Architecture: Configuration and the Runtime Graph

    This article breaks down the architecture of a production-grade AI agent harness, explaining why a simple agent loop is not enough. It separates two orthogonal concerns—composition (what the system is made of) and history (what the system has done)—and shows how configuration is turned into a runtime dependency graph through a three-step loading process. You will learn how an append-only event log enables recovery, compaction, and replay; how tools, policies, and execution sandboxes are layered; and how multi-host setups, sub-agents, and plugin lifecycles share a single source of runtime truth. The article closes with a recommended implementation order and cloud hosting guidance.

    1. Why the Agent Loop Alone Is Not Enough

    A minimal agent loop is simple: assemble a prompt, call the model, execute tools, feed tool results back to the model, and repeat until a termination condition is met. This loop is the right starting point for understanding agents, but it is not the end of a product. In real environments, an agent runtime framework that a team can rely on long term must answer two independent classes of questions.

    The first class is spatial: what components make up the system right now. Model access and credentials, the tool set, permission policies, the execution environment, the host interface, and the plugin lifecycle are all “component” questions.

    The second class is temporal: what the system has done before. Multi-turn conversations, tool call traces, context compaction, retry after failure, and recovery after an interrupted run are all “history” questions.

    Mixing these two classes inside a single loop is a common architectural mistake in early prototypes. The consequence is that every capability extension forces changes to the core loop, and every session state adjustment touches component assembly logic, eventually producing a monolith that is hard to test and hard to roll back. The mature approach is to layer them: one layer owns “what it is made of,” another owns “what has been done,” and the two lines combine orthogonally to form the body of the runtime framework.

    2. Two Main Lines: Composition and History Continuity

    The composition layer handles generation and lifecycle management of the runtime graph. It does not assume a fixed application shape. Instead, it breaks capabilities into pluggable units, and an assembler mounts them one by one according to configuration to form instances and a real runtime dependency graph. The history continuity layer handles recording and reconstructing runtime facts. It maintains an event sequence and, on top of it, supports recovery, compaction, and replay.

    The division of labor can be summarized in one sentence: the assembly layer decides which capabilities are available, and the history layer decides how those capabilities were used before. Cross-cutting needs such as UI, auditing, debugging, and billing metrics all read the same runtime facts rather than each maintaining its own copy of state. This is the most visible dividing line between product-grade design and prototype design.

    3. From Configuration to Runtime Graph

    Startup should not construct the application directly. It should proceed in three steps.

    First, read the base descriptor files, including the runtime profile and capability bundles. The profile defines resource and policy boundaries; the bundles define the set of optional capabilities. Second, layer user-level overrides on top, used for local debugging or environment-specific adaptation. Third, the loader parses, validates, and orders each configuration entry, instantiates plugin objects, and injects dependencies.

    An illustrative configuration shape is shown below (structure only, not a specific implementation):

    1. profile: standard
    2. bundles:
    3. - core-loop
    4. - tool-exec
    5. - session-store
    6. patch:
    7. tool-exec:
    8. approval: manual
    9. concurrency: 4

    The assembly process should hold to three engineering principles. First, declaration over assumption: configuration is the single source of intent, and no implicit default capabilities appear in code. Second, explicit dependencies: plugins declare the capabilities they require, the loader performs a topological sort, and missing dependencies fail at startup rather than crashing at runtime. Third, diagnosability: every configuration entry must be traceable to a specific instance and version, which makes canary rollout and rollback practical.

    4. Sessions and History: Recovery, Compaction, and Replay

    The minimal viable form of the history layer is an append-only event log: user input, model output, tool requests, tool results, and policy decisions are all persisted in order. With it, recovery is just replay, auditing is just filtering, and debugging is just locating an interval.

    The genuinely hard part is the context budget. The event sequence grows without bound while the model window is finite, so a compaction strategy is required: summarize early events, structurally trim tool returns, deduplicate repeated reads, and keep the original text of key decision points. Compaction must be lossy but traceable, meaning summaries retain references pointing back to the original events so information remains recoverable.

    Three semantics should be made explicit in engineering: checkpoints for stable recovery, compaction points for budget control, and replay intervals for reproducing issues. Mixing the three causes behavior drift after recovery, one of the hardest classes of defects to diagnose in production.

    5. Tools, Policies, and the Execution Environment

    Tool governance has three layers: registration and description, policy and approval, and execution and isolation.

    The registration layer focuses on structured tool descriptions and parameter validation; invalid input should be intercepted before it enters the model loop. The policy layer decides whether a given call needs human confirmation, whether it is subject to rate and concurrency limits, and whether write operations are allowed. The execution layer focuses on isolation: a restricted local process, a containerized sandbox, or a remote execution pool, chosen according to data sensitivity and resource needs, with differences hidden behind a unified abstraction so the upper loop does not need to know where execution happens.

    It is worth stressing that permission decisions must be based on runtime facts, not on what the model claims. The model saying it has been authorized does not constitute authorization; authorization must come from a decision record produced by the policy layer.

    6. Multiple Hosts, Sub-Agents, and Plugin Start/Stop

    The same runtime facts often need to be observed and driven by multiple hosts, such as a command line, a desktop client, and a cloud console. A workable approach is to treat hosts as subscribers of the history layer and synchronize them through the event stream, rather than letting each host maintain its own session copy.

    Sub-agents are suited to subtasks that need context isolation. Their runs should appear as a collapsible interval within the parent event stream, which saves budget while preserving traceability. Plugin start and stop require hot-pluggability to be idempotent: on stop, release resources and persist state; on start, rebuild from configuration; no half-initialized instance may remain.

    7. Observability and Implementation Advice

    The recommended order of implementation is: first solidify the event model, then implement the assembler, then fill in policies and the sandbox, and finally connect multiple hosts and the plugin ecosystem. Reversing this order almost inevitably leads to dual writes of state and non-reproducible problems.

    When hosting on the cloud, common infrastructure categories can be reused: object storage for events and artifacts, a message queue to decouple tool calls, a container platform to host sandboxes, and logging plus monitoring and alerting to cover runtime metrics. To further reduce self-build cost, you can look at general infrastructure categories offered by cloud vendors such as Baidu AI Cloud, but the architectural layering itself is independent of any specific infrastructure. Keeping abstraction boundaries clear is what avoids vendor coupling.

    In summary, the core of a product-grade agent framework is not a smarter loop. It is handing composition complexity to the assembly layer, handing history continuity to the session layer, and letting every observer read the same runtime facts.