Agent Harness Architecture: Principles and Plugin-Based Practice
This article explains the role of an agent harness, the runtime layer that turns a token-generating language model into a system capable of completing tasks end to end. It covers the core "everything is a plugin" design constraint, four preset plugin combinations for isolating behavior differences, the separation of responsibilities across skills, tools, and hooks, and how guard, approval, and sandbox layers differ. It also describes plugin runtime concerns such as dependency resolution, lifecycle consistency, hot reload, and configuration separation, along with a bottom-up build order and a four-part verification system. Readers will gain a practical framework for designing and validating their own harness.
1. The Starting Problem: Models Generate Tokens, but Tasks Require a Closed Loop
The core capability of a large language model is to predict and generate subsequent tokens given a context. It has no inherent knowledge of the current time, what exists in a database, or whether the file system is writable, and it will not retry on its own after a failure. A system that can be called an “agent,” however, must complete a closed loop of perception, planning, action, observation, and replanning. The gap between these two is precisely why the agent runtime exists — commonly referred to in the industry as a harness, a framework that carries and constrains the model.
The relationship can be summarized as a contrast:
- The model decides “what to say next.”
- The harness decides “whether that utterance can be executed as an action, how the execution result is fed back, and when to terminate.”
The harness is therefore not an appendage to the prompt, but a software system with clear boundaries. It must handle context assembly, tool invocation protocols, permission decisions, execution isolation, state persistence, error recovery, and observability. Skipping this layer and connecting a model directly to a business system typically produces three kinds of failures: unconstrained tool calls that lead to privilege escalation, unbounded context growth that leads to runaway cost, and no recoverable state after failure that leaves tasks hanging.
2. Core Design Principle: Everything Is a Plugin
“Everything is a plugin” does not mean the slogan “make everything a pluggable module.” It is a strict architectural constraint: no privileged paths exist in the system, and every capability must be registered, composed, and unloaded through a unified contract.
This principle yields three direct benefits.
First, capabilities become replaceable. The model adapter layer, the tool set, session storage, and the loop scheduling strategy are all plugins, so switching model vendors or storage media requires no changes to the main flow code.
Second, behavior becomes explainable. When the same model behaves differently under different plugin combinations, the source of the difference can be traced to a specific plugin rather than vaguely attributed to “model instability.”
Third, boundaries become trimmable. High-risk capabilities (such as writing to external systems or executing scripts) can be loaded on demand as standalone plugins, turning security policy from a code branch into a configuration decision.
A unified contract typically contains four elements: a unique identifier, dependency declarations, lifecycle hooks, and capability exports. The structure looks like this (illustrative only, not a specific product interface):
plugin:id: <unique name>dependsOn: [<plugin id>, ...]setup(ctx): # register tools, subscribe to events, read configurationdispose(): # release connections, cancel timers, unregister listenersexports: { tools, hooks, services }
The key point is that setup and dispose must come in pairs and be reentrant. Only when the unload path is treated with equal importance do hot updates and canary rollbacks become engineering-feasible.
3. Four Observation Dimensions: Using Preset Combinations to Locate Behavior Differences
The most effective engineering entry point is to get the system running first, then observe behavior using a controlled-variable approach. Prepare several preset combinations, keep the model and task prompt unchanged, vary only the plugin set, and observe differences in output and execution traces. The four common combinations can be abstracted as follows:
- Minimal combination: only the model adapter and the basic loop, with no tools and no persistence. Used to confirm baseline reasoning quality and whether termination conditions are reliable.
- Read-only combination: adds retrieval and query tools, and forbids any write operation. Used to validate context injection and citation traceability.
- Read-write combination: adds write tools and an approval step. Used to observe the agent’s decision tendencies and risk appetite under “able to act” conditions.
- Isolated execution combination: adds a sandbox and resource limits. Used to evaluate the stability of long-chain tasks and failure recovery capability.
The value of this method is that it converts “agent performance” from a vague impression into attributable engineering variables. If the minimal combination works but the read-only combination produces hallucinated citations, the problem lies in the retrieval plugin and context assembly; if the read-write combination triggers approval frequently, the problem lies in the granularity of permission design rather than model capability.
4. Three Extension Layers: Dividing Responsibilities Across Skill, Tool, and Hook
Extension capabilities must be layered, or the rules will contaminate one another. A fairly common industry split is as follows.
A skill is a package of knowledge and process aimed at the model, usually presented as a structured description and a sequence of operations, telling the model “how many steps to take for this kind of task and what to watch for at each step.” It executes no action and only affects planning quality. The key to skill design is to keep it short, deterministic, and decidable, avoiding vague style suggestions.
A tool is the only layer that actually produces external side effects. A tool definition needs to include a name, a purpose description, a parameter schema, a return structure, and error semantics. Parameter schemas should be narrowed as much as possible: replace free text with enumerations and compress the ambiguity space with required fields. Errors must be returned in a structured form so the model can distinguish “invalid parameter,” “insufficient permission,” “resource not found,” and “temporarily unavailable,” and therefore choose the correct next step.
A hook is a cross-cutting concern, used to insert unified logic before and after tool calls — for example, redacting sensitive information, auditing calls, suppressing duplicate requests, and circuit-breaking on timeout. Placing cross-cutting logic in hooks rather than inside each individual tool is the key to preventing rules from scattering.
5. Execution Boundaries: What Guard, Approval, and Sandbox Each Handle
The three are often conflated, but their responsibilities are entirely different.
- Guard is the decision layer: before execution, it decides to allow, deny, or require human confirmation based on policy. It concerns “whether it should be done,” its output is a decision, and it consumes no business resources.
- Approval is the interaction layer: it suspends requests judged as “needs confirmation,” waits for human input, and handles timeouts, rejections, and additional notes. It concerns “who decides,” and is essentially a waiting flow with a state machine.
- Sandbox is the isolation layer: it executes in a controlled environment, limiting the file system, network egress, CPU and memory, and execution duration. It concerns “how large the impact is if it goes wrong.”
Clear boundaries avoid the most common design mistakes: using a sandbox in place of permission decisions (which leads to an epidemic of high-cost executions), or using approval in place of isolation (which leads to human fatigue while the risk is not truly constrained). The three should be chained into a single pipeline: Guard decides → Approval if necessary → Sandbox executes → Hook records and reclaims.
6. The Plugin Runtime: Dynamic Composition, Lifecycle, and Dependency Re-resolution
Once all capabilities are pluggable, the real difficulty shifts to the runtime. The runtime must solve four things.
First, dependency resolution. Plugins declare dependencies instead of hard-coding order; the runtime builds a dependency graph and performs a topological sort. When a dependency is missing, loading should be rejected with a clear reason, rather than failing later at call time.
Second, lifecycle consistency. The unload order is the reverse of the load order, and if any plugin fails to initialize, the completed setup calls must be rolled back to avoid leftover listeners and half-open connections.
Third, hot updates. When replacing a plugin, load the new instance and complete dependency re-resolution first, then remove the old instance; during this window, reference counting or generation identifiers keep in-flight requests from being interrupted.
Fourth, separation of configuration and code. The same plugin differs only in configuration across presets, making “behavior differences” reproducible, versionable, and reviewable.
An illustrative loading flow:
load(config):graph = resolveDependencies(config.plugins)for node in topologicalOrder(graph):await node.setup(ctx) # on failure, dispose loaded nodes in reverse orderactivate(exports)reload(pluginId, newConfig):new = instantiate(pluginId, newConfig)await new.setup(ctx)swapReferences(pluginId, new) # in-flight calls still hold the old referenceawait old.dispose()
7. From the Designer’s Perspective: Building and Validating Your Own Harness
The recommended build order is bottom-up: first define the tool contract and error semantics, then add hooks and decision policies, and finally tune skills and preset combinations. Writing complex skills too early amplifies contract defects into behavioral problems that are hard to locate.
The verification system should include four types of tests:
- Contract tests: whether each tool’s parameter validation, error codes, and idempotency are stable.
- Policy tests: whether Guard’s decision matrix covers privilege escalation, boundary violation, and rate-exceeding scenarios.
- Lifecycle tests: after repeated load/unload and hot updates, whether listener leaks, unreleased handles, or dangling dependencies exist.
- End-to-end replay: regression with a fixed task set and fixed model outputs, comparing success rate, average number of steps, approval trigger rate, and resource consumption across plugin combinations.
Observability is likewise a harness responsibility. Task identifiers, the basis for each step’s decision, tool input summaries (after redaction), elapsed time, and result status should be recorded uniformly, so that a failure can be fully replayed. Without replay capability, an agent system can hardly iterate stably on complex tasks.
8. Conclusion
The maturity of agent engineering does not depend on how many tools are connected, but on whether the harness has a unified contract, clear boundaries, and a controllable lifecycle. Only by bringing the model adapter, tools, sessions, and the loop into the plugin system, using preset combinations for controlled-variable observation, constraining side effects through layered extensions, and relying on the runtime to guarantee the consistency of dynamic composition, can a “model that generates tokens” be reliably turned into “an agent that completes tasks in a closed loop.” In Baidu AI Cloud’s engineering practice, this kind of capability is typically carried by a container platform for the runtime, supported by log services and monitoring alerts for observability, and backed by object storage for session and replay data, forming a reusable layered architecture paradigm.
