Dual-Layer Architecture of Plugin-Based Agent Execution Frameworks: Runtime Graph and Event Stream
Plugin-based agent execution frameworks are often summarized as "everything is a plugin," but their real engineering value goes beyond plugin count or a uniform entry point. This article explains the dual-layer architecture behind such frameworks: a runtime plugin graph that defines what the system is composed of, and an append-only session event stream that records what the system has done. It also examines how the agent loop bridges those two layers, how the graph handles visibility, dependency readiness, scoped resolution, cleanup, and configuration-to-runtime projection, and why these mechanisms matter for production-grade agent harnesses.
“Everything is a plugin” is often used as a shorthand for a class of agent execution frameworks, but having many plugins with a uniform entry point does not explain the real engineering value. A more precise view is that these frameworks try to converge model adapters, system prompts, tool catalogs, sessions, storage, sandboxing, the agent loop, the Web UI, standard mode, preset tool-calling mode, minimal mode, and creative mode into one composition mechanism. Their defining feature is not the number of packages, but the fact that the runtime kernel handles five problems that are usually separate:
- What capabilities are visible to a plugin at its current location?
- Should a plugin start when a required capability has not yet appeared?
- Can the same service name resolve to different implementations across sessions or scopes?
- Who cleans up registrations, listeners, processes, and handles when a plugin exits?
- How does static configuration become an inspectable, updatable runtime plugin tree?
A useful way to explain this architecture is to view the execution framework as two systems running in parallel: one maintains a runtime plugin graph, and the other maintains an append-only event stream. The graph describes “what the system is made of now”; the event stream records “what the system just did.” The agent loop sits between them: it obtains model, tool, prompt, and session services from the graph, then writes execution back into the event stream. The graph handles composition and dependency; the event stream handles historical continuity and observability. Together they form the backbone of a production-grade execution framework.
The Runtime Plugin Graph: What the System Is Made Of
The runtime plugin graph is not a simple plugin list. It is a capability graph with scope, dependency, and lifecycle constraints. Each plugin node contains at least four kinds of information: the capabilities it provides, the capabilities it depends on, the scope in which it takes effect, and how it releases resources when unloaded. Edges represent dependency and resolution relationships; nodes represent plugin instances that can be mounted, stopped, or replaced.
PluginNode {id: stringscope: Scopeprovides: ServiceKey[]requires: ServiceKey[]setup(context): Disposable}RuntimeGraph {resolve(key, scope): Implementationmount(configLine): PluginNodeunmount(id): void}
The first question this graph must answer is capability visibility. Which services a plugin can see at its current location cannot be decided implicitly by a global singleton. It must be constrained by scope and context. A session-level plugin should see session-level implementations; a host-level plugin should see host-level implementations; a sub-agent should not accidentally access private parent capabilities. Only when visibility is explicit can plugin composition avoid collapsing into implicit global state.
The second question is dependency readiness. After a plugin declares required capabilities, the runtime must not simply assume those dependencies already exist. A safer strategy is to distinguish required dependencies from optional dependencies. If a required dependency is not ready, the plugin can wait in a suspended state, delay startup, or fail according to a policy. If an optional dependency is missing, the plugin should degrade gracefully. This prevents configuration order, asynchronous initialization, and lazy loading from breaking startup stability.
The third question is multi-scope resolution for services with the same name. The same service key may correspond to different implementations in different sessions, hosts, or tenants. The runtime graph must confine service resolution to the scope chain rather than maintaining one global key-value table. Resolution can follow the order: current scope → parent scope → default implementation. This approach supports override, isolation, and test doubles.
The fourth question is unload cleanup responsibility. When a plugin exits, registrations, event listeners, child processes, file handles, timers, and other resources must have a clear owner. A common approach is to let plugin initialization return a disposable object, which the runtime registers and then releases in reverse order during unload. At the same time, plugins should be prevented from holding untracked global resources. Cleanup order should follow dependency order: stop dependents before stopping the dependencies they rely on.
The fifth question is turning static configuration into a runtime tree. On startup, the framework does not directly construct a fixed application. Instead, it reads configuration profiles and capability packages, overlays user patches, and lets the loader mount each configuration line into a plugin instance. A configuration line is not a one-off script; it is a declarative, inspectable, diffable, and updatable statement. The runtime graph therefore becomes a projection of the configuration. It can report which nodes currently exist and can compute additions, removals, changes, and affected scopes when the configuration changes.
The Session Event Stream: What the System Has Done
If the plugin graph solves composition, the session event stream solves history. What actually happened during an agent run should not exist only in memory objects or UI state; it should be written into an append-only event stream. The event stream records model calls, tool executions, approvals, errors, compaction, recovery, and forks, and it projects those facts into model context, UI trace, recovery points, and fork data.
The benefit of an append-only log is that facts are unique, ordering is explicit, and the stream can be replayed. Model context can be derived by projecting the event stream rather than by reverse-engineering history from context. The UI trace can subscribe to the same facts, avoiding drift between interface state and execution state. Recovery and forking can be based on checkpoints built from the event sequence without copying the entire runtime graph. In this way, session continuity is decoupled from plugin composition: the plugin graph can change, while the event stream still preserves history.
Agent Loop: The Bridge Between the Two Layers
The agent loop sits between the plugin graph and the event stream. It does not invent capabilities. Instead, it resolves model, tool, prompt, and session services from the graph, assembles context according to policy, calls the model, executes tools, and appends each step to the event stream.
loop:services = graph.resolve(scope)context = eventLog.project(services.prompt, services.session)decision = services.model.infer(context)result = services.tools.execute(decision, policy, sandbox)eventLog.append(result)
The key point is that the loop only orchestrates. Capabilities come from the plugin graph, and history is written to the event stream. For this reason, a production-grade execution framework cannot be judged only by its minimal loop. A minimal loop needs to build a prompt, call a model, execute tools, and send the result back to the model. A complete product must also handle model and credential management, session recovery and compaction, tool policy and approval, sandbox and remote execution, multiple hosts, sub-agents, plugin startup and shutdown, and a UI that can observe the same runtime facts. Delegating that composition complexity to the runtime plugin graph and delegating historical continuity to the event stream is the core division of this dual-layer architecture.
Engineering Implications
First, pluginization is not about splitting modules into smaller pieces. It is about bringing capability declaration, scope, dependency, lifecycle, and configuration updates into the same runtime graph.
Second, observability is not a UI feature. It is a projection capability built on the event stream. Only when facts are append-only and replayable can recovery, forking, and multi-end observation be reliable.
Third, the agent loop should remain a thin orchestration layer. It should avoid hardcoding model, tool, storage, sandbox, or other policies directly into the loop.
Fourth, the complexity of a production-grade harness lies mostly in composition, isolation, cleanup, and historical continuity, not in a single inference call. Understanding these two main lines will do more for grasping the architectural essence of such execution frameworks than counting plugins.
