Plugin-Based Agent Harness Architecture: Runtime Plugin Graph and Append-Only Event Stream
This article breaks down the core design principles of a plugin-based Agent Harness from a neutral perspective. It explains the dual-system model of a runtime plugin graph and an append-only event stream, how configuration is assembled into a runtime plugin tree, and the five problems a unified plugin mechanism must solve, including visibility, dependency readiness, scope resolution, lifecycle cleanup, and configuration as a runtime graph. Readers will learn how this architecture enables swapping models, tools, prompts, and storage without code changes while supporting session recovery, branching, approvals, and multi-host environments.
1. Background: Why an Agent Harness Needs to Be Composable
When building a production-grade agent runtime (Harness), teams often run into a familiar trap. A minimal viable version is easy to build: stitch together prompts, call the model, execute tools, and feed results back to the model. A few dozen lines of code are enough to get it running. But once the project moves into a real product, complexity shifts quickly to composition: how to switch models and credentials, how to restore and compress sessions, how to enforce tool policies and approvals, how to isolate sandboxes and remote execution, how to adapt to multiple host environments, how to spawn sub-agents, how to hot-swap plugins, and how to let the UI observe the same runtime facts.
If all of these capabilities are hardcoded into a monolithic application, replacing any single capability triggers widespread changes. As a result, the industry has gradually adopted an “everything is a plugin” approach: model adapters, system prompts, tool registries, sessions, storage, sandboxes, the execution loop, the web UI, and even different interaction modes are all abstracted into composable units and assembled at runtime by a unified mechanism. This article analyzes the general design principles of such architectures from a neutral perspective and does not cover any specific product implementation.
2. Dual-System Model: Runtime Plugin Graph + Append-Only Event Stream
A mature plugin-based Harness is essentially two systems running at the same time:
- Runtime plugin graph: describes “what the system is made of right now.” It records which capabilities (services) are currently available, the dependencies between them, the scopes in which they take effect, and who cleans up registrations and resources on unload.
- Append-only event stream: describes “what the system just did.” It records the events that actually occurred during an agent run in an append-only manner, and projects the data needed for model context, UI traces, and recovery and branching.
The two are connected by the agent loop: the loop obtains the model, tools, prompts, and session services from the plugin graph and writes each step’s execution result back to the event stream. The plugin graph solves “composition,” while the event stream solves “continuity.” Only when both lines come together do they form the body of the Harness.
This separation brings a direct benefit: when swapping a model or tool, only the assembly result of the plugin graph changes, and the historical event stream does not need to be rewritten; when performing session recovery or branching, you only need to replay the event stream rather than rebuild the plugin graph.
3. From Static Configuration to a Runtime Plugin Tree
At startup, a Harness does not directly construct a fixed application. Instead, it goes through a “configuration to runtime graph” process:
- Read the base configuration (Profile) and capability bundles (Bundle);
- Layer user patches (Patch) on top for overrides and customization;
- The loader (Loader) mounts configuration entries one by one as plugin instances, forming an updatable and inspectable runtime plugin tree.
Illustrative configuration (neutral pseudocode):
profile: defaultbundle:- core-session- model-adapter- tool-registrypatch:model-adapter:provider: local-llm # Replace only the capability implementation, not the caller codetool-registry:allow: [read_file, run_shell]
The key point is: replacing a capability relies on changing configuration, not code. The caller only declares “I need a model service,” and which adapter actually provides it is decided by the configuration tree.
4. Five Problems a Plugin Mechanism Must Solve at Once
“Having many plugins” is not enough to explain this kind of architecture. What makes it distinctive is that a unified mechanism handles five problems that are usually separate from each other:
- Visibility: which capabilities a plugin can see at its current location. Through scope restriction, a plugin can only access authorized services, avoiding global namespace pollution.
- Dependency readiness: whether a plugin should start when a required capability has not yet appeared. A common approach is to declare dependencies and, if they are not satisfied, stay pending and activate once the dependency is registered, rather than failing outright.
- Scope resolution: whether services with the same name can resolve to different implementations in different sessions or scopes. For example, different sessions using different models or different storage backends need scope-based resolution rather than a global singleton.
- Lifecycle cleanup: who reclaims registrations, listeners, child processes, and file handles when a plugin exits. Unloading a plugin should trigger its registered deregistration and resource release to avoid handle leaks.
- Configuration as a runtime graph: how static configuration becomes an updatable and inspectable runtime tree. At runtime you can query the current assembly state and hot-update some nodes.
Illustrative plugin declaration (neutral pseudocode):
export const inject = { required: ['model'], optional: ['logger'] };export function apply(ctx) {const model = ctx.model; // Visibility + dependency readinessctx.tool.register('read_file', ...); // Registrations are bound to the current scopereturn () => ctx.tool.unregister('read_file'); // Clean up on unload}
5. Session Event Stream: History Continuity and Recoverability
The event stream is usually written in an append-only manner, with each event carrying a type and a payload, such as user input, model request, tool call, tool result, error, and so on. Its value lies in:
- Context projection: projecting the message sequence sent to the model from the event stream, making compression and trimming easier;
- UI trace: the UI subscribes to the same events and displays content consistent with runtime facts;
- Recovery and branching: replaying from a certain event restores the session or creates a branch;
- Audit and replay: when locating issues, you can review the sequence of events in order.
Illustrative events (neutral pseudocode):
{"type":"user_input","payload":{"text":"..."}}{"type":"model_request","payload":{"messages_ref":"ctx-1"}}{"type":"tool_call","payload":{"name":"run_shell","args":{}}}{"type":"tool_result","payload":{"ok":true,"output_ref":"blob-9"}}
6. Engineering Practices and Best Practices
- Explicit dependencies: plugins obtain capabilities by declaring dependencies rather than through implicit global access, reducing coupling.
- Scope isolation: layering at session, task, and global levels, with same-named services resolved by scope.
- Cleanup loop closure: registration is bound to deregistration, and processes and handles are released when a plugin is unloaded.
- Inspectable configuration: the runtime can query the plugin tree state, which helps with troubleshooting and canary rollouts.
- Separation of events and graph: capability replacement does not touch history, and history replay does not rebuild the graph.
- Progressive enhancement: when an optional dependency is missing, degrade rather than crash to ensure availability.
7. Conclusion
The core of a plugin-based Harness is not “having many packages,” but using a unified mechanism to answer both “what the system is made of” and “what the system has done” at the same time. Understanding the division of labor between the runtime plugin graph and the append-only event stream, as well as the assembly process from the configuration tree to the runtime graph, makes it possible to replace models, tools, prompts, and storage without changing code, while supporting enterprise-level needs such as recovery, branching, approvals, and multi-host environments.
