Plugin-Based Agent Architecture: Runtime Plugin Graph and Append-Only Event Stream
This article breaks down a plugin-based architecture for production-grade AI agents. It explains why a minimal agent loop is not enough, how a runtime plugin graph manages system composition, and how an append-only event stream manages execution history. You will also find the four key mechanisms behind dependency handling, scoped service resolution, resource cleanup, and configuration-to-runtime mapping, along with startup flow, context projection, and engineering best practices.
1. Background: Why a Minimal Runnable Loop Is Not a Production-Grade Agent
A working agent loop needs only four steps: assemble the prompt, call the model, parse tool calls from the model output, and feed tool results back to the model to continue reasoning. These four steps are enough for demos and prototype validation. Once the system enters a real business scenario, however, complexity quickly shifts from the loop itself to everything around the loop.
The surrounding problems include at least the following: how models and credentials are managed and rotated; how long conversations are compressed and restored; whether tool calls require approval and policy checks; where code and commands run and how they are isolated; how the same core can be embedded in a CLI, a desktop app, and a web interface at the same time; how sub-agents are spawned and reclaimed; how plugins are started and stopped on demand; and how the interface observes the same runtime facts without creating a second source of truth.
If all this complexity is pushed into the loop body, the code quickly degrades into a huge set of conditional branches. A more reasonable approach is to abstract the complexity into two orthogonal concerns: one answers “what capabilities make up the system right now,” and the other answers “what the system actually did a moment ago.” The former is best expressed as a runtime plugin graph, and the latter as an append-only event stream, with the agent loop acting only as the executor between them.
2. Dual-System Overview: Runtime Plugin Graph and Append-Only Event Stream
A production-grade agent framework of this kind can be understood as two systems running at the same time.
The first is the runtime plugin graph. It maintains which capabilities are currently available, what each capability depends on, in which scope it takes effect, and who is responsible for cleanup when it is unloaded. It describes the real runtime projection of the system’s static composition.
The second is the append-only event stream. It records, in append-only fashion, the facts that actually occurred during a task run: user input, model requests and responses, tool calls and results, approval decisions, errors, and retries. Model context, UI traces, checkpoint recovery, and branch replay are all projected from this log rather than maintained as separate copies.
The agent loop sits between the two: it obtains the model, tools, prompts, and session services from the plugin graph, and writes the result of each step back to the event stream. In one sentence: the plugin graph answers what the system is composed of now, the event stream answers what the system just did, and only the two lines together form the whole.
3. Capability Composition: Plugin Boundaries Go Beyond Tools
A common misunderstanding is to equate plugin-based design with “having many tools.” Tool plugins are only the most surface-level layer. In this kind of architecture, model adapters, system prompts, tool catalogs, session management, storage backends, sandboxes, the agent loop itself, the UI layer, and even standard mode, structured output mode, minimal mode, and custom mode are all composed through the same assembly mechanism.
Unified assembly brings replaceability and composability: switching model providers requires only replacing the adapter plugin; changing output constraints requires only replacing the mode plugin; moving the execution environment from a local process to a remote container requires only replacing the sandbox plugin, while the loop code stays unchanged. Whether a framework is truly plugin-based is not measured by the number of packages, nor by whether every module exposes an initialization hook, but by whether it can describe all of the above layers with one mechanism.
4. Four Key Mechanisms
The truly distinctive capability is handling four problems that are usually kept separate.
4.1 Startup Strategy When Dependencies Are Not Met
When a required capability is not yet present, should the plugin wait, fail, or degrade? Mature implementations distinguish required dependencies from optional ones: when a required dependency is missing, the plugin enters a waiting state and starts once the dependency is ready; when an optional dependency is missing, it runs with reduced capability. This avoids hard-coding startup order.
4.2 Scoped Resolution of Same-Named Services
The same service name may resolve to different implementations in different sessions or scopes. For example, the main session uses default storage, while an isolated session uses separate storage and a separate sandbox. Service lookup should not be a global singleton table lookup; it should follow scope visibility rules.
4.3 Resource Reclamation on Unload
When a plugin exits, who cleans up the entries it registered, event listeners, child processes, and file handles? If the caller is relied on to reclaim them manually, long-running systems will inevitably leak. A workable approach is to create a scope context for each plugin, register on registration, and release everything in reverse order on disposal.
4.4 Mapping Static Configuration to a Runtime Plugin Tree
How does a static configuration file become an updatable, inspectable runtime plugin tree? Configuration lines are mounted one by one as plugin instances, forming a tree structure; changing the configuration updates a subtree locally without restarting the whole process; and the shape of the tree itself can be queried and printed, which helps troubleshooting.
The illustrative relationship between configuration and assembly can be understood as follows:
profile: basebundle: [core, session, tools, sandbox, webui]patch:- id: modeladapter: default- id: sandboxmode: remoteloader:mount: [core, session, tools, model, sandbox, webui]scope: per-sessiondispose: reverse-order
5. From Configuration to Runtime Graph: The Startup Path
The startup phase does not directly construct a fixed application object. Instead, it goes through a clear pipeline: first read the base configuration and capability bundles, then apply user patches, then have the loader mount configuration lines one by one as plugin instances, and finally resolve dependencies to form the runtime graph.
The value of this path is explainability. At any moment you can answer three questions: which layer of overlay the effective configuration comes from; why a capability has not started yet; and which implementation a service resolves to in the current scope. For troubleshooting and auditing, this is far more efficient than reading an imperative startup routine.
6. Event Stream and Context Projection
The event stream uses append-only semantics, which keeps the write path minimal and naturally persistable. Multiple views are derived from it:
- Model context: a message sequence truncated and summarized according to token budget and compression policy;
- UI trace: a user-facing timeline that can collapse tool details;
- Recovery point: rebuilding session state from any event position;
- Branch: forking at a given event to obtain another execution history.
The key point is projection, not copying: once each view is allowed to rewrite history independently, the consistency of recovery and branching can no longer be guaranteed. For long-term retention, the event stream can be archived to object storage, with log services and monitoring alerts tracking backlog and latency.
7. Engineering Notes and Evolution Advice
First, define stable boundaries. In the developer preview stage of such frameworks, interfaces and default behaviors may change, so keep the adapter layer narrow and avoid letting business code depend directly on volatile interfaces.
Second, separate policy from execution. Approval, rate limiting, and tool allowlists belong to the policy layer and should be independent of the execution layer, so they can be switched per environment.
Third, prioritize isolation. Put command and code execution in a sandbox by default; for remote execution, run it on a container platform; inject credentials through a managed credential mechanism rather than writing them into configuration.
Fourth, build observability in. A printable plugin tree and a replayable event stream are key to lowering troubleshooting costs, not add-on features.
In summary, the architectural focus of a production-grade agent is not the loop itself, but using a runtime plugin graph to manage composition and an append-only event stream to manage history, while keeping the loop thin. Mastering this layering is what lets you build agent systems that keep evolving even in a fast-moving framework environment.
