AI Agent Harness Architecture: A Plugin-Based Runtime Design
This article breaks down a plugin-based AI agent harness architecture built on two parallel systems: a runtime plugin graph and an append-only event stream. It explains how layered configuration becomes an inspectable runtime plugin tree, how dependency resolution and scope isolation handle missing capabilities and per-session implementations, how lifecycle management reclaims resources, and how context projection, tool policies, sandboxing, and multi-host support fit together. Engineers will find practical guidance on implementation order and acceptance criteria.
1. Why a Minimal Agent Loop Cannot Support a Product
A minimal working agent loop usually has only four steps: assemble the prompt, call the model, execute tools, and feed tool results back to the model. That loop is enough for a demo, but not for a product. A real product must handle model and credential management, session recovery and context compression, tool policies and approvals, sandboxing and remote execution, multiple host environments, sub-agent orchestration, dynamic plugin startup and shutdown, and a UI layer that observes the same runtime facts.
These requirements are tightly coupled. If they are all packed into a single monolithic loop, the code quickly degrades into a collection of hard-to-test conditional branches. A common industry approach is to introduce a plugin-based harness: capabilities are split into composable units and assembled by a unified runtime. However, “having many plugins” is not what makes an architecture distinctive. What matters is whether the runtime systematically solves the following five problems, which are usually handled separately:
- Which capabilities a plugin can see at its current position;
- Whether a plugin should start when a required capability is not yet available;
- Whether services with the same name can resolve to different implementations across sessions or scopes;
- Who cleans up registrations, listeners, child processes, and file handles when a plugin exits;
- How static configuration becomes a runtime plugin tree that can be updated and inspected.
2. The Dual-System Model: Runtime Plugin Graph + Append-Only Event Stream
A more accurate way to understand this kind of harness is to view it as two systems running at the same time.
The first is the runtime plugin graph, which describes “what the system is made of right now”: which capabilities exist, what they depend on, which scope they apply to, and how they are cleaned up on unload. The second is the append-only event stream, which describes “what the system just did”: what actually happened during a task, and the data from which model context, UI traces, and recovery and forking are projected.
The agent loop sits between the two: it obtains the model, tools, prompts, and session services from the plugin graph, then writes the execution process back to the event stream. This distinction is the pivot of the entire architecture and the starting point for all the mechanisms described below.
3. From Static Configuration to a Runtime Plugin Tree
Startup should not directly construct a fixed application object. Instead, configuration is layered in three tiers: a base Profile, reusable Bundles, and user Patches. The loader reads the configuration line by line and mounts each line as a plugin instance, forming a runtime tree that can be traversed and inspected.
An illustrative configuration (neutral pseudocode):
# Base capability layer- plugin: model-adapteroptions: { provider: local, timeout_ms: 30000 }- plugin: tool-registry- plugin: session-store# Composition layer: pull in a set of preset capabilities- bundle: standard-mode- bundle: sandbox-exec# User patch layer: override or append- plugin: approval-policyoptions: { require_confirm_for: [fs_write, shell] }
This layering brings three direct benefits: configurations are reviewable, capabilities are replaceable, and behavior can be rolled out gradually. A user patch can override the implementation of a service with the same name without modifying the base layer.
4. Dependency Resolution and Scope Isolation
Plugins declare the capabilities they require, and the runtime uses the dependency graph to determine startup order. When a required capability is missing, the plugin enters a waiting state instead of crashing, and automatically proceeds once the capability appears; when the capability disappears, it can optionally be suspended or exit. This answers the question of whether a plugin should start when a required capability is not yet available.
Services with the same name can resolve to different implementations across sessions or scopes—for example, different sessions bound to different credentials, different tool allowlists, or different sandbox backends. Illustrative code:
// A plugin declares dependencies, injected by the runtimeexport const apply = (ctx) => {const model = ctx.get('model'); // resolved within the scopeconst tools = ctx.get('toolRegistry');ctx.on('session/event', (e) => log(e)); // listeners are reclaimed with the scopereturn () => ctx.off('session/event'); // explicit cleanup};
Scope isolation allows sub-agents, parallel sessions, and multi-tenant scenarios to share the same plugin code while having mutually invisible capability views.
5. Lifecycle and Resource Reclamation
When a plugin exits, registrations, listeners, child processes, and handles must be reclaimed uniformly by the runtime; otherwise, long-running services will suffer from handle leaks and zombie processes. Three engineering constraints can be applied: all registrations return a cancel function; child scopes are recursively cleaned up when a scope is destroyed; and external resources are registered as leases and released collectively by the runtime in exit hooks. An inspectable plugin tree lets operations answer “who is currently occupying which port or process.”
6. Event Stream, Context Projection, and Recovery/Forking
The event stream is append-only and records facts such as user input, model output, tool calls and results, and policy approvals. The model context is not directly modified text, but a projection of the event stream: it is trimmed and compressed against a window budget to produce the message sequence needed for the current request. Recovery means replaying the projection from the event stream; forking means copying a new stream from a given event to compare the effects of different policies. The UI layer subscribes to the same event stream, so the runtime facts it sees are consistent with what the model sees.
7. Tool Policies, Sandboxing, and Multi-Host Support
The tool catalog is registered as a plugin, and the approval policy is a separate plugin that can insert a confirmation step before high-risk actions such as writing files or executing commands. On the execution side, a sandbox plugin isolates the file system and network, and remote execution is integrated as an adapter without changing the upper-level loop. Multiple hosts (CLI, desktop, cloud container platforms) share the same plugin graph and event stream, replacing only the host adapter layer. If persistence is needed, it can integrate with common cloud capability categories such as object storage, logging services, and monitoring and alerting to enable session archiving and observability.
8. Implementation Recommendations
For implementation, it is recommended to first solidify the event stream format and projection rules, then implement a minimal plugin graph with dependency resolution, and finally gradually add approvals, sandboxing, and UI subscriptions. Acceptance should focus on four points: whether the system waits gracefully when a capability is missing, whether resources return to zero after a scope is destroyed, whether the same event stream can drive both the model and the UI, and whether configuration patches can take effect without restarting the core. Note that the interfaces of such an architecture are not stable in the early preview stage, and production selection should be based on your own testing conclusions.
