Agent Harness Architecture: Principles and Plugin-Based Practice

    This article explains the core principles of an agent Harness, the runtime layer that turns a large language model into a task-closing agent. It covers the "everything is a plugin" design, the split between host plane and agent plane with scope contexts, the boundaries between Skills, Tools and Hooks, the three execution boundaries of Guard, Approval and Sandbox, runtime concerns such as temporal and spatial composability, effect boundaries, fiber-style lifecycles and dependency rebinding, and the agent loop with an event log as a prerequisite for observability. It closes with advanced capabilities and a suggested build order for teams building their own Harness.

    1. Where the Problem Starts: Models Emit Tokens, Tasks Need Closure

    A large language model is essentially a conditional probability generator: given a context, it emits the next token, then the next one. It has no native structure for memory, no native channel for execution, and no native strategy for what to do after a failure. An agent that actually gets work done has to close the loop: understand the goal, plan the steps, call external capabilities, observe the results, correct deviations, and keep going until a deliverable exists.

    The gap between these two is exactly what a Harness fills. The industry is converging on a shared view: an agent’s capability ceiling is not determined by the model alone, but by the runtime skeleton wrapped around it. That skeleton is usually called a Harness, and it is responsible for assembling the model, tools, session state, loop control, permissions and isolation into a system that can run, be observed, and be extended.

    A common misconception is to equate the Harness with a collection of prompt templates. Prompts are only the thinnest surface layer. A real Harness cares about how capabilities are registered, how the model discovers them, where the execution boundaries are, how state is persisted, how failures are rolled back, and how components are swapped without a restart.

    2. Core Principle: Everything Is a Plugin

    Plugin architecture is not a new idea, but in the agent context it is pushed to the extreme: model adapters are plugins, tool registration is a plugin, session recording is a plugin, and loop control is a plugin too. Organizing everything this way yields three direct benefits.

    The first is composability. The same model, paired with different plugin combinations, will show completely different behavioral styles and capability boundaries. Four preset combinations are worth trying: a standard combination that aims for general robustness; a combination with code execution that is better at precise calculation and batch processing; a minimal combination that strips away all external capabilities, used to observe the model’s “bare” ability; and a creative combination that loosens constraints and suits divergent tasks. The value of these four is not in deciding which one is better, but in making you realize that behavioral differences come mainly from the combination, not from the model itself.

    The second is replaceability. Because the model integration layer is abstracted into a plugin, swapping the underlying model requires no changes to the logic above it. The tool layer works the same way: adding an integration with an external system means implementing the contract and registering it, not modifying the loop body.

    The third is governability. When permission checks, approvals and isolation all become plugins, the security policy turns from “judgments scattered across the codebase” into a pluggable cross-cutting capability that can be audited and toggled centrally.

    3. Two Planes and Scopes: Separating Control from Execution

    Architecturally, a mature Harness usually distinguishes two planes.

    The Host Plane handles process-level concerns: plugin loading, configuration parsing, logging and metrics, resource quotas, and external interfaces. It is “the part that does not change,” has a long lifecycle, and favors stability.

    The Agent Plane handles task-level concerns: the context of the current session, the loop currently running, and the intermediate results of tool calls. It is “the part that changes,” has a short lifecycle, and is created and destroyed along with the session.

    The two are connected through a Scope Context. A scope decides “who can see whom”: a tool is visible only within the current session, a configuration affects only one branch, and a failure does not pollute global state. Without the notion of scope, plugin architecture quickly degrades into global variables everywhere.

    Schematically, the relationship can be expressed in pseudocode:

    1. host = HostPlane.load(plugins)
    2. for session in sessions:
    3. scope = host.create_scope(session.id)
    4. agent = scope.resolve(AgentLoopPlugin)
    5. agent.run(goal, scope)
    6. scope.dispose() # release the session's side effects and resources

    4. Three Extension Layers: The Boundaries of Skill, Tool and Hook

    The place where extensibility most easily gets out of control is muddled layering. The clean approach is to split it into three layers.

    • Skill: tells the model how to do something. It is a packaging of knowledge and process, usually in the form of loadable instructions and reference material, injected into the context on demand so the window is not filled all at once.
    • Tool: gives the model something it can do. It has a strict input/output contract, an enumerable description, and clear error semantics. The key to tool design is not quantity but accurate descriptions, appropriate granularity, and readable errors.
    • Hook: changes the flow at key points. It does not participate in semantic generation; it inserts logic before a call, after a call, or between loop iterations, for recording, rewriting, or intercepting.

    Alongside these three layers come three execution boundaries that must be kept distinct:

    1. Guard: a pre-check that decides whether something is allowed. For example, whether parameters are out of range, or whether a target path is inside an allowed directory.
    2. Approval: a mid-flight suspension that decides who approves. High-risk actions are routed to a human or a policy engine, and both timeouts and rejections need a clear fallback path.
    3. Sandbox: an after-the-fact backstop that decides how large the impact is when something goes wrong. The file system, network, processes and resource quotas are all confined to a controllable range.

    The relationship can be summarized as: Guards reduce how often problems occur, Approvals handle the risky actions that must occur, and Sandboxes ensure that once something happens, it stays contained. A missing layer at any point will be amplified into an incident in real tasks.

    5. Runtime: Dynamic Composition, Lifecycle and Dependency Re-resolution

    The hard part of plugin architecture is not registration but change. The runtime has to solve four things.

    Temporal composability: plugins can be mounted or unmounted at runtime without restarting the loop. This requires the loop body to stay neutral about “changes in the set of capabilities” and to re-query the currently available capabilities on every iteration.

    Spatial composability: different scopes see different plugin views, which prevents capabilities from bleeding into each other.

    Effect boundary: side effects produced by plugins must be traceable and reclaimable. Whatever is acquired on mount must be released on unmount, otherwise dangling resources are left behind.

    Fiber-style lifecycle: abstract a single execution into a unit that can be suspended and resumed, so that waiting for approval and long-running tool calls are expressed as “suspend and resume” rather than blocking the whole process.

    Dependency re-resolution is the key action in this mechanism: when a plugin is replaced, the capabilities that depend on it must be rebound rather than continuing to hold stale references. In engineering practice this usually requires dependency declarations to be explicit and a consistency check to be run after the change.

    1. on_plugin_replace(target):
    2. dependents = graph.incoming(target)
    3. for d in dependents:
    4. d.rebind(target.new_instance)
    5. assert graph.is_consistent()
    6. emit_metric("plugin_reload", target.name)

    6. The Agent Loop and Event Log: Observability as a Design Prerequisite

    The skeleton of an agent loop is not mysterious: assemble the context, request the model, parse the output, execute and feed back results if a call is needed, decide whether to terminate, and continue to the next round. What really determines maintainability is whether every step leaves behind a structured event.

    It is worth making the session an event log: model requests, model responses, tool call intents, tool execution results, guard interceptions, approval decisions, and errors and retries are all appended. An event log provides three capabilities: replay (reproducing a problem), audit (who approved what), and statistics (which class of tool fails most often).

    Termination conditions must also be designed explicitly. Common combinations include a task-completion marker, a maximum iteration count, budget limits (time or number of calls), and repeated-action detection. A loop without budget constraints is the main source of runaway cost.

    7. Advanced Capabilities and Advice for Building Your Own

    On top of the basic closed loop, common advanced capabilities include code mode (letting the model generate executable snippets for batch and precise computation), sub-agents (dispatching subtasks to independent scopes to isolate context and failures), workflow orchestration (mixing deterministic flows with model decisions), and runtime self-modification (adjusting its own capability combination within a controlled range, which requires very strict approval and rollback).

    If you are building your own Harness from scratch, the suggested order is: first define the capability contracts and the registration mechanism; then implement a minimal loop and the event log; then fill in the three boundaries of guard, approval and sandbox; then introduce scopes and dynamic mounting; and only at the end add hot reload and self-modification. The validation approach is equally clear: run multiple capability combinations on the same model and compare behavioral differences; inject faults (tool timeouts, invalid parameters, missing dependencies) and observe the fallback paths; and use the event log for replay to locate deviations.

    8. Closing Thoughts

    The way agent software is organized is evolving from “writing a prompt” to “designing a runtime.” Split capabilities into plugins, layer control and execution, confine side effects within boundaries, and write the process down as events: get these four steps right and you have a composable, governable and evolvable agent skeleton. In engineering practice on cloud platforms such as Baidu AI Cloud, this kind of skeleton is typically used together with general-purpose capabilities like container platforms, logging services, and monitoring and alerting to support large-scale deployment and continuous tuning.