Plugin Architecture for AI Agent Harnesses: Runtime Component Graph and Event Log
This article explains why production-grade AI agents need more than an execution loop, and how a plugin-based harness architecture separates a dynamic runtime component graph from an append-only execution event log. It covers how configuration is instantiated into components, how scope, dependency waiting, name resolution, cleanup, and configuration mapping are handled, and how the event log serves as the single source of truth for context projection, UI traces, and recovery. It also outlines the role of the execution loop, the engineering benefits of this separation, and the current boundaries of the approach.
1. Background: Why Production Agents Need More Than an Execution Loop
A minimal working agent loop usually does only three things: assemble the prompt, call the model once, and feed tool results back to the model to continue reasoning. This is enough for a demo, but in real business scenarios complexity quickly moves outside the loop: how models and credentials are managed, how sessions are restored and compacted, whether tool calls require approval, what kind of isolation code runs in, how the same runtime facts are observed by the UI, and how subtasks are spawned and reaped.
A common industry response is to stack these capabilities into a monolithic application. The result is tight coupling between modules, configuration that is hard to update incrementally, and leftover listeners and handles on shutdown. A more reasonable abstraction splits the system into two lines that run at the same time: one describes what the system is currently made of, and the other describes what the system just did. The former is a runtime component graph that can be updated dynamically; the latter is an append-only execution event log. The execution loop sits between them, taking capabilities from the component graph and writing the process back to the log.
2. Runtime Component Graph: Turning Static Configuration into an Inspectable Live Structure
2.1 Line-by-Line Mounting from Configuration to Instances
At startup, the system does not directly construct a fixed application. Instead, it first reads the runtime configuration and capability packages, then layers user-defined patches on top, and a loader instantiates each configuration line into a component. The benefit is that configuration is structure: any line can be replaced, disabled, or appended without modifying core code.
An illustrative configuration shape looks like this (structure only, not a specific product interface):
plugins:- id: model-adapteroptions: { provider: local }- id: prompt-registry- id: tool-registryoptions: { policy: ask }- id: session-store- id: sandbox-runner- id: agent-loop
2.2 Five Core Problems Handled by One Mechanism
The distinctive part of the design is not the number of packages, but that the same mechanism answers five problems that are usually handled separately.
First, visibility. Which capabilities a component can perceive at its location is determined by scope, not global variables. Second, startup timing. When a required capability has not appeared yet, components that depend on it should wait rather than crash. Third, name resolution. Services with the same name can resolve to different implementations in different sessions or scopes, which is the basis for multi-tenant and multi-session isolation. Fourth, cleanup responsibility. When a component exits, there must be a clear owner for releasing registrations, event listeners, child processes, and file handles; otherwise long-running systems will leak. Fifth, configuration-to-runtime mapping. Static declarations must become a component tree that can be updated, traversed, and diagnosed.
2.3 Lazy Satisfaction and Graceful Shutdown
Dependencies follow a three-stage pattern: declare, inject, wait. A component declares the capabilities it needs, the container injects them when available, and the component stays suspended if they are not satisfied. Shutdown destroys components in reverse order, first removing registrations and listeners, then terminating child processes and handles. As an engineering practice, each component should maintain a resource inventory and check it item by item during destruction, avoiding hidden failures where “the logic is offline but the port is still occupied.”
3. Append-Only Event Stream: Making Runtime History a Projectable Source of Truth
The session layer maintains an append-only event stream that records what actually happened during a task: user input, model requests and responses, tool calls and results, policy interceptions, errors, and retries. The value of the event stream is that it is the single source of truth, and every other view is a projection of it.
- Model context: projected from the event stream according to window and summarization policies, supporting compaction without losing history.
- UI trace: the UI subscribes to the same log, so multiple clients do not each maintain their own state.
- Recovery and forking: replaying from any event position yields a new branch, making it easy to compare the effects of different strategies.
It is important that log writes remain immutable and orderable. Projections may be cached, but they must not modify the original events in reverse; otherwise recovery and audit capabilities would both fail.
4. Execution Loop: The Meeting Point of Both Systems
The execution loop resolves the model, tool catalog, prompts, and session service from the component graph, and appends the result of each step back to the event stream. Its responsibility boundary should be strictly limited: it does no capability discovery and no history storage, and only orchestrates one round of reasoning and action. The benefit is replaceability: when swapping the model adapter or tool policy, the loop itself does not need to change.
A simplified pseudocode expression:
while not done:ctx = session.project_context()decision = model.invoke(ctx, tools=registry.visible(scope))if decision.is_tool_call:result = sandbox.run(decision, policy=registry.policy(scope))session.append(result)else:session.append(decision)done = True
5. Compositional Complexity and Engineering Benefits
Giving compositional complexity to the component graph and history continuity to the event stream brings several direct benefits: capabilities are pluggable, so evaluation, approval, sandboxing, and remote execution can each be replaced as independent components; scope isolation keeps multiple sessions and subtasks from interfering with each other; a unified cleanup mechanism keeps plugin hot-swapping safe under long-running operation; and incremental configuration updates mean canary releases and rollbacks do not require restarting the whole system.
For implementation, it is worth clarifying three things first: the capability inventory and naming conventions, the event schema and versioning strategy, and resource ownership and destruction order. Once these three are settled, the remaining components can be integrated step by step through the same mechanism. When integrating with external systems, this is usually carried by general-purpose category services, such as object storage for session snapshots, message queues for task distribution, container platforms for isolated execution, and logging, monitoring, and alerting services for observing runtime status.
6. Current Status and Boundaries
This type of architecture is still evolving quickly, and both interfaces and the target model may change, so it should not be treated as a long-term stable commitment. When evaluating it, focus on whether the mechanism is self-consistent, whether cleanup is complete, and whether events can be replayed, rather than chasing specific interface shapes. Understanding the division of labor between the two lines, “composition” and “history,” is the key step from example code to a maintainable agent system.
