Agent Harness Architecture: Runtime Plugin Graphs and Append-Only Event Streams
A production-grade Agent Harness needs more than a model-and-tool execution loop. This article explains how a runtime plugin graph manages capabilities, dependencies, scopes, and resource cleanup, while an append-only event stream preserves execution history for context, UI views, session recovery, and branching. It also outlines how layered configuration becomes an updateable runtime plugin tree.
1. The Hidden Complexity of Plugin Lifecycles
When building a production-grade AI coding tool—an Agent Harness—the model call itself is often not the main engineering challenge. Much of the work lies in managing how capabilities are organized, replaced, and released. At least four questions need explicit architectural answers:
- Startup when required capabilities are missing: If a plugin depends on a capability that is not yet available, should it defer startup, wait, or fail immediately? This defines the system’s fault-tolerance boundaries.
- Resolving the same service name across scopes: Can a logical service name resolve to different implementations in different sessions or scopes? This matters for multitenancy, session isolation, and hot swapping.
- Resource ownership during shutdown: When a plugin is unloaded, who cleans up its registrations, listeners, subprocesses, and file handles? Unclear ownership is a major source of memory leaks and orphaned processes.
- Turning static configuration into a runtime tree: How does a static declaration become a runtime plugin tree that can be updated and inspected node by node?
Scattering these decisions across application code quickly produces an unmaintainable system. A better approach is to treat the Harness as two systems running together.
2. The Dual-System Model: A Plugin Graph and an Event Stream
The Runtime Plugin Graph: What the System Contains Now
The first system maintains a directed runtime plugin graph. It describes which capabilities are available, what they depend on, where they apply, and how cleanup proceeds when they are unloaded.
Its primary responsibility is managing composition complexity. Models, credentials, tools, prompts, and session services become nodes organized through dependencies rather than hard-coded connections.
Typical registration and resolution logic can be expressed in pseudocode:
register(name, impl, scope):graph.addNode(name, impl, scope)for dep in impl.requires:graph.addEdge(dep, name) # Declare the dependencyresolve(name, scope):# The same service name can resolve to different implementations by scopereturn graph.lookup(name, scope)unmount(name, scope):node = graph.remove(name, scope)node.dispose() # Clean up registrations, listeners, processes, and handles
The key ownership rule is simple: whoever registers a resource is responsible for cleaning it up. Each node runs its own dispose operation when unmounted. This keeps resource ownership local instead of relying on global scans as a cleanup fallback.
The Append-Only Event Stream: What the System Has Done
The second system maintains an append-only event stream. It records each step of an agent’s work and serves as the single source of truth from which three types of data are projected:
- Model context;
- UI execution traces;
- State needed for recovery and branching.
The append-only design provides two direct benefits. First, state at a given point can be reconstructed by replaying the log, supporting session recovery. Second, a new branch can start from a historical point by copying the log prefix, supporting branching experiments.
3. The Agent Loop: Where the Two Systems Meet
The agent execution loop connects the plugin graph and the event stream:
- It reads from the plugin graph to obtain the currently available models, tools, prompts, and session services.
- It writes execution events to the event stream, creating a traceable record of its work.
The architectural division is straightforward: the plugin graph describes what the system contains now; the event stream records what the system has done. Together, they form the foundation of the Harness.
4. Why a Production Harness Needs More Than an Execution Loop
A minimal working loop can assemble a prompt, call a model, execute tools, and return the results to the model. But moving from a working prototype to a production-grade system introduces substantial composition complexity:
- Managing and rotating models and credentials;
- Recovering sessions and compressing context;
- Applying tool policies and obtaining approval before execution;
- Providing sandbox isolation and remote execution;
- Adapting to different host environments;
- Spawning and coordinating subagents;
- Starting and stopping plugins dynamically;
- Presenting multiple UI views of the same execution record.
Putting all of these responsibilities inside the execution loop makes it difficult to test and reuse. Delegating capability composition to the plugin graph and historical continuity to the event stream allows the loop itself to remain lightweight.
5. Startup: From Static Declarations to an Updateable Plugin Tree
Rather than constructing a fixed application at startup, the Harness follows a configuration-driven process:
- Read the base Profile and Bundle to establish the default set of capabilities.
- Apply the user Patch to override or extend those defaults.
- Use the Loader to mount configuration entries as plugin instances, resolving dependencies during mounting.
- Once mounting is complete, the static declarations have become an updateable runtime plugin tree that can be inspected node by node.
This layered approach—defaults, extensions, then user overrides—allows the same core to support different scenarios. It also makes runtime changes observable and reversible.
6. Design Takeaways
Separating the Harness into a plugin graph, event stream, and execution loop is an exercise in separation of concerns: composition, history, and execution each have a clear home.
For teams building recoverable, observable, and extensible AI coding tools, this model offers a practical architectural path. Use the plugin graph to organize capabilities and their lifecycles, use the event stream to preserve continuity, and keep the execution loop focused on running the agent.
