Plugin-Based AI Agent Runtimes: A Dual-Plane Architecture

    A production-ready AI agent runtime needs more than a model-and-tool execution loop. This article explains a dual-plane architecture in which a runtime plugin graph manages capabilities, dependencies, scopes, and lifecycles, while a session event stream preserves execution history for recovery, branching, auditing, and observability. It also examines how the execution loop coordinates these planes and outlines the design requirements for reliable plugin composition.

    1. From a Minimal Agent Loop to a Production Runtime

    Discussions of AI agent runtimes often focus on the execution loop: assemble a prompt, call a model, parse tool requests, execute tools, return the results to the model, and repeat until completion. This model explains a demo, but not a production system. Real deployments must also handle model and credential management, session recovery and compression, tool policies and approvals, sandboxes and remote execution, multiple host integrations, subagents, plugin activation and deactivation, UI observability, and auditing.

    A more useful starting point is not the number of plugins a framework supports, but two architectural planes that operate together:

    1. The runtime plugin graph describes the capabilities currently available, their dependencies, the scopes in which they apply, and how their resources are cleaned up when unloaded.
    2. The session event stream records what actually happened during an agent session. Projections of that stream produce model context, UI traces, recovery points, branching history, and audit records.

    The execution loop sits between these planes. It obtains models, tools, prompts, policies, and session services from the plugin graph, then appends execution facts to the event stream.

    The plugin graph answers, “What is the system composed of right now?” The event stream answers, “What has the system done?” Together, they form the foundation of a complete agent runtime.

    2. What “Everything Is a Plugin” Really Means

    “Everything is a plugin” is often interpreted as having many packages, many extension points, and a common entry point for every module. That interpretation only covers the surface.

    The real value of plugin architecture is a shared composition mechanism for model adapters, system prompts, tool catalogs, session services, storage, sandboxes, execution loops, UI capabilities, and operating modes.

    A common mounting interface alone, however, does not establish a sound architecture. A plugin system must address at least five questions:

    • Which capabilities can a plugin see in its current context?
    • Should a plugin start if a required capability is not yet available?
    • Can the same service name resolve to different implementations in different sessions or scopes?
    • Who cleans up registrations, listeners, processes, and handles when a plugin exits?
    • How does static configuration become a runtime plugin tree that can be updated, inspected, and rolled back?

    Only when one coherent mechanism addresses all five does plugin architecture become more than modular code organization. It becomes an operational composition model with capability discovery, dependency gating, scope isolation, lifecycle management, and dynamic assembly.

    3. The Runtime Plugin Graph: What the System Is Composed Of

    The runtime plugin graph can be understood as a scoped directed graph. Nodes represent plugin instances or service providers, and edges represent dependencies. Scope adds a third dimension, determining whether a capability is visible within a session, task, subagent, or tenant.

    The loader mounts configuration entries as instances and maintains their service-resolution relationships.

    3.1 Capability Visibility: Moving Beyond Global Singletons

    Plugins should not automatically have access to the entire system. A more robust design lets each plugin declare the capabilities it needs within an explicit context, then resolves those capabilities by scope.

    A local scope can override its parent scope, which can in turn fall back to a global default. This provides default capabilities while allowing a particular session or subtask to use its own model, toolset, storage policy, or sandbox implementation.

    Capability visibility also affects security boundaries. If plugins can freely access a global registry, tool policies, tenant isolation, and auditing become difficult to enforce. Explicit capability resolution creates a point at which the system can apply permission checks, fallback policies, and observability logic.

    3.2 Startup Gating: Do Not Start Without Required Dependencies

    Before starting a plugin, the runtime should verify that its required dependencies are available. If a required capability is missing, the plugin should remain inactive rather than fail later with a null reference. If an optional capability is missing, the plugin may operate in a degraded mode.

    The gating mechanism needs to distinguish states such as unresolved, resolving, ready, and failed. It must also prevent circular dependencies from disrupting startup ordering.

    This allows the system to assemble capability bundles dynamically. If an environment lacks remote execution, plugins that require it do not start. If a session has not enabled a particular mode, the corresponding plugins do not enter its runtime graph.

    Configuration errors can then surface during assembly rather than on the first request.

    3.3 Same-Named Services and Scoped Resolution

    Production agent systems frequently need multiple instances of the same named service. Different sessions may use different model adapters, different tenants may use different storage implementations, and different subtasks may use different tool policies.

    If a service name can only map to a global singleton, meaningful isolation is not possible.

    A better model is service token plus scope. Resolution begins in the current scope and proceeds upward: local overrides take precedence, followed by parent scopes and finally global defaults.

    Implementations may pass context explicitly or carry it implicitly through a scoped container. The essential requirement is that resolution remains predictable and inspectable, including an explanation of why a particular implementation was selected.

    3.4 Unloading and Resource Cleanup

    Unloading a plugin is not simply deleting an object. It means reversing all the effects the plugin created: registrations, event listeners, timers, child processes, file handles, network connections, caches, and background tasks.

    A reliable approach is to have mounting return disposable handles, or to track plugin side effects within its scope and release them in reverse order during unloading. Cleanup operations should be idempotent where possible and support retries after partial failures.

    Mounting also needs transactional semantics if it can fail partway through. When a new plugin fails, any capabilities it has already registered should be rolled back so the runtime graph is not left partially mounted.

    For hot updates, stop plugins that depend on the old implementation, replace the provider, and then restart its dependents. Where necessary, retain a snapshot of the previous graph to support rollback.

    3.5 From Static Configuration to a Dynamic Plugin Tree

    Startup should generally assemble the application from configuration rather than construct a fixed application directly.

    Configuration profiles, capability bundles, and user patches are merged into configuration entries, which the loader then mounts. Merging requires explicit precedence rules and conflict detection. Mounting order must respect dependencies, and the resulting runtime graph must be queryable, exportable, and diagnosable.

    The assembly process can be summarized as follows:

    1. Read configuration profiles and capability bundles
    2. Merge user patches into configuration entries
    3. Validate dependencies, scopes, and conflicts
    4. Mount plugin instances in topological order
    5. Expose ready services
    6. Open a session and start the execution loop

    Dynamic updates should not simply restart the entire process. Instead, compare the old and new configuration entries, determine the affected components, stop and replace plugins according to their dependencies, restore their dependents, and record the changes as events.

    This is what turns configuration into an updatable runtime plugin tree rather than a one-time set of startup parameters.

    4. The Session Event Stream: What the System Has Done

    The plugin graph handles composition; the event stream handles continuity.

    A session should not be modeled only as mutable fields that are repeatedly overwritten. It should maintain an append-only event log. Events can include user input, model output, tool calls, tool results, policy decisions, approvals, compression, branching, errors, and cancellation.

    The log is the source of truth. Model context, UI traces, recovery points, and statistics are projections of it.

    An event stream provides traceability and replayability. Session recovery reconstructs state from the log rather than guessing what was previously held in memory. A UI can subscribe to the same events instead of maintaining a separate private representation of execution state. A new session branch can be derived by copying the event prefix up to a selected point.

    Event design must also account for engineering constraints:

    • Events need version numbers, unique identifiers, causal correlation identifiers, and timing information.
    • Writes should be idempotent.
    • Sensitive fields should be redacted during writing or projection.
    • Context compression should be recorded as an explicit event rather than silently rewriting history.

    Without these safeguards, recovery and auditing lose their reliable foundation.

    5. The Execution Loop: Coordinating the Two Planes

    The execution loop should not own all global state. Its role is closer to that of a coordinator.

    On each iteration, it resolves the model, tools, policies, sandbox, and session services from the plugin graph for the current scope. It projects model context from the event stream, performs model and tool calls, and writes the results back to the stream.

    1. runTurn(session, scope):
    2. while not stop:
    3. ctx = session.projectContext(scope.policy)
    4. model = graph.resolve("ModelService", scope)
    5. tools = graph.resolveAll("Tool", scope)
    6. output = model.generate(ctx, tools.schema)
    7. for call in output.toolCalls:
    8. decision = graph.resolve("PolicyService", scope).check(call)
    9. if decision.approved:
    10. result = graph.resolve("SandboxService", scope).exec(call)
    11. else:
    12. result = denied(decision.reason)
    13. session.append({type: "ToolResult", callId: call.id, result: result})
    14. session.append({type: "ModelOutput", output: output})

    This pseudocode illustrates the separation of responsibilities:

    • The loop advances execution.
    • The plugin graph assembles capabilities.
    • The event stream records facts and supplies projections.

    Tool approval, sandbox execution, context compression, cancellation, and limit enforcement do not all need to be embedded in the loop. They can participate in composition as replaceable services.

    6. Production Design Checklist and Trade-Offs

    Define Plugin Boundaries Around Change

    Plugin granularity should follow boundaries of change, not file counts. Model adapters, tool policies, storage, sandboxes, and UI observability are good candidates because they are likely to vary.

    Foundational event formats, resolution protocols, and security invariants should remain stable.

    Make Dependencies Explicit

    Required and optional dependencies, startup gates, readiness states, and failure policies should all be inspectable. Avoid implicit global lookups that hide dependencies and make behavior difficult to diagnose.

    Apply Scope Throughout the Lifecycle

    Scope must carry through service resolution, event writing, tool execution, and cleanup. Lifecycle management without scope eventually degenerates into global side effects that are difficult to trace.

    Treat the Event Stream as Infrastructure

    The event stream needs schemas, version migration, redaction, and compression policies. It is the shared foundation for recovery, branching, auditing, and UI observability—not a temporary diagnostic log.

    Build Observability on Shared Runtime Facts

    The plugin graph exposes capability structure, while the event stream exposes execution history. UIs, alerts, and diagnostic tools should read from these two sources rather than maintain independent versions of runtime state.

    7. Conclusion

    The defining feature of a plugin-based AI agent runtime is not the number of plugins it contains. It is a unified mechanism for capability visibility, startup gating, scoped resolution, lifecycle cleanup, and dynamic configuration.

    The runtime plugin graph manages composition. The session event stream preserves continuity. The execution loop obtains services from the graph and writes execution facts to the stream.

    Separating these three responsibilities gives a production agent runtime the architectural foundation it needs for extensibility, recovery, auditing, and observability.