Everything Is a Plugin: Inside the Agent Microkernel Architecture
This article breaks down the "everything is a plugin" agent microkernel architecture, a design that removes the fixed central execution loop and moves model adapters, tools, session logs, file access, sandboxes, sub-agents, and prompt assembly into replaceable plugins. It explains what the kernel deliberately does not do, the five core concepts (plugins, context, service dependencies, typed events, and revocable side effects), and the two forms of composability: temporal composability for clean load/unload cycles and spatial composability for depending on capabilities rather than implementations. The article also compares this approach with a traditional centralized loop, outlines its costs, and offers practical guidance for adoption.
1. Introduction: From a Central Loop to a Microkernel Runtime
When engineering agent applications, a structural tension keeps resurfacing: the core execution loop is treated as a stable hub, yet business requirements keep forcing changes to it. The model integration needs to be swapped, the tool set needs to grow, session records need to be migrated, the file system and sandbox need to be replaced, the source of sub-agents needs to change, and the prompt assembly strategy needs adjustment. If all of this revolves around a hub that cannot be replaced, every step of evolution means invasive changes to core code, the scope of regression testing keeps expanding, and you end up in a maintenance trap where pulling one thread moves the whole body.
The “everything is a plugin” agent microkernel architecture is the answer to this trap. Its core premise is that there is no privileged, irreplaceable core. Model adaptation, tool registration, session logging, the execution loop, file access, isolated environments, sub-agent sources, and prompt assembly all exist as plugins, with their lifecycles and dependencies carried by a unified runtime context. The kernel only provides composition rules and scheduling semantics; it carries no business capability of its own.
2. The Kernel’s Boundary: What the Kernel Does Not Do
To understand a microkernel, you first have to understand its restraint. Traditional frameworks tend to accumulate high-frequency capabilities into the core, forming a de facto privileged path. A microkernel deliberately keeps the core lean, retaining only four minimal responsibilities.
The first is plugin loading and unloading: determining at runtime which capabilities exist, in what order they take effect, and how they are removed. The second is context and dependency resolution: a plugin declares what capability it needs, and the kernel connects providers and consumers correctly. The third is event dispatch: plugins communicate through typed events rather than holding references to each other. The fourth is side-effect registration and reclamation: every registration is recorded so it can be precisely undone on unload.
Everything else, including “how to call the model,” “how to run a reasoning-action loop,” and “how to persist a session,” belongs to plugins. The direct result of this boundary is that replacing any capability requires no change to the kernel and no change to other plugins.
3. Five Foundational Concepts
The architecture is usually summarized in five concepts that together form the minimum viable mental model.
- Plugin: the unit of capability encapsulation; it declares dependencies, registers services, listens for events, and produces side effects.
- Context: the single entry point for a plugin to interact with the runtime, providing a unified interface to services and events.
- Service dependency: a plugin declaratively expresses “what capability I need” rather than “who provides the capability.”
- Typed event: a message channel with type constraints that makes cross-plugin collaboration statically checkable.
- Revocable side effect: every registration can be rolled back precisely, which is the prerequisite for safe unloading.
A schematic plugin structure looks like this; the focus is on declaring dependencies and registering in pairs:
const fileToolPlugin = {name: 'tool:file',inject: ['fs', 'sandbox', 'approval'], // declare required capabilitiesapply(ctx) {const dispose = ctx.tools.register(readFileTool); // produce a side effectctx.on('session/append', handler); // produce a side effectreturn () => { dispose(); }; // undo on unload}};
4. Temporal Composability: Side Effects Must Be Fully Reversible
Temporal composability is about ordering: if loading a plugin produces a set of side effects, then unloading it should fully reverse those side effects, leaving nothing behind and not polluting plugins loaded afterward.
Side effects that typically need to be undone include tool registrations, event listeners, prompt fragments, model adapters, service provider bindings, scheduled tasks, and resource handles. To guarantee this in engineering, three disciplines are required. First, registration must return a callable dispose function; “register without recording” is forbidden. Second, nested scopes must form a stack structure, so destroying a child scope automatically reclaims its internal registrations. Third, disposal must be idempotent and isolated against exceptions, so a single plugin’s failed reclamation cannot block the overall unload.
Without this layer of protection, hot swapping is just a slogan: repeated load/unload cycles cause duplicate tool registrations, duplicate event triggers, and duplicate prompt assembly. These problems only surface in long-running processes and are extremely costly to diagnose.
5. Spatial Composability: Depend on Capabilities, Not Implementations
Spatial composability is about coexistence: when a capability declared by a plugin appears, disappears, or is replaced, the plugins that depend on it should respond automatically without rewriting their own logic.
This is exactly where dependency injection and reactive dependencies deliver value. A tool plugin can declare only three dependencies—file access, isolated execution, and human approval—without caring whether the implementation behind them is a local file system, a remote file service, an in-container mount, or an implementation with access control policies. When the provider switches, the consumer only needs to rebind; the business code stays unchanged.
// The consumer is programmed against capabilities onlyconst listDirTool = {inject: ['fs'],apply(ctx) {ctx.tools.register({name: 'list_dir',async run(path) { return ctx.fs.list(path); } // unaware of the concrete implementation});}};
This design also enables canary rollout and graceful degradation: replacing a capability provider with a cached or rate-limited version, or switching to a read-only implementation during a failure, is a runtime composition adjustment rather than a code change.
6. Comparison with a Traditional Centralized Loop
A centralized loop hard-codes the reasoning-action flow in the core and offers limited extension points, usually allowing only local intervention through callbacks or hooks. A plugin-based microkernel treats the loop itself as a replaceable plugin, so extension happens at the composition layer. The former has high replacement cost, strong coupling, and a large testing surface; the latter has low replacement cost and clear boundaries, at the price of higher demands on dependency governance and lifecycle management.
It should be stated objectively that the microkernel is not free of cost: the call chain gains a layer of indirection, dependency resolution and event dispatch add a small amount of runtime overhead, and debugging requires dependency graphs and event tracing tools to locate problems. It is therefore better suited to scenarios with frequently changing capabilities, long-term evolution, and multi-environment deployment. For small scripts with fixed logic and short lifecycles, a centralized structure is actually more economical.
7. Practical Recommendations
First, define the capability list before writing plugins: enumerate model integration, tools, sessions, the loop, files, sandbox, approval, and prompt assembly as replaceable items, and specify the contract and failure semantics of each. Second, enforce paired registration: every registration returns a dispose function, and make this a hard check item in code review. Third, add validation for dependency declarations, detecting missing dependencies, cycles, and multiple-provider conflicts at startup rather than failing at runtime. Fourth, implement observability as a plugin capability, plugging in logging, metrics, and tracing themselves as plugins so they can be toggled on demand. Fifth, when deploying in the cloud, reuse common capability categories—for example, use object storage for sessions and artifacts, a message queue to decouple events, a container platform to host the sandbox, and logging and monitoring services for auditing and alerting—so the runtime stays neutral and portable.
8. Conclusion
The essence of “everything is a plugin” is to strip variability out of core code entirely and hand it over to composition rules. Temporal composability guarantees clean load/unload, spatial composability guarantees stable dependencies, and together they give the agent runtime true replaceability and evolvability. For developers, mastering the five concepts—plugins, context, service dependencies, typed events, and revocable side effects—means mastering the basic ruler for designing and reviewing this kind of architecture.
