Agent Harness Architecture: Principles and Plugin-Based Practice

    This article explains what an agent harness is and why it sits between a language model and a deliverable agent system. It covers the core "everything is a plugin" principle, the two-plane design with scoped contexts, the three extension layers of skills, tools, and hooks, and the guard, approval, and sandbox boundaries. It also walks through runtime lifecycle and hot updates, traces a full loop from a single tool call, and offers a hands-on path from a minimal setup to a custom plugin, plus notes on mapping the design to cloud capabilities.

    1. Where the Problem Starts: Models Generate Tokens, Agents Complete Tasks

    A large language model is fundamentally a conditional probability generator: given a context, it emits the next token, then repeats. It has no memory, no tools, no notion of permissions, and no idea what “task complete” means. An agent system that can actually be delivered must do more: remember multi-turn interactions, call external capabilities, stop and ask for confirmation when something goes wrong, confine sensitive operations to an isolated environment, and retry or roll back after failures.

    That gap is the reason a harness (the agent runtime) exists. A harness is not the model, nor is it a specific application. It is the middle layer that hosts the model and organizes model capabilities into a system that can complete tasks. A common mistake in the industry is to conflate the harness with the product: the product is the final form shaped for a scenario, while the harness is the runtime foundation that makes such products possible to build reliably. Separating the “product layer” from the “runtime layer” is the first step in any architecture discussion.

    2. Core Design Principle: Everything Is a Plugin

    Traditional agent frameworks often hardcode model adapters, tool registration, session storage, and loop control into one large object. As a result, swapping a model means changing core code, and adding a tool means intruding into the main flow. The plugin principle inverts this structure: the runtime provides only a minimal kernel and contracts, and every capability is composed in as a plugin.

    The engineering value shows up in three places. First, replacement cost: the model adapter becomes a pluggable unit, so switching providers or protocols does not touch the loop logic. Second, capability trimming: a minimal composition keeps only the generation loop for troubleshooting, while a full composition layers in tools, memory, and approval for production. Third, observable composition: the same model behaves differently under different plugin combinations, which itself becomes a reproducible experimental method.

    A schematic plugin contract can be abstracted as:

    1. interface Plugin {
    2. name: string
    3. dependsOn?: string[] // Declared dependencies, re-resolved by the runtime
    4. setup(ctx: ScopeContext): void | Promise<void>
    5. dispose?(): void | Promise<void>
    6. }

    The key parts are dependsOn and dispose. The former lets the runtime perform topological sorting and re-resolution of dependencies; the latter makes unloading a first-class operation instead of something that can only be cleaned up by restarting the process.

    3. Two Planes and the Scope Context

    Putting every plugin into a single global namespace quickly leads to mutual overrides and permission overreach. A more mature approach divides the system into two planes:

    • Host Plane: process-level and long-lived, responsible for configuration loading, plugin loading, logging, and resource pools. It is close to an “operating system.”
    • Agent Plane: task-level and potentially short-lived, carrying the session, the visible tool set, and loop state. It is close to “a sandbox process for one run.”

    Connecting the two is the Scope Context. It is both a dependency injection container and a boundary for visibility and permissions: a plugin can only resolve services exported within its own scope, and child scopes inherit by default but can be narrowed. This turns questions like “can tool A see the session transcript” and “can a subtask use the write-file tool” into declarative configuration rather than checks scattered through the code.

    4. Three Extension Layers: Skill, Tool, Hook

    Extension points fall into three layers with clear, non-overlapping responsibilities:

    1. Skill: an encapsulation of knowledge and methodology that tells the model “how to approach this kind of problem.” It is usually loadable instructions and reference material, and it does not directly produce side effects.
    2. Tool: the execution entry point for a capability, with a defined input schema and output structure. It is the only channel that interacts with the external world.
    3. Hook: a cross-cutting concern that inserts logic before and after tool calls and between loop iterations, used for recording, rewriting, and interception.

    Three boundaries around tools must be kept distinct, or the security model is effectively useless:

    • Guard: static and upfront validation that checks parameter schemas, target paths, and command allowlists, and can reject a call outright before it runs.
    • Approval: routing high-risk actions to a human or a policy engine for confirmation, emphasizing “pausable and rollback-able.”
    • Sandbox: even if the first two layers are bypassed, the execution environment itself still restricts the reachable filesystem and network, serving as the last line of defense.

    The three are layered in depth, not substitutes for one another. Writing “do not delete files” in a prompt is not a Guard; approval without a sandbox cannot prevent unexpected behavior in the dependency chain.

    5. The Runtime: Dynamic Composition, Lifecycle, and Hot Updates

    The hard part of plugin architecture has never been “registration” but “change.” A usable runtime needs two kinds of composability:

    • Composability over time: plugins can be mounted or unmounted during a run, dependencies are re-resolved accordingly, and plugins whose requirements are not met enter a waiting state instead of crashing.
    • Composability over space: scope nesting determines service visibility, child scopes can override implementations, and implementations can switch strategies by environment.

    The lifecycle is usually abstracted into a few phases: resolve dependencies → initialize → ready → suspend → dispose. Side effects (timers, listeners, external connections) must be bound to the current lifecycle node and reclaimed together when the node is disposed. This is the meaning of an Effect boundary. An execution unit (think of something like a Fiber, a cooperative task node) carries one plugin initialization or one task run and supports cancellation and upward error propagation.

    The correct way to do hot updates is not to “swap an object reference.” Instead: load the new version in a new scope and run a health check, then switch traffic or references over, and finally dispose of the old node. If initialization of the new version fails, the new node is discarded and the system stays as it was.

    6. From a Single Tool Call to a Full Loop

    Restoring the chain gives you a basis for troubleshooting and optimization:

    1. User input
    2. → Append to the session event log (replayable)
    3. → Assemble context (system instructions + skills + history)
    4. → Model generation
    5. → Parse the tool call intent
    6. → Guard check → Approval (if needed) → Execute inside the Sandbox
    7. → Write the result back to the event log
    8. → Decide whether to terminate, otherwise continue to the next round

    The session event log is the “source of truth” for the whole architecture: it is the basis for reconstructing context and the foundation for replay, evaluation, and auditing. Designing the log as append-only, with typed events and correlation identifiers, makes time-travel debugging, failure reproduction, and metrics collection much easier later.

    Advanced capabilities are also built on this chain: Code Mode lets the model emit an executable snippet instead of a long sequence of tool calls; a SubAgent opens a constrained loop in a child scope to isolate context growth; a Workflow declares a multi-step process to reduce the uncertainty introduced by model freedom; and a self-modifying runtime allows adjusting its own plugin composition within a controlled range, but must be paired with approval and snapshot rollback.

    7. Hands-On: From Running It to Building Your Own

    The recommended order is “get it running, take it apart, then build your own”:

    1. Run the minimal composition with only the generation loop, and confirm the model connection and logging work.
    2. Use four different plugin compositions (standard, tool-enhanced, minimal, divergent creative) to observe differences in the same model, and build an intuition that “behavior is determined by composition.”
    3. Add skills, tools, and hooks one by one, recording how the event log changes at each layer.
    4. Turn on Guard and the sandbox, and construct privilege-escalation cases to verify that interception actually works.
    5. Write your own plugin: declare dependencies, implement setup and dispose, and verify hot updates and failure rollback.
    6. Define a custom composition that pins down defaults, permission boundaries, and log levels, forming a baseline your team can reuse.

    8. Mapping to Common Capabilities in the Cloud

    In real deployments, a harness is often not a single-process application. Common cloud capabilities can carry each part: a container platform hosts runtime instances and elastic scaling; object storage holds session snapshots and experiment artifacts; a message queue decouples long-running tasks from result delivery; logging, monitoring, and alerting services handle event log search, metrics dashboards, and anomaly notifications; and key management services hold model credentials and tool credentials. Baidu AI Cloud offers corresponding capabilities in these common categories, and you can organize them along the principle of “stateless runtime + externalized state + centralized observability,” avoiding leaving sessions and credentials on the instance locally.

    Conclusion

    The value of a harness is turning “can the agent complete the task” from something mystical into an engineering problem: capabilities come from plugin composition, boundaries come from scopes and the three lines of defense, change comes from lifecycle and dependency re-resolution, and quality comes from event logs and reproducible experiments. Once you understand this way of organizing a system, the model is just one replaceable part; what really determines the ceiling of the system is how you design the composition and the constraints.