Agent Harness Architecture for Open-Source AI Agents: Design and Implementation
This article breaks down what an Agent Harness is and why model capability alone does not make an AI agent. It explains a plugin-based architecture that turns the agent into a reconfigurable tree, then covers layered sandboxing and permissions, fault tolerance for long-running sessions, observability and governance, and a practical implementation checklist for building an auditable agent runtime on cloud infrastructure.
1. Why Model Capability Is Not Agent Capability
When discussing next-generation agent infrastructure, the most common misconception is treating the model as the agent itself. In reality, a model does very little on its own: it takes a piece of context and outputs the next chunk of text or a single tool-call intent. It does not know the current working directory, does not know which branches exist in a repository, and has no inherent ability to read or write files, execute commands, query databases, or drive a browser. There is an entire execution system between a model saying “I want to read this file” and the file actually being read reliably.
Four boundaries need to be made explicit:
- The model is not the agent. It is only responsible for deciding the next step.
- A tool protocol is not the agent. Standardized protocols solve how tools, resources, and prompts are exposed uniformly, but they do not provide the task loop, session recovery, context compression, permission decisions, or execution state management.
- An application framework is not the same as a runtime. Frameworks focused on workflow orchestration care about how nodes connect, whereas a runtime must actually handle model requests, tool dispatch, process execution, log persistence, user approval, and the interaction interface.
- The runtime is where the agent is truly “alive.” The system surrounding the model is commonly called an Agent Harness.
In one sentence: the model makes decisions, and the Harness makes those decisions land safely, reliably, and traceably.
2. Plugin Architecture: Turning the Agent into a Recombinable Tree
A recently open-sourced agent runtime offers a representative approach: everything is a plugin, driven at the bottom by a dependency-injection plugin kernel. Instead of writing the agent as a closed program, it breaks the model adapter, task loop, tool registry, session log, sandbox, approval, context compression, sub-agents, and even the graphical interface into plugins.
This design brings three direct benefits:
- Reconfigurable at startup. A configuration file decides which plugins are assembled and in what order, so the same kernel can become a CLI tool, a server-side agent, or a workbench with a UI.
- Replaceable at runtime. Swapping the model adapter, switching the logging backend, or adjusting the compression strategy requires no changes to the main loop code.
- Explicit dependencies. Plugins are connected through declarative dependencies, so missing dependencies surface at startup rather than crashing halfway through a run.
An illustrative assembly configuration looks like this (it expresses structure only and does not represent any specific product interface):
plugins:- id: model-adapteroptions: { provider: local, timeout_ms: 30000 }- id: agent-loopdepends_on: [model-adapter, tool-registry]options: { max_steps: 40 }- id: tool-registryoptions: { allow: [fs.read, fs.write, shell.exec] }- id: approvaloptions: { mode: manual, risky_commands: [rm, git push] }- id: session-logoptions: { sink: object_storage, rotate_mb: 100 }
It is worth stressing that a “complete architecture” does not mean a “stable interface.” Preview-stage implementations often introduce breaking changes, and plugin contracts, configuration fields, and event names may all shift. The correct engineering practice is to pin versions, lock dependencies, bring plugin contracts into automated tests, and reserve a regression window for upgrades.
3. Sandboxing and Permissions: Default Distrust Is the Only Starting Point
Plugin architecture increases flexibility and also enlarges the attack surface. Dynamically loaded third-party plugins are not a strong security boundary; once introduced, they get the same privileges as the main program. Isolation therefore has to be designed in layers rather than relying on a single switch.
- Command execution layer: dangerous commands are denied by default, using an allowlist rather than a denylist; recursive deletion, force push, and bulk history rewrites require explicit confirmation.
- File system layer: anything outside the working directory is invisible by default, writes are limited to the project root, and sensitive paths (credential directories, system configuration) are blocked separately.
- Network layer: outbound traffic is restricted by default, allowing only necessary dependency sources and model service addresses, so plugins or tools cannot exfiltrate data.
- Credential layer: tokens are obtained through environment injection or an external credential service, never written into session logs, and never placed into context, so the model cannot “read them into” the conversation history.
- Persistence layer: sessions and artifacts are written to a controlled directory or object storage, recoverable after the container is rebuilt, while avoiding cross-contamination between different tasks.
A minimal policy expression could be:
{"sandbox": { "mode": "container", "network": "deny-all" },"fs": { "read": ["./src", "./docs"], "write": ["./src"] },"exec": { "allow": ["git status", "git diff", "npm test"], "confirm": ["git push"] },"secrets": { "source": "env", "redact_in_logs": true }}
4. Stability: Don’t Let One Failure Take Down the Whole Session
In production, the most destructive problem is often not a wrong answer from the model but the system falling over. A failed tool call, a process timeout, or an oversized context can each make the entire session unusable if handled poorly. A reliable runtime needs four capabilities:
- Failure isolation. A single tool exception is caught and returned to the model as a structured error, letting the model decide whether to retry, take another path, or ask for help, instead of throwing an uncaught exception that terminates the loop.
- Step and budget control. Cap the maximum number of iterations, per-step timeout, total token budget, and total elapsed time to prevent infinite loops and runaway cost.
- Context compression. When history approaches the window limit, summarize and archive earlier content while keeping key decisions and file change records, avoiding “amnesiac” repeated work.
- Interrupt recovery. Persist task state, actions already executed, and an artifact index so the process can resume from the latest checkpoint after a restart instead of starting from zero.
Pseudocode can summarize the fault-tolerance skeleton of the main loop:
for step in range(cfg.max_steps):resp = model.next(context) # the model proposes the next intentif resp.is_final: return resp.answertry:result = tools.call(resp.tool, resp.args, timeout=cfg.step_timeout)except ToolError as e:result = {"error": str(e)} # feed the failure back as an observable resultcontext.append(resp, result)if context.tokens > cfg.limit:context = compressor.summarize(context) # compress instead of droppingstate.checkpoint(context) # enables interrupt recovery
5. Observability and Governance: Make Every Step Questionable
Once agents reach production, auditing is unavoidable. Session logs should record a summary of model requests, tool call arguments and result status, approval records, and artifact paths, with retrieval by task ID. Logs are best sent to a general-purpose logging service and object storage, with monitoring and alerting thresholds set for error rate, average step count, and timeout ratio. The approval stage should distinguish automatically permitted actions from those requiring human confirmation, and all high-risk operations should leave a trail for later review and accountability.
6. Implementation Checklist
- Pin the runtime version, lock plugin sources, and introduce only trusted or in-house plugins.
- Choose a stronger isolation sandbox mode, deny network access by default, and keep credentials off disk and out of context.
- Allowlist dangerous commands, feed failures back, cap timeouts, and make state checkpoint-recoverable.
- Store session logs centrally with monitoring and alerting, and require approval with an audit trail for high-risk actions.
- Bring plugin contracts, permission policies, and recovery flows into continuous integration, and run regression before upgrading.
To build an enterprise-grade agent foundation, you can run the runtime on a container platform, store session artifacts in object storage, and close the observability loop with a logging service plus monitoring and alerting, forming an autonomous, auditable, and evolvable agent execution system on top of general cloud infrastructure.
