Agent Harness Architecture: Principles and a Plugin-Based Approach

    This article explains what an agent harness is and why it matters for building reliable AI agents. It covers the core "everything is a plugin" principle, the three extension layers of skills, tools, and hooks, the execution boundaries enforced by guards, approvals, and sandboxes, and the runtime capabilities needed for dynamic mounting and dependency re-resolution. It also outlines a layered approach to verifying a harness design. The goal is to turn unpredictable model behavior into an engineering structure that is controllable, replaceable, and testable.

    1. The Starting Point: Models Generate Tokens, but Tasks Need a Closed Loop

    The core capability of a large language model is narrow and focused: given a context, predict and generate the next sequence of tokens. It does not read files on its own, issue requests on its own, or retry after a failure on its own. A real task, however, usually demands a complete loop: understand the goal, break it into steps, invoke capabilities, check results, and roll back when necessary. The layer of software that connects these two ends is commonly called an agent shell or runtime framework (referred to as the harness throughout this article).

    The harness is not part of the model. It is an engineering layer built around the model. It decides what context the model can see, which capabilities it can call, when a single loop ends, and how failures are observed and recovered. For this reason, the quality of the harness design directly determines the stability and maintainability of an agent in real business scenarios.

    The traditional approach writes all of these responsibilities into one large main flow: model invocation, tool dispatch, history trimming, and permission checks are all mixed together. It may run in the short term, but it will inevitably rot over time—any single change ripples across the whole system. Solving this problem at the root requires a unified structural principle.

    2. The Core Principle: Everything Is a Plugin

    “Everything is a plugin” means that the harness kernel itself implements no business capability and is responsible only for assembly. Model adaptation, tool registration, session recording, loop scheduling, and permission guards all exist as plugins, composed into a concrete, runnable agent through declarative configuration.

    This principle brings three direct benefits:

    • Replaceability: switching model providers requires only replacing the adapter plugin, with zero changes to business code.
    • Composability: the same model paired with different plugin sets yields multiple distinct “personalities” with clearly different behavior.
    • Trimability: capabilities that are not needed are not assembled, reducing context pollution and attack surface.

    A schematic assembly description can be written in the following form (it expresses structure only and is not a specific product interface):

    1. preset "research":
    2. - model.adapter # handles request construction, streaming parsing, token counting
    3. - session.memory # handles history persistence and window trimming
    4. - tool.registry # handles tool declaration and parameter validation
    5. - loop.agent # handles multi-turn loops and termination decisions
    6. - guard.risk # intercepts high-risk actions

    Keeping the same model unchanged and only swapping the plugin combination reveals a clear shift in capability boundaries. This is the most direct experiment for verifying whether a harness design is truly decoupled.

    3. Three Extension Layers: Skills, Tools, and Hooks

    In engineering practice, treating extension points as the same thing is a common mistake. A clear division should be as follows.

    The skill layer solves the knowledge problem of “how to do it.” It describes processes, constraints, and judgment criteria as structured text, injected into context when needed without occupying a permanent budget. A skill is an organizational form of prompt engineering, not executable code.

    The tool layer solves the capability problem of “what can be done.” A tool must have a clear input schema, output structure, and error semantics. Registration should complete parameter validation, timeout control, and result normalization, avoiding throwing raw exceptions directly back to the model, which would cause drift in subsequent reasoning.

    The hook layer solves the cross-cutting problem of “when something is governed.” It attaches logic at key points for logging, rewriting, and interception. Hooks should not carry the main business flow, or they will reintroduce coupling.

    The relationship among the three can be summarized as: skills tell the model the strategy, tools provide the actions, and hooks constrain the boundaries.

    4. Execution Boundaries: Guards, Approvals, and Sandboxes

    The real risk of an agent comes from “actions” rather than “text.” Therefore, the responsibility differences among three types of boundaries must be made clear.

    A guard is a synchronous, deterministic rule check, such as parameter ranges, destination domain allowlists, and call frequency, requiring low latency and unit-testability. An approval is an asynchronous gate that requires human intervention, suitable for irreversible or high-cost actions, and must support a fallback path after timeout or rejection. A sandbox is environment-level isolation that restricts the file system, network, and resource quotas, so that even if the first two layers fail, the impact is confined to a local scope.

    The three form a defense-in-depth relationship and cannot replace one another. A common anti-pattern is using a prompt to ask the model to “act cautiously,” which can only lower the probability and cannot constitute a guarantee.

    5. Runtime: Dynamic Mounting and Dependency Re-Resolution

    Once the number of plugins grows, static assembly can no longer cope. The runtime needs to provide four foundational capabilities:

    1. Dependency resolution: build a dependency graph from the declarations, determine assembly order, and detect circular dependencies.
    2. Lifecycle management: provide plugins with unified init, start, stop, and dispose phases, ensuring symmetric resource release.
    3. Dynamic mounting: load or unload plugins without restarting the process, enabling hot updates of capabilities.
    4. Re-resolution and migration: re-solve the assembly plan after dependencies change, and safely hand off state to the new instance.

    The symmetry of the lifecycle is especially critical. Schematic code:

    1. plugin.tool.registry:
    2. init(ctx) -> read declarations, build the index
    3. start(ctx) -> validate dependencies, open registration
    4. stop(ctx) -> close registration, wait for in-flight calls to finish
    5. dispose(ctx)-> release handles and caches

    During a hot update, first start the new instance and complete dependency re-resolution, then switch traffic over, and finally stop the old instance; at the same time, keep a persistent copy of the session state to avoid context loss.

    6. Verifying the Harness from the Designer’s Perspective

    Verification should be done in layers, narrowing the problem scope layer by layer:

    • Unit layer: deterministic tests for tool parameter validation, guard rules, and trimming strategies.
    • Composition layer: fix the model, switch plugin combinations, and compare whether behavior differences match expectations.
    • Fault layer: inject timeouts, error returns, and missing dependencies, and check the fallback and recovery paths.
    • Observability layer: confirm that every step has structured logs, call traces, and token metering, so issues can be traced and located.

    If cloud hosting is needed, general-purpose category capabilities can be used: a container platform hosts the runtime instances, object storage holds sessions and artifacts, a message queue decouples asynchronous approvals, and logging and monitoring with alerting provide observability. When selecting services, focus on elasticity, isolation, and auditability rather than the specific interface form.

    7. Conclusion

    The value of the harness lies in converging unpredictable model behavior into an engineering structure that is controllable, replaceable, and verifiable. “Everything is a plugin” provides the organizing principle, the three extension layers provide the order of extension, guards, approvals, and sandboxes provide defense in depth for security, and a runtime with dependency re-resolution provides the ability to evolve. With all four in place, an agent moves from a demonstration to an operable system.