Plugin-Based Agent Harness Architecture: A Dual-Runtime Model
A production-grade Agent Harness is more than an Agent loop and a collection of plugins. It combines a runtime plugin graph for capability composition, dependency management, scope isolation, and lifecycle cleanup with an append-only session event stream for execution history, recovery, and branching. This article explains how these two systems work together, why the Agent loop should remain a bridging layer, and how to evolve configuration into an inspectable runtime tree.
In intelligent coding tools and Agent platforms, “everything is a plugin” is often interpreted as having many plugins and an entry point for each one. However, architectural maturity is determined not by the number of packages, but by whether the same composition mechanism can handle capability discovery, dependency initialization, scope isolation, lifecycle cleanup, and configuration evolution.
A more useful model is that a production-grade Agent Harness contains two systems running together:
- The runtime plugin graph answers, “What currently makes up the system?”
- The session event stream answers, “What has the system done?”
The Agent loop sits between them. It obtains models, tools, prompts, and session services from the plugin graph, then writes execution activity back to the event stream.
1. Why a Production Harness Cannot Be Reduced to the Agent Loop
A minimal Agent loop only needs to assemble prompts, call a model, execute tools, and send the results back to the model. This is enough to validate an execution path, but not enough to support a production product.
A complete Harness must also handle model and credential management, session recovery and compaction, tool policies and approvals, sandboxing and remote execution, multiple hosts, sub-Agents, plugin activation and deactivation, and the way a user interface observes the same execution facts. If all of this complexity is placed inside the loop, the loop quickly becomes an oversized control module that is difficult to test and evolve.
The value of a plugin-based architecture is that it moves composition complexity into the runtime container. Model adapters, system prompts, tool catalogs, sessions, storage, sandboxes, the Agent loop, web interfaces, and operating modes such as standard, minimal, and creative can all be composed through a consistent plugin mechanism.
The Agent loop can then focus on execution orchestration, while historical continuity is handled by the event stream and capability composition is handled by the plugin graph.
2. The Runtime Plugin Graph: Five Problems That Must Be Solved Together
A mature plugin runtime is not merely a registry with a call mechanism. It must address five related concerns.
Capability Visibility
The capabilities visible to a plugin depend on its scope chain and declared dependencies. If capability resolution is globally flattened, tests, multi-tenant environments, and sub-Agents can easily contaminate one another.
A more reliable approach is to let plugins declare required and optional capabilities, while the container resolves them according to scope.
Dependency-Ready Startup
What should happen when a required capability is not available? Should the plugin block, fail, or start later? Can it degrade gracefully when an optional capability is missing?
These decisions belong to the container, which should maintain dependency state instead of forcing each plugin to guess during initialization.
Scoped Resolution of Same-Named Capabilities
The same capability name may resolve to different implementations in different request, session, or tenant scopes. The resolution order must be explicit. For example:
Request scope overrides session scope, session scope overrides tenant scope, and tenant scope overrides the global default.
Unloading and Cleanup
When a plugin exits, who cleans up its registrations, listeners, processes, and handles?
The runtime should define ownership and disposer protocols. Cleanup should happen in reverse order and be idempotent. This helps prevent leftover listeners and orphaned processes after hot replacement.
Converting Static Configuration into a Runtime Tree
Each configuration entry should be mounted by a loader as a plugin instance, producing a runtime plugin tree that can be enumerated, validated, and updated.
Configuration is not merely a set of startup parameters. It is a declaration of what the system consists of.
Interface sketch:provide(capabilityName, factoryFunction, scope) -> disposerrequire(capabilityName) -> instance or missing-capability erroronDispose(cleanupFunction) -> register reverse-order cleanup
3. The Session Event Stream: An Append-Only Fact Log
The session event stream records what actually happened during an Agent run, including user input, model responses, tool calls, approval results, errors, and recovery points.
It should use an append-only design rather than overwriting history. Projectors can then generate the data needed for model context, interface timelines, recovery, and branching.
The event stream should remain decoupled from the plugin graph:
- The plugin graph describes the system’s current composition.
- The event stream describes historical facts.
From an engineering perspective, it is important to distinguish fact events from projection results. Fact events should use stable schemas and version numbers. Context compaction, interface rendering, and metrics are projections that can evolve independently.
During recovery or branching, the system can replay events after a checkpoint instead of treating UI state as the sole source of truth.
{"type":"tool_call","session":"s1","step":3,"tool":"search","status":"requested"}{"type":"tool_result","session":"s1","step":3,"status":"ok"}
4. The Agent Loop as a Bridging Layer
The Agent loop obtains models, tools, prompts, and session services from the plugin graph. It then executes a sequence such as:
- Read the current context projection.
- Call the model.
- Parse tool requests.
- Apply approval and policy checks.
- Invoke tools.
- Write execution facts to the event stream.
- Decide whether to continue or finish.
The loop should not own capability registration or historical storage. Its role is to coordinate the two runtime systems.
A sub-Agent can be treated as an execution unit with an independent scope. Its capability resolution and event records should remain traceable and isolated.
5. From Configuration to Runtime Graph: The Startup Path
At startup, the system should not directly construct a fixed application. It should first load a Profile and its Bundles, apply user patches, and then mount each configuration entry through the loader.
The loading process includes:
- Parsing configuration.
- Instantiating plugins.
- Registering capabilities.
- Resolving dependencies.
- Establishing scopes.
- Recording disposers.
- Validating the runtime tree.
When configuration changes, the runtime should first calculate the difference, then mount and unload components in dependency order, and finally check for leftover registrations.
profile: defaultbundles: [model-adapter, tool-catalog, session-store]patches:- scope: sessionplugin: tool-policyconfig: {approval: required}
6. Engineering Recommendations
- Design scopes first. Define the global, tenant, session, and request scopes and their resolution order before implementing capability registration.
- Make dependencies explicit. Declare required and optional capabilities separately, and provide diagnosable errors when required capabilities are missing.
- Standardize cleanup. Every registration, listener, process, and handle must be associated with a disposer. Test for leftovers after hot replacement.
- Version event schemas. Keep fact events stable while allowing projectors to change. Compaction and checkpoints should support replay.
- Build in observability. The plugin tree, dependency states, scope resolution results, and event projection latency should all be queryable.
- Avoid excessive pluginization. High-frequency, stable, and tightly cohesive logic can remain in core modules. Pluginization should serve composition and isolation rather than become an end in itself.
The defining characteristic of a plugin-based Agent Harness is not that it contains many packages. It is the cooperation between two runtime systems: the plugin graph manages capability composition and lifecycle, while the event stream manages historical continuity and recoverability. The Agent loop serves as the bridge and orchestration layer.
This model turns “everything is a plugin” from a marketing phrase into an architecture that can be inspected, tested, and evolved.
