Agent Harness Architecture Principles and Plugin-Based Design
This article explains why an agent harness is needed between a language model and task execution, and how to organize it around a plugin model. It covers the core "everything is a plugin" principle, preset capability combinations for controlled comparison, the boundaries between Skills, Tools, and Hooks, the layered safety design of Guard, Approval, and Sandbox, and the runtime concerns of dependency resolution, lifecycle management, dynamic mounting, and hot updates. It also outlines a build-and-validation path and common pitfalls, showing how to turn an agent from a demo into a software system that can evolve sustainably.
1. The Starting Point: 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 does not read files on its own, does not call external APIs on its own, and does not retry on its own after a task fails. A deliverable agent, by contrast, has to complete a task: understand the goal, break it into steps, select tools, execute actions, observe results, correct deviations, and keep going until the output is acceptable.
The gap between these two is exactly why a harness (the runtime or carrying layer) exists. The relationship can be understood as:
Task goal → [Harness orchestration layer] → Model inference (token generation)↑ |└──── tool results/observations ────┘
The harness takes on four responsibilities: context assembly, action execution, state persistence, and loop control. If these four capabilities are stacked into the main flow as hardcoded special cases, the system quickly degrades into a giant set of condition branches that is hard to modify. The core value of a plugin-based organization is to separate “variable capabilities” from the “stable loop skeleton.”
2. Core Design Principle: Everything Is a Plugin
“Everything is a plugin” is not modularization for its own sake, but a binding design rule: except for the loop skeleton and the plugin loading mechanism, no capability may be embedded as a special case.
Under this principle, the units that are typically split into pluggable pieces include:
- Model adaptation: models differ in API protocols, context length, structured output support, and token accounting, so the adaptation layer provides a unified abstraction.
- Tool registration: declares externally executable capabilities (retrieval, computation, code execution, data queries) as actions the model can understand.
- Session records: handles persistence and replay of messages, actions, and observations, and is the basis for debugging and evaluating results.
- Loop control: decides when to keep reasoning, when to converge, and when to abort.
The direct benefit of this split is that capability combinations can be swapped like configuration, without changing the main loop.
3. Start from Preset Combinations: Observe Capability Differences with the Same Model
The step most often overlooked in engineering practice is establishing a comparable experimental baseline first. One effective approach is to prepare several preset combinations, keep the model unchanged, and vary only the capability set to observe behavioral differences:
| Preset | Capability configuration | What to observe |
|---|---|---|
| Minimal | Model adaptation + loop only | Text output only, no actions produced |
| Tool-enabled | Adds tool registration | Action selection appears, but error correction may be missing |
| Controlled | Adds approval and sandbox boundaries | High-risk actions are blocked or escalated to a human |
| Full | Adds records, hooks, and policies | Replayable, evaluable, auditable |
The point of the comparison is that it turns the vague feeling that “agents are unstable” into a locatable conclusion about which layer of missing capability causes which kind of failure.
4. Three Extension Layers: Where Skill, Tool, and Hook Belong
If extension capabilities are not layered, overlapping responsibilities and conflicts appear quickly. A reasonably clear split is:
- Skill: knowledge and process encapsulation for “how to do it,” usually instructional content the model can read, shaping strategy and step preferences.
- Tool: an execution interface for “what can be done,” with a clear input/output contract and a defined scope of side effects.
- Hook: cross-cutting logic for “what to do at which moment,” such as rewriting before a request, validating after a result, or providing a fallback on errors.
Illustrative definitions (pseudocode):
@tool(name="query_metric", description="Query a metric over a given time window")def query_metric(window: str, key: str) -> dict:return metric_backend.fetch(window, key)@hook(event="before_action")def guard(ctx):if ctx.action.risk == "high" and not ctx.approval:raise Denied("Explicit authorization required")
A practical test for which layer a capability belongs to: if the model must decide the content autonomously, lean toward Skill; if there is a definite contract and side effects, make it a Tool; if it is independent of any specific action but must be enforced uniformly, make it a Hook.
5. Safe Execution Boundaries: Guard, Approval, Sandbox
Once an agent has real side effects, safety design must come first. The three boundaries cannot replace one another:
- Guard (policy enforcement): evaluates rules before an action executes, handling deterministic constraints such as allowlists, parameter ranges, and rate limits.
- Approval (human review): adds a confirmation step for irreversible or high-impact actions, following “deny by default, allow explicitly.”
- Sandbox (isolation): limits the resources the execution environment can reach, such as filesystem scope, network egress, available compute, and lifetime.
The correct relationship among the three is progressive narrowing: Guard filters quickly, Approval handles the gray zone that needs human judgment, and Sandbox ensures the damage stays contained even if the first two layers fail. A system missing any one of them is hard to run stably in a real environment.
6. Runtime Mechanics: Dynamic Mounting, Lifecycle, and Dependency Re-resolution
Once all capabilities are plugins, the real difficulty moves to the runtime. A usable plugin runtime usually has to solve four things:
- Dependency declaration and resolution: plugins declare the capabilities they need rather than concrete implementations, and the runtime matches against the declarations to avoid hard binding.
- Lifecycle management: define the order of initialization, readiness, suspension, and unloading, plus failure rollback, so resources do not leak.
- Dynamic mounting and unloading: support adding and removing capabilities at runtime without breaking the continuity of the loop skeleton.
- Hot updates and state migration: when updating a plugin, decide how session state is preserved, migrated, or rebuilt.
The lifecycle can be abstracted as:
Resolve dependencies → Initialize → Mount → Ready (join the loop) → Unload → Release resources
The most worthwhile engineering investment is in failure paths: a failed initialization must roll back as a whole, unloading must be idempotent, and hot updates must let old sessions finish on the old version, so switching midway does not corrupt state.
7. The Builder’s View: How to Build and Validate Your Own Harness
When building from scratch, follow the order “converge the skeleton first, then extend capabilities”:
- Step 1, fix the loop skeleton: define three interfaces for context assembly, action dispatch, and termination conditions, without introducing any concrete capability.
- Step 2, define the plugin contract: metadata, dependency declarations, lifecycle hooks, and error semantics.
- Step 3, establish observability: fully record prompt versions, action inputs, execution time, and result status; general-purpose logging and monitoring/alerting are sufficient.
- Step 4, build an evaluation set: use a repeatable task set to measure success rate, average number of steps, and blocked-overreach rate across capability combinations.
- Step 5, open up permissions gradually: run under sandbox and approval constraints first, then widen the scope of automatic execution once stable.
Suggested key validation metrics: task success rate, average interaction steps, tool call failure rate, policy interception accuracy, and state consistency after hot updates. Without an evaluation set, any architecture change in a harness can only be judged subjectively.
8. Common Pitfalls
- Treating plugins as “directory splitting” while dependencies remain hardcoded, so capabilities cannot be swapped dynamically.
- Designing only for the success path and ignoring rollback and idempotency, which makes runtime problems hard to converge.
- Treating approval as the whole of safety, with no sandbox as a fallback.
- Storing only the final output in session records instead of intermediate actions, making post-hoc review impossible.
Conclusion
The complexity of agent engineering comes not mainly from the model but from how capabilities are organized. With “everything is a plugin” as the constraint, model adaptation, tools, records, and the loop are decoupled; the runtime takes on dependency resolution and lifecycle management; and Guard, Approval, and Sandbox form defense in depth. That is what lets an agent move from a demo to a software system that can evolve sustainably.
