Agent Harness Architecture Principles and Plugin-Based Practice
This article explains the role of an agent harness in turning a language model's token generation into a task execution loop, and how a plugin-based design organizes that complexity. It covers four key plugin layers—model adapter, tool registry, session store, and agent loop—along with a three-tier extension model of Skill, Tool, and Hook, a defense-in-depth security boundary of Guard, Approval, and Sandbox, and runtime requirements such as dynamic mounting, lifecycle management, and dependency re-resolution. It also outlines a learning path and four verification layers for building and validating your own harness.
1. The Starting Problem: Models Generate Tokens, Agents Complete Tasks
The core capability of a large language model is to predict and generate subsequent tokens given a context. It has no inherent ability to execute actions, remember history, constrain risk, or orchestrate a workflow. A deliverable agent, however, must close the loop: understand the goal, select tools, execute actions, observe results, and revise the plan until the task is done. The gap between the two is exactly why a harness exists.
A harness can be understood as an engineering layer wrapped around the model. It extends a pure text generation into a task execution process that is runnable, constrained, observable, and extensible. Without this layer, developers end up hand-writing prompt concatenation, tool call parsing, failure retries, and state persistence over and over inside business code, which eventually becomes a monolithic script that is hard to maintain. Systematically organizing these capabilities is a prerequisite for agent engineering to mature.
2. Core Design Principle: Everything Is a Plugin
“Everything is a plugin” is not a slogan. It is an engineering method that slices complexity horizontally and converges coupling points onto a unified contract. Concretely: model adaptation is not a hard-coded branch, tools are not functions baked into the main flow, session records are not scattered temporary variables, and even the agent main loop itself can be treated as a replaceable composition of plugins.
This design yields three direct benefits:
- Replaceable: the same model can run under different capability combinations, with behavior differences determined by the composition rather than by code branches.
- Evolvable: adding a new kind of logging, a new permission policy, or a new tool protocol only requires adding a plugin, with no change to the trunk.
- Verifiable: each plugin has a clear boundary, can be tested independently, and can also be regression-tested at the composition level.
3. Plugin Breakdown of Four Key Capabilities
3.1 Model Adapter Layer
Models differ in interface shape, context length, structured output support, and streaming behavior. Adapter plugins translate a unified internal request semantic into concrete calls, and normalize the returned results into a unified event stream. The key design is to lock the “differences” inside the plugin while exposing a stable contract to upper layers, for example a unified inference request and a set of incremental events.
Illustrative code (pseudocode):
interface ModelAdapter {async *stream(request: InferRequest): AsyncIterable<InferEvent>}
3.2 Tool Registry Layer
Tools are how an agent reaches the outside world. The registry must solve three things: description (name, purpose, parameter schema), discovery (how tools are retrieved at runtime), and invocation (parameter validation and result return). Making the registry a plugin means the tool set can change at runtime without restarting the process.
3.3 Session Record Layer
The session is the agent’s working memory. Record plugins handle message appending, context trimming, summary compression, and persistence. Abstracting persistence as a plugin lets the same agent logic run on local files or on general cloud capabilities such as object storage, message queues, or logging services, with no change to the trunk code.
3.4 Agent Loop Layer
The loop layer is the engine that drives repeated reasoning–action–observation iterations. Once it is pluginized, the loop strategy (single-turn, multi-turn, with reflection, with parallel branches) becomes a configuration item. Termination conditions, maximum steps, timeouts, and budget control should also be explicit parameters of the loop plugin rather than hidden inside business logic.
4. Three-Tier Extension Model: Skill, Tool, Hook
In practice, splitting extension points into three tiers significantly reduces cognitive load:
- Skill: a composite, task-facing capability, usually made of prompt constraints, workflow orchestration, and tool combinations. It answers “how to do a class of things.”
- Tool: an atomic, action-facing capability with clear and verifiable input and output. It answers “what can be done.”
- Hook: a process-facing interception point that inserts checks, rewrites, or records at key moments. It answers “when to intervene.”
The relationship among them: Hooks observe and constrain the process, Tools provide actions, and Skills organize actions into tasks. Confusing the tiers is a common anti-pattern, for example writing permission checks inside every tool, which scatters the policy and makes unified auditing impossible.
5. Security Boundaries: Guard, Approval, Sandbox
Once an agent has real execution ability, security design must come first. Three types of boundaries each play their own role:
- Guard: upfront static and rule-based validation that blocks obviously out-of-bounds or invalid-parameter calls, aiming for low latency and determinism.
- Approval: introduces human or policy confirmation for high-risk actions, emphasizing traceability and accountability.
- Sandbox: limits the capability scope of the execution environment, such as the visible filesystem range, network egress, and resource quotas, emphasizing that “losses stay bounded even if bypassed.”
The three are not substitutes but defense in depth: Guards reduce invalid risk, Approvals handle risks that require judgment, and Sandboxes cover residual risk.
6. Runtime: Dynamic Mounting, Lifecycle, and Dependency Re-Resolution
The hard part of pluginization is not “defining plugins” but “safely composing plugins at runtime.” A mature runtime needs to provide four foundational capabilities:
- Dynamic mounting: load or unload plugins without restarting the process.
- Lifecycle management: define explicit phases such as init, ready, deactivate, and dispose, and guarantee resource release and idempotency.
- Dependency resolution and re-resolution: when a plugin is replaced or removed, recompute the dependency graph and notify affected parties to avoid dangling references.
- Isolation and error boundaries: a single plugin’s failure should not make the whole system unavailable.
Lifecycle pseudocode sketch:
onLoad(ctx) // register services, subscribe to eventsonReady() // initialization after dependencies are readyonDispose() // release handles, cancel subscriptions
The key principle of dependency re-resolution is “explicit declaration, one-way dependencies, nullable implementations.” A plugin should declare what capability it needs rather than look up a specific implementation; the runtime is responsible for injecting the capability provider. That way, replacing one implementation requires no change on the dependent side.
7. From Running It to Taking It Apart: A Recommended Learning Path
Step one, get it running. Prepare several presets, then use the same model and the same input to observe behavior differences under different capability combinations. The goal here is to build intuition: model capability stays constant, while behavior changes come from the harness.
Step two, take it apart. Disable or replace Skills, Tools, and Hooks one by one, record changes in output and side effects, and draw the call sequence and boundary positions to make clear which layer is responsible for what.
Step three, build it yourself. First write a minimal tool, then a minimal hook that validates parameters, and finally a composition that wires them together, filling in the failure paths as well.
8. The Designer’s View: Building and Validating Your Own Harness
Four guidelines are recommended when building:
- Contract first: define the three unified contracts—request, event, and tool description—before implementing plugins.
- Composition over inheritance: acquire capabilities through composition, avoiding the rigidity of deep inheritance.
- Explicit state: sessions and intermediate results must be modeled explicitly; do not rely on implicit global variables.
- Observability on by default: every reasoning step, every tool call, and every interception should produce a structured record for replay and diagnosis.
The verification system should cover at least four layers:
| Layer | Verification Goal | Typical Means |
|---|---|---|
| Plugin unit | Input/output and exception paths | Unit tests, contract tests |
| Composition integration | Plugin collaboration and dependency re-resolution | Scenario integration tests |
| Behavior regression | Stability of the same model under different compositions | Fixed case set replay |
| Security drill | Whether out-of-bounds calls are correctly blocked | Red team cases, sandbox escape attempts |
It is worth stressing that verification is not only about “whether the answer is right,” but also about “whether the process is compliant, whether failures are controllable, and whether resources are released.” This is fundamentally different from testing a traditional monolith.
9. Common Pitfalls and Engineering Advice
- Pitfall one: treating prompts as architecture. A prompt is only one carrier of behavioral constraints and cannot replace state management and permission design.
- Pitfall two: too fine plugin granularity. Excessive granularity makes the dependency graph explode; divide by “capability units that can evolve independently.”
- Pitfall three: ignoring the unload path. Designing only loading and not disposal will inevitably leak resources over long-running operation.
- Pitfall four: treating approval as decoration. Approval must have clear trigger conditions, a timeout policy, and a fallback action.
For implementation, you can start by using a container platform to host the runtime, logging services plus monitoring and alerting to close the observability loop, and object storage or message queues to handle persistence of sessions and events, so that attention stays on plugin contracts and composition strategies themselves.
10. Conclusion
The complexity of agent engineering is essentially composition complexity, not model complexity. With “everything is a plugin” as the organizing principle, together with clear extension tiers, defense-in-depth security boundaries, and a runtime capable of dynamic composition, developers can refactor an uncontrollable script-style implementation into a system that is replaceable, observable, and verifiable. Once you master this method, your agent architecture can keep evolving steadily no matter how the underlying model changes.
