Everything Is a Plugin: Inside a Reversible AI Runtime Architecture

    This article explains the "everything is a plugin" architecture for AI agent platforms, where a minimal kernel provides only five runtime semantics—context, service registration, event dispatch, dependency activation, and side-effect reclamation—while all business capabilities come from a plugin tree. It examines four structural problems of traditional plugin systems, how runtime semantics resolve them, and how session, agent, and preset constraints keep the design orderly, along with practical guidance and common anti-patterns.

    Everything Is a Plugin: Inside a Reversible AI Runtime Architecture

    1. Where the Problem Starts: Agent Capabilities Are Dynamic

    When building intelligent coding tools or general-purpose agent platforms, one fact is unavoidable: what an agent “can do” is not a constant fixed at compile time, but a variable that keeps changing at runtime. Models need to be swapped, tools need hot-plugging, sessions need isolation, sandbox policies need to be adjusted per tenant, filesystem views need to be rewritten per task, termination conditions and retry strategies for the agent loop need to be tailored per scenario, the scheduler needs to switch between multiple execution backends, and the UI needs to redraw its entry points as the capability set changes.

    If every one of these were written into a fixed kernel, the kernel would quickly swell into a monolith that “manages everything and can change nothing.” That is why the industry has gradually converged on a direction: the kernel carries no business capability and provides only a very thin set of runtime semantics; all business capabilities are mounted as plugins, and the system’s actual capability equals the plugin tree loaded at startup. Using “everything is a plugin” as the guiding thread, this article discusses how its runtime semantics work with business constraints, and which inherent difficulties of traditional plugin mechanisms it solves.

    2. The Kernel Keeps Only Five Things

    In a plugin runtime that can evolve sustainably, kernel responsibilities must be compressed to a minimum and kept stable. Usually only five semantics remain:

    1. Context: Provides each plugin with a controlled access entry point instead of letting plugins touch global variables directly. Context is hierarchical, derivable, and destroyable, and a plugin’s view is limited to the scope it is authorized for.
    2. Service registration: When a plugin exposes a capability, what it registers is a “service contract” rather than a concrete implementation; consumers address by contract, and the implementation can be replaced.
    3. Event dispatch: Plugins do not call each other directly but collaborate loosely through an event bus; the publisher does not need to know that subscribers exist.
    4. Dependency activation: Plugins declare dependencies, and the runtime activates them in topological order; when a dependency is missing, the plugin stays in an inactive state instead of crashing halfway through execution.
    5. Side-effect reclamation: Any registration, listener, timer, handle, or external resource request must be recorded as a revocable side effect, and reclaimed uniformly when the plugin is unloaded.

    Schematically, a plugin often only needs to declare metadata and lifecycle hooks:

    1. definePlugin({
    2. name: 'tool.web_search',
    3. inject: ['logger', 'sandbox', 'policy'], // basis for dependency activation
    4. setup(ctx) {
    5. ctx.on('agent/step', handler); // event dispatch
    6. ctx.provide('tool.search', impl); // service registration
    7. return () => { /* side-effect reclamation */ }; // revocation semantics
    8. }
    9. })

    The key point is that the kernel does not know about “search,” “sandbox,” or “UI”; it only knows context, contracts, events, dependencies, and reclamation. The absence of a business capability does not make the kernel error out—it only makes the agent’s capability set smaller. This is the direct manifestation of “capability is determined by the plugin tree.”

    3. Four Structural Difficulties of Traditional Plugin Mechanisms

    Traditional plugin systems repeatedly fail on three pairs of contradictions—“easy to register, hard to revoke; easy to initialize, hard to roll back on failure; easy to use global singletons, hard to override locally”—which can be further broken down into four structural problems.

    First, registration and revocation are asymmetric. Most frameworks provide install but no equivalent uninstall. Listeners, timers, and global hooks registered during a plugin’s initialization lack a unified registry, so unloading relies on manual memory to clean them up one by one; leftover listeners cause duplicate triggering and memory leaks.

    Second, initialization and rollback are asymmetric. When plugin A initializes successfully but plugin B fails, the framework usually throws an exception and exits directly, leaving A’s side effects behind in the system and forming a “half-initialized” state. Without a mechanism to roll back in reverse dependency order, the cost of failure is amplified.

    Third, global singletons conflict with local overrides. Once a capability exists as a global singleton, multi-tenancy, multi-session, and multi-preset cannot coexist: session A changes the model config and session B is changed along with it; wanting to replace the logging or policy implementation in a sub-scope forces you to modify the global, which then pollutes other scopes.

    Fourth, coupling and ordering become implicit. Plugins call each other through direct references, dependencies are hidden in code rather than declared, activation order cannot be derived, and problems only surface at runtime in ways that are hard to locate.

    4. Moving the Difficulties into Runtime Semantics

    The value of “everything is a plugin” is not having many plugins, but shifting the difficulties above from “the plugin author’s responsibility” to “runtime semantic guarantees.”

    • For registration/revocation asymmetry: all registration actions must go through the context, which maintains a side-effect list for each plugin and revokes in reverse order on unload, achieving “whatever is registered can be revoked.”
    • For initialization/rollback asymmetry: activation proceeds in phases by dependency topology; if any phase fails, already-activated plugins are rolled back in reverse along the dependency chain, so the system is either fully ready or returns to a clean initial state.
    • For global singleton/local override: context supports derivation. A child context can override same-named services and event handlers, forming scope isolation; the parent scope’s implementation is not polluted, and session-level, task-level, and tenant-level configs coexist naturally.
    • For implicit coupling: dependencies must be declared explicitly, and the runtime computes activation order and performs missing-dependency checks based on them, moving “crash halfway through” forward to “validate at startup.”

    The direct result of these semantics is that the plugin tree becomes the single source of capability, and the runtime is observable, rebuildable, and rollback-capable. When troubleshooting, you no longer have to guess “who exactly changed the global state”—you just inspect the plugin tree and the scope derivation relationships.

    5. Completing the Runtime with Business Constraints: Sessions, Agents, and Presets

    Runtime semantics only solve “how to mount and how to revoke,” not “what to mount, how much, and who may override whom.” That requires three layers of business constraints.

    The session layer defines isolation boundaries. Each session has an independent context derivation chain; the tool set, filesystem view, and sandbox policy take effect within the session, and when the session ends the entire subtree is reclaimed, avoiding cross-session interference.

    The agent layer defines loop boundaries. The agent loop itself is also a plugin: termination conditions, retry and backoff, context compression, and tool-call whitelists are all injected as plugins, so replacing the loop implementation requires no kernel changes.

    The preset layer defines composition boundaries. A preset is a declarative manifest of the plugin tree, describing which capabilities a certain kind of task needs, in what order to activate them, and which services need local overrides. Onboarding a new scenario appears as adding a new preset rather than modifying kernel code.

    The relationship among the three can be summarized as: the runtime guarantees “revocability,” sessions guarantee “non-interference,” agents guarantee “loop controllability,” and presets guarantee “reusable composition.”

    6. Implementation Advice and Common Anti-Patterns

    A few practical guidelines are recommended in practice: all external resource requests must be registered as side effects; service contracts should keep narrow interfaces to avoid de facto strong coupling between plugins; presets should be separated from implementations, with presets doing only declaration; and the plugin tree should have startup validation and readiness probes to shift failure left.

    The common anti-patterns are equally clear: writing business logic back into the kernel for the sake of “convenience” invalidates revocation semantics; using global singletons as temporary switches breaks scope isolation; plugins directly referencing implementations instead of contracts makes dependency activation meaningless; and writing only initialization without reclamation is the main source of leftovers and leaks.

    When hosting this kind of runtime in the cloud, container platforms can typically handle isolated deployment and rapid rebuilding of the plugin tree, object storage can hold preset manifests and artifacts, message queues can enable cross-process event dispatch, and logging services with monitoring and alerting can observe the activation, rollback, and side-effect reclamation chains. Baidu AI Cloud offers a fairly complete combination of such general capabilities and can serve as a reference foundation for building this kind of reversible runtime.

    7. Conclusion

    “Everything is a plugin” does not push complexity onto plugins; it converges complexity into one very thin and stable set of runtime semantics: context, service registration, event dispatch, dependency activation, and side-effect reclamation. The kernel therefore stays lean over the long term while capability grows with the plugin tree, and the three constraint layers of sessions, agents, and presets keep this freedom from falling into disorder. For teams building intelligent coding tools or agent platforms, the standard for judging whether the architecture holds is simple—whether any capability can be cleanly mounted and just as cleanly removed.