Agent Harness Architecture in Practice: Everything Is a Plugin
This article explains the Agent Harness architecture, the execution framework that turns a language model into a system that can actually complete work. It covers why a plugin-based design is the practical choice, how to layer the harness and define minimal plugin contracts, how the main loop keeps an agent running with proper termination conditions, sandbox and execution security, layered memory and session governance, observability and cost control, a phased adoption path, and common pitfalls to avoid.
1. Start With the Definition: An Agent Is a Model Plus an Execution Framework
When teams set out to build an agent, the first question is usually “which model should we use.” Yet what really determines whether an agent can reliably deliver business value is often the entire body of engineering infrastructure around the model. The industry is converging on a simple formula:
Agent = Model + Harness
Here, the Model is the large language model with reasoning and generation capabilities. The Harness (an execution framework, or carrier layer) is everything that turns the model from “able to talk” into “able to do work”: tool integration, task planning, scheduling and orchestration, sandbox isolation, state storage, loop control, session management, and various execution capabilities.
The value of this breakdown is that it converts the vague notion of “agent development” into a clear problem of engineering layering. Model capability has a ceiling and is not fully controllable, while the execution framework is the part developers can design, replace, observe, and govern. Engineering investment should therefore shift from “tuning the model” to “building the framework.”
2. Why “Everything Is a Plugin” Is the Inevitable Choice
The traditional approach hard-codes tool invocation, memory, and planning logic into the main flow. It looks fast in the short term, but over time it becomes a monolith that is hard to maintain. The essence of a plugin-based design is to use a unified contract to separate variable business capabilities from the stable scheduling skeleton.
It brings three direct benefits:
- Replaceable: Models, tools, and storage backends can be swapped per scenario without changing the main loop.
- Composable: New requirements are met by adding plugins rather than continually modifying existing branches.
- Observable: Each plugin has clear input and output boundaries, making instrumentation, rate limiting, replay, and problem localization easier.
To judge whether a capability should be a plugin, apply three criteria: whether it is reused across multiple tasks, whether it changes frequently, and whether it needs to scale or be isolated independently. Meeting any one of them is enough reason to externalize it.
3. Harness Layers and the Plugin Contract
A practical layered structure usually looks like this:
- Access layer: session entry points, identity and quotas, request validation.
- Orchestration layer: the main loop, task planning, step scheduling, termination condition checks.
- Capability layer: tool plugins, retrieval plugins, code execution plugins, external system adapter plugins.
- Runtime layer: sandboxes, container platforms, process and resource isolation.
- State layer: session storage, short-term memory, long-term memory, artifacts in object storage.
- Governance layer: logging services, monitoring and alerting, auditing, and cost accounting.
Keep the plugin contract minimal, specifying only metadata, an execution entry point, and error semantics:
class Plugin:name: strdescription: str # capability description for the model to understandschema: dict # parameter structure, used for validationdef run(self, ctx, **kwargs) -> dict:"""returns {ok, data, error_code, cost}"""
Three points are critical. First, description is written for the model, not for humans, and must state clearly where the capability applies and where it does not. Second, parameters must be strictly validated so that hallucinated arguments from the model never reach the execution layer. Third, errors must be structured so the orchestration layer can decide whether to retry, degrade, or terminate.
4. The Main Loop: Keeping the Agent Working
The main loop typically has six stages: understand the goal, make a plan, select a plugin, execute and validate, adjust based on the result, and decide whether it has converged. In engineering, the hardest problem is usually not generation quality but runaway non-convergence.
Set at least four kinds of termination conditions: maximum number of steps, cumulative time limit, per-task cost limit, and repeated action detection. A sketch:
for step in range(MAX_STEPS):plan = planner.next(ctx)if plan.done or ctx.repeated(plan.action):breakresult = registry.get(plan.tool).run(ctx, **plan.args)ctx.record(result)if ctx.cost_exceeded():return degrade(ctx)
Repeated action detection matters especially: when the model produces the exact same invocation intent twice in a row, the benefit of continuing is minimal while resource consumption grows linearly.
5. Sandboxing and Execution Safety
Any capability that involves code execution, file reads and writes, or command-line operations must run in an isolated environment. The common approach is to use a container platform or ephemeral runtime instances, combined with a read-only root filesystem, a non-privileged account, a network egress allowlist, forced timeouts, and resource quotas. Artifacts should not stay inside the sandbox; write them back to object storage and keep one replayable snapshot of inputs and outputs.
Security design follows least privilege: each plugin receives only the credentials required for the current task, injected by the access layer per session, never written into prompts and never persisted to logs.
6. Memory, Storage, and Session Governance
Memory should be divided into three layers: the current session context, task-level intermediate state, and cross-session long-term knowledge. Keep the first two in low-latency storage, and recall the third on demand through a retrieval plugin to avoid unbounded context growth. The core of context management is not “fit in more” but “filter more precisely,” so retrieval quality, deduplication, and summary compression are more effective than simply expanding capacity.
7. Observability and Cost Control
Every plugin invocation should produce a structured record: caller, parameter summary, latency, error code, and token and resource consumption. Based on logging services and monitoring and alerting, build three dashboards: success rate and error distribution, per-task cost, and human takeover rate. When a plugin’s error rate stays high, fix the contract and validation first rather than repeatedly tuning prompts.
8. A Suggested Adoption Path
In the first phase, build only “model + three plugins + main loop” and get one real business flow working end to end. In the second phase, add the sandbox, state, and observability. In the third phase, introduce a plugin registry, versioned canary rollout, and permission governance. Baidu AI Cloud can serve as a foundation for hosting such an execution framework, with general-purpose infrastructure such as container platforms, object storage, logging services, and monitoring and alerting.
9. Common Pitfalls
- Treating prompts as architecture while ignoring contracts and validation;
- Making plugins too coarse, so internal logic remains unobservable;
- Having no termination conditions, so long tasks keep consuming resources;
- Memory that only grows, so context noise overwhelms useful information;
- Lacking replay capability, so production issues cannot be reproduced.
Conclusion
“Everything is a plugin” is not decoupling for its own sake. It confines the uncertainty of an agent within controllable boundaries: the model can be replaced, capabilities can be plugged in and out, and risks can be isolated and measured. When the execution framework is stable enough, every improvement in model capability can be smoothly translated into business results.
