Plugin Graph and Event Stream: Agent Runtime Framework Architecture

    Agent runtime frameworks often claim to be plugin-based, but the real architectural challenge is runtime composition rather than the number of packages. This article explains a production-grade runtime as two concurrent systems: a plugin graph that manages capability visibility, dependency-aware startup, scoped resolution, cleanup, and configuration-to-runtime updates; and an append-only event stream that records execution facts and supports projections, recovery, and branching. The agent loop sits between them, consuming model, tool, prompt, and session services from the plugin graph while writing execution history back to the event stream. The article also examines event schema versions and projectors, design tradeoffs, and practical recommendations for observability, lifecycle testing, replay, and governance.

    In the design of agent runtime frameworks, “everything is a plugin” is often understood as having many tools and rich extension points. From an architectural perspective, however, pluginization really addresses runtime composition: which capabilities a plugin can see at its current position; whether it should start when required capabilities are not yet present; whether same-named capabilities can resolve to different implementations in different sessions or scopes; who cleans up registrations, listeners, processes, and handles when a plugin exits; and how static configuration becomes an updatable, inspectable runtime plugin tree. Without unified mechanisms for these problems, the more plugins a system has, the harder it becomes to maintain.

    A more appropriate way to understand such frameworks is as two systems running at the same time: the plugin graph maintains “what the system currently consists of,” while the append-only event stream maintains “what the system just did.” The plugin graph describes which capabilities exist, what they depend on, which scope they take effect in, and how they are cleaned up on unload. The event stream records what actually happened during an agent run and projects the data needed for model context, UI traces, recovery, and forking. The agent loop sits between the two: it obtains models, tools, prompts, and session services from the plugin graph, then writes execution back to the event stream. Together, these two lines form the main body of a production-grade runtime framework.

    1. Plugin Graph: Runtime Composition and Capability Resolution

    The plugin graph is not a simple package list. It is a capability dependency graph with scopes and lifecycles. Nodes represent capability providers or consumers; edges represent dependency relationships and visibility boundaries; scopes determine resolution ranges; and lifecycle hooks determine cleanup responsibility. Which capabilities a plugin can see at a given position should not be determined solely by a global registry. It should be determined by a rule that searches upward from the current scope. In this way, the same set of base capabilities can present different views across sessions, tenants, or run modes, avoiding global pollution.

    First, capability visibility must be modeled explicitly. Plugins declare what capabilities they provide, what capabilities they require, and what optional dependencies they have. The container builds a capability index when mounting. During resolution, it searches upward from the current scope and returns results according to priority when override rules apply. Clearer visibility reduces coupling between plugins. Conversely, implicit global singletons make testing, isolation, and replacement difficult.

    Second, startup conditions require deferral and waiting mechanisms. When a required capability is not yet present, a plugin should neither start blindly nor fail permanently. The container can maintain a “waiting for dependency” state, trigger startup when the dependency appears, and trigger pause or unmount when the dependency disappears. Optional dependencies allow a plugin to run in degraded mode. In this way, plugin graph loading order no longer depends on manual arrangement; it is determined jointly by dependency declarations and runtime state.

    Third, same-named capabilities need scoped resolution. Different sessions may require different model adapters, tool policies, or storage implementations. If every same-named service can only be globally unique, the system will soon be filled with conditional branches. Through scoped registration and resolution, same-named capabilities can resolve to different implementations at the session level, request level, or plugin level, while retaining fallback and override rules.

    Fourth, unmount cleanup must have a unified responsibility chain. When a plugin exits, registrations, listeners, processes, and handles cannot depend on developer discipline. The container should record the cleanup items produced by each plugin, execute them in reverse order on unmount, and notify dependents to re-resolve. For asynchronous resources, it must also handle cancellation, timeouts, and duplicate cleanup. Cleanup mechanisms are key to whether the plugin graph can run stably over time.

    Fifth, static configuration must become an inspectable runtime graph. At startup, the system reads configuration profiles, capability packages, and user patches. The loader mounts plugin instances one by one and completes dependency resolution, scope creation, and consistency checks. During configuration updates, plugins can be added or removed, implementations can be replaced, or rolling reloads can be performed, but resolution results must remain observable and rollback-capable. Illustrative pseudocode follows:

    1. Container.mount(configItem):
    2. plugin = instantiate(configItem.entry)
    3. scope = resolveScope(configItem.scope)
    4. registerCapability(plugin.declaredCapabilities, plugin, scope)
    5. awaitDependencies(plugin.requiredDependencies)
    6. if dependenciesSatisfied: start(plugin)
    7. recordCleanupItems(plugin)
    8. Container.resolve(capabilityName, currentScope):
    9. search upward from currentScope for implementation
    10. if multiple implementations exist: return according to override rules
    11. if none exists: return unsatisfied or trigger deferred startup
    12. Container.unmount(plugin):
    13. execute cleanup items in reverse order
    14. remove capability registrations
    15. notify dependents to re-resolve

    2. Event Stream: Append-Only Log and Recoverability

    The plugin graph solves the composition problem, while the event stream solves the problem of historical continuity. An agent run produces facts such as user input, model requests and responses, tool calls and results, approval records, context compaction, branches, and recovery. If these facts are kept only in in-memory state, UI observation, failure recovery, and session forking all become fragile. The value of an append-only event stream is that facts are appended rather than arbitrarily rewritten, projections can be rebuilt, and branches can be derived from a specific event offset.

    The event stream needs schema versions and projectors. Before an event is written, its schema version is validated. After it is written, an optional projection cache is updated. During rebuild, the system starts from the latest snapshot, applies subsequent events one by one, and generates model context, UI traces, and recovery state. Context compaction should not destroy the original facts. Instead, it should record the compaction result as a new event so that replay can still explain why the context became what it is. A session fork creates a new branch from a specified event offset, preserving shared history and isolating subsequent events.

    1. EventStream.append(event):
    2. validate schema version
    3. write to append-only log
    4. update projection cache (optional)
    5. Projection.rebuild(offset):
    6. snapshot = latestSnapshot(offset)
    7. apply events after snapshot one by one
    8. generate model context / UI trace / recovery state

    3. Agent Loop: Bridging the Plugin Graph and Event Stream

    The agent loop is not an isolated module. It obtains models, tools, prompts, and session services from the plugin graph, calls models and executes tools according to policy, handles approvals and errors, and then writes the execution process back to the event stream. A minimal loop only needs to assemble the prompt, call the model, execute tools, and send results back to the model. A production-grade runtime framework must also handle models and credentials, session recovery and compaction, tool policy and approvals, sandboxing and remote execution, multiple hosts, sub-agents, plugin start/stop, and how the UI observes the same runtime facts. By delegating composition complexity to the plugin graph and historical continuity to the event stream, the agent loop can remain relatively clear.

    4. Design Tradeoffs and Practical Recommendations

    The plugin graph brings flexibility, but it also brings observability and governance costs. It is advisable to start with capability contracts, dependency declarations, minimized scopes, lifecycle tests, event schema versioning, projection caches, replay tests, and configuration validation. Scopes should not be overused, cleanup items must be testable, the event stream needs snapshot and archival strategies, and configuration updates need consistency checks and rollback paths. A spatiotemporal composability programming paradigm proposed in related research can serve as a long-term reference, but its target model is not yet stable; practical engineering should still focus on verifiable runtime mechanisms.

    Overall, the distinguishing characteristic of a production-grade agent runtime framework is not that it has many packages or that every package has a uniform entry point. It is whether the framework can simultaneously handle capability visibility, dependency startup, scoped resolution, unmount cleanup, configuration updates, and the appending, projection, recovery, and forking of execution history. The plugin graph and event stream run in parallel, with the agent loop bridging them in the middle. That is the backbone of this class of architecture.