Agent Microkernel Architecture: A Runtime Where Everything Is a Plugin

    This article explains why traditional Agent loops become hard to evolve as they move into production, and how a microkernel approach solves the problem. The core idea is that there should be no privileged, irreplaceable core: models, tools, sessions, and infrastructure should all be replaceable plugins. The design rests on two kinds of composability—time composability through reversible effects, so unloading a plugin cleanly reverts everything it registered, and space composability through reactive dependencies, so components automatically respond when the capabilities they depend on change. Five runtime primitives (Plugin, Context, Service Dependency, Typed Event, and Reversible Effect) form a thin, stable kernel, while the actual behavior of an agent is assembled dynamically from the loaded plugin set. The article also maps the design to familiar engineering patterns and offers practical advice for adopting it.

    1. Why Traditional Agent Loops Are Hard to Evolve

    In most Agent frameworks, the Agent loop—typically described as a cycle of “perceive → plan → call tools → observe results → plan again”—is the central hub of the whole pipeline. Capabilities such as model adaptation, tool registration, session recording, and context assembly are often hard-coded inside this hub or tightly tangled around it.

    This “fat core” design is efficient in the prototype stage, but problems gradually surface once you move into production:

    • Models are not replaceable. Switching from model A to model B usually means changing the internal logic of the loop, rather than simply plugging in an adapter.
    • Tool lifecycles become messy. A tool may attach event listeners, inject prompt fragments, and reserve resources when it registers, but when it needs to be removed or downgraded, those side effects linger, producing hard-to-reproduce “ghost states.”
    • Dependencies are hard-wired. A tool may depend directly on a concrete implementation such as “the local file system,” which makes it impossible to migrate smoothly to remote storage or a containerized environment.
    • Composition is difficult. To combine several capabilities into different forms of agents under different configurations, you can only pile up branches and switches, and complexity quickly spirals out of control.

    The root cause is the lack of a runtime with no privileged core. By “privileged core” we mean the parts that are treated as inherently irreplaceable and can only be patched on top of.

    2. The Microkernel Approach: No Irreplaceable Agent Core

    The philosophy of the microkernel operating system is instructive here: the kernel keeps only the smallest, most stable set of mechanisms (such as scheduling, context switching, and inter-process communication), while everything else—file systems, drivers, network stacks—exists as services that can be loaded and unloaded.

    Transplanting this idea to an Agent runtime leads to a counterintuitive conclusion: there is no core that must be patched; everything should be a replaceable plugin. Concretely, this means:

    • Model adapters are swappable. Behind ctx.llm can be an implementation from any model provider.
    • Tool sets are swappable. The tools referenced by ctx.tools—both their registry and their implementations—can be replaced as a whole.
    • Session recording is swappable. ctx.sessions can be in-memory, file-based, backed by a database, or a distributed log.
    • The loop itself is swappable. ctx.agentLoop is a pluggable component too, not a hard-coded skeleton.
    • Infrastructure is swappable. The file system, sandbox, sub-agent provider, and prompt assembly are all plugins.

    This means an “Agent” is no longer a fixed class or one giant function, but the result of dynamically assembling a set of composable plugins. The runtime’s responsibility is reduced to an extremely thin layer: providing a context that can be mounted into and plugged into (called the Runtime Context in Cordis), responsible for orchestrating context, effects, events, and the loader. The structural relationship can be illustrated as follows:

    1. Cordis Runtime (thin kernel)
    2. Context / Effects / Events / Loader
    3. │
    4. ┌────────────┼────────────┐
    5. ▼ ▼ ▼
    6. Model Provider Tool Store Session Runtime
    7. │ │ │
    8. └────────────┴────────────┘
    9. ▼
    10. Agent / Loop / FS / Sandbox / ...

    What truly determines an agent’s behavior is not this thin kernel, but the set of plugins that get loaded.

    3. Two Kinds of Composability: Time and Space

    To make “everything is a plugin” work in practice, being able to plug in and unplug is not enough. Two deeper questions must be answered: how do you cleanly reclaim resources on unload? How do components respond automatically when something they depend on changes? In engineering terms, these are time composability and space composability.

    3.1 Time Composability: Reversible Effects

    When a plugin loads, it usually performs a series of “registration” actions, such as:

    • Registering several tools;
    • Registering several event listeners;
    • Appending a fragment to the system prompt (a Prompt Section);
    • Registering a model adapter;
    • Providing a service.

    Time composability requires that when a component loads and produces a bunch of side effects, unloading it should completely and cleanly revert those side effects, leaving no trace. This “register binds, unload reverts” behavior is called a reversible effect.

    The following illustrative pseudo-code demonstrates this design:

    1. // On unload, a plugin must be able to revert every effect it produced during loading
    2. class ToolPlugin extends Plugin {
    3. apply(ctx) {
    4. const dispose = ctx.effects.collect(() => {
    5. ctx.tools.register(this.buildTool()); // 1. Register a tool
    6. ctx.on('session:end', this.onSessionEnd); // 2. Attach an event listener
    7. ctx.prompt.append(this.promptSection()); // 3. Append a prompt section
    8. ctx.llm.register(this.buildAdapter()); // 4. Register a model adapter
    9. ctx.provide('approval', this.approval); // 5. Provide a capability
    10. });
    11. // When the plugin is unloaded, dispose is called once
    12. return dispose; // All of 1–5 above are reverted, zero residue
    13. }
    14. }

    Here ctx.effects.collect(...) “keeps the books” on all the side effects a plugin produces during loading and collects the corresponding revert functions. On unload, a single cleanup triggers them, and the tools, listeners, prompt fragments, adapters, and services all disappear together. This is precisely the value of reversible effects—it makes a plugin’s “birth” and “death” an atomic, traceable whole.

    3.2 Space Composability: Reactive Dependencies

    The second question is spatial: plugin A declares that it depends on some service B. When B appears, disappears, or is replaced, how should A respond automatically?

    This mechanism—where a dependent automatically adjusts to changes in the thing it depends on—is called a reactive dependency. It ensures that when services are dynamically attached and detached at runtime, upper-layer components neither crash nor read dirty state, but smoothly reassemble.

    This is easy to understand in the Agent context. Suppose you write a “file operation tool” that declares only three kinds of capabilities it needs:

    • File access capability (ctx.fs);
    • Sandbox isolation capability (ctx.sandbox);
    • Human approval capability (ctx.approval).

    Each of these three capabilities is provided by a provider that can be swapped dynamically:

    • ctx.fs can be a local file system, a remote file system, an in-container file system, or even a file system with specific access-control policies.
    • ctx.sandbox can be process-level, container-level, or VM-level isolation.
    • ctx.approval can be automatic pass-through, human confirmation, or a policy-engine decision.

    The key point is: the tool itself does not need to know at all where the capability actually lives or how it is executed. It depends only on the abstract interface of “a capability.” When the underlying file-system provider switches from “local” to “remote,” not a single line of the tool’s code changes—reactive dependencies automatically inject the new provider, and the tool keeps working as usual.

    4. Five Building Blocks: A Self-Consistent Set of Runtime Primitives

    Abstracting out the mechanisms above, this design can be summarized as five interlocking core building blocks. Understanding them gets you to the skeleton of the whole architecture:

    • Plugin: the unit of capability encapsulation; it is both a provider of functionality and the smallest unit of loading and unloading.
    • Context: the runtime environment a plugin lives in; all capabilities (services), events, and effects hang off it.
    • Service Dependency: a plugin’s declarative need for “a kind of capability,” rather than a hard reference to a concrete implementation.
    • Typed Event: a message bus with type constraints; components communicate through publish/subscribe to stay decoupled, rather than calling each other directly.
    • Reversible Effect: a bookkeeping mechanism that lets registration actions be fully reverted; it is the cornerstone of time composability.

    In one sentence, the core division of labor in this design is this: tools describe “what capability I need,” while providers decide “where that capability lives and how it is executed.” The microkernel itself makes almost no business decisions; it is only responsible for making plugin declaration, assembly, response, and reclamation composable and predictable.

    5. Analogies to Familiar Engineering Concepts

    For most backend and platform engineers, none of this is unfamiliar—it is essentially a fusion of several mature patterns:

    • Dependency injection container: capabilities are injected into plugins via ctx, rather than plugins constructing their own dependencies;
    • Plugin system: functionality is loaded and unloaded with the plugin as the unit;
    • Event bus: components communicate decoupled through typed events;
    • Lifecycle management: the loading, running, and unloading phases are managed uniformly;
    • Effect management: registration actions are brought into reversible bookkeeping, supporting clean rollback;
    • Configurable component trees: configuration declares “which plugins to assemble and which capabilities to provide,” yielding a runtime of a different shape.

    Once you understand this layer of analogy, the mental burden of getting started is much lower—you are not learning a brand-new set of abstractions, but combining familiar paradigms like DI, event-driven design, and plugin architectures into a new runtime form.

    6. Practical Engineering Advice for Implementation

    If you want to borrow this “everything is a plugin + microkernel” approach in your own system, a few practices are worth thinking through ahead of time:

    1. Put capability abstraction ahead of concrete implementation. First define clearly “what capability a tool needs” (file, sandbox, approval, model), then consider who provides it. Only when the abstractions are drawn correctly does the cost of replacement genuinely drop.
    2. Bring effects into reversible bookkeeping. Every “registration-type” action (listeners, prompt fragments, adapters, services) must be revertible one by one. Otherwise, the more plugins you add, the harder state becomes to reason about.
    3. Keep dependencies declarative and responses reactive. The upper layer declares only “what I depend on,” leaving “when a dependency is available and how to switch it” to the runtime’s reactive mechanisms, avoiding hard-coded ordering.
    4. Keep an extremely thin, extremely stable kernel. The kernel handles only context, events, effects, and the loader, and carries no business decisions—this is what allows it to evolve over the long term without being locked down by a single requirement change.
    5. Build observability in from the start. Because behavior is assembled dynamically, there should be clear observable output for which plugins are loaded, which capabilities are provided, and which provider a dependency currently resolves to, making troubleshooting easier.

    7. Summary

    The value of “everything is a plugin” lies not in making the architecture look advanced, but in turning “replaceability” from a slogan into a mechanism. Time composability (reversible effects) solves the problem of “clean on unload,” and space composability (reactive dependencies) solves the problem of “automatic response when dependencies change.” Then five primitives—Plugin, Context, Service Dependency, Typed Event, and Reversible Effect—gather the runtime into an extremely thin microkernel. What you end up with is an Agent runtime in which models, tools, sessions, and infrastructure can all be freely replaced and dynamically orchestrated. For teams looking to build a long-term evolvable, reusable platform for intelligent applications, this design approach offers considerable reference value.