Why AI Agent Runtimes Choose an “Everything as a Plugin” Microkernel Architecture
An “everything as a plugin” design turns an AI Agent from a fixed execution loop into a dynamic capability runtime. This article explains how a small microkernel can manage context, dependencies, events, lifecycles, and side effects while model providers, tools, storage, sandboxes, approval workflows, and Agent loops remain replaceable plugins. It also examines reversible side effects, dynamic dependency composition, event-driven extensibility, engineering benefits, trade-offs, and practical implementation guidelines.
In traditional Agent frameworks, the execution path is usually relatively fixed:
- Receive user input.
- Assemble a prompt.
- Call a model.
- Parse the model output.
- Execute tools.
- Write to the session history.
- Decide whether to continue the loop.
This design is straightforward to implement. However, as functionality grows, the central execution flow gradually takes on more responsibilities. Eventually, it becomes a “central controller” that is difficult to replace, test, and maintain.
A more aggressive approach is to split the Agent runtime into a collection of dynamically loadable plugins. Model adapters, tool systems, session storage, Agent loops, filesystems, sandboxes, approval mechanisms, sub-Agent schedulers, and even prompt assembly are no longer treated as irreplaceable core code. Instead, they become capability modules managed by the runtime.
The architecture can be summarized as follows: keep the runtime kernel small enough, and move most business capabilities into plugins. The kernel does not determine what specific work gets done. Its responsibilities are managing context, dependencies, event propagation, lifecycles, and side effects.
1. From a Centralized Agent to a Composable Runtime
A traditional design often looks like this:
User request│Agent core loop├── Model invocation├── Tool selection├── Tool execution├── Session persistence├── Prompt assembly└── State management
This structure has a clear execution path, but it also has several obvious limitations:
- Changing the model integration may require changes to the core loop.
- Replacing session storage may affect multiple business modules.
- Adding remote tools, container sandboxes, or human approval introduces more branches into the core logic.
- It is difficult to replace one capability in isolation during testing.
- After a plugin is unloaded, its registered events, tools, and services may remain active.
- Modules can easily develop implicit dependencies on one another.
A plugin-based runtime attempts to reshape the system as follows:
Runtime kernel├── Context management├── Service registration and discovery├── Event system├── Plugin lifecycle management├── Dependency resolution└── Side-effect cleanupCapability plugins├── Model provider├── Tool provider├── Session storage├── Agent loop├── Filesystem├── Sandbox├── Approval service├── Sub-Agent scheduler└── Prompt extensions
The important change is not simply splitting the code into more files. It is redefining the relationships between components. Components no longer depend on a specific implementation. Instead, they depend on a capability.
For example, a file-reading tool does not need to know whether the underlying implementation uses a local directory, a remote file service, or an isolated container. It only needs to declare that it depends on a “file reading” capability.
2. What “Everything as a Plugin” Means
“Everything as a plugin” does not mean that every piece of code must be dynamically loaded, nor does it mean that the kernel has no functionality at all. More precisely, except for the most fundamental lifecycle and dependency-management capabilities of the runtime, other capabilities should generally be integrated through a unified plugin mechanism.
A plugin typically contains the following elements:
Plugin metadata├── Unique identifier├── Dependency declarations├── Initialization logic├── Capability registration├── Event listeners├── Configuration access└── Unload and cleanup logic
For example, a model plugin might register:
- A model invocation service
- Model capability metadata
- Request and response events
- Retry policies
- Usage metrics
- Error handlers
A tool plugin might register:
- The tool name and parameter schema
- The tool execution function
- Permission requirements
- Timeout policies
- Tool invocation events
- Audit log handlers
With a unified registration mechanism, the runtime can load different capabilities during startup or at runtime without modifying the Agent’s core logic.
3. The Most Important Design Principle: Reversible Side Effects
One of the most frequently overlooked issues in plugin systems is that unloading a plugin is not the same as deleting the plugin object.
During initialization, a plugin may create many side effects, including:
- Registering a tool
- Adding an event listener
- Providing a service
- Adding system prompt content
- Modifying configuration
- Creating scheduled tasks
- Establishing network connections
- Requesting filesystem or sandbox permissions
- Starting background worker threads
If unloading only removes the plugin object without cleaning up these side effects, the system can enter a ghost state. Tools may remain callable, listeners may fire repeatedly, outdated configuration may continue to take effect, and invalid services may still be referenced by other modules.
A mature plugin system should therefore require every registration operation to return a revocable handle:
const removeTool = runtime.tools.register(tool)const removeListener = runtime.events.on("model.response", handler)const removeService = runtime.services.provide("filesystem", fs)// During unloadremoveTool()removeListener()removeService()
The important principle is not the specific programming language. It is the constraint that registration and revocation must be paired. Plugin initialization may create side effects, but every side effect must have a clear cleanup path.
This approach can be described as reversible side-effect management. It provides three immediate benefits.
First, plugins can be safely replaced at runtime. For example, a local filesystem service can be switched to a remote filesystem service without restarting the entire process.
Second, test environments are easier to isolate. After a test completes, all registrations can be revoked, preventing state from leaking between tests.
Third, failure recovery becomes more reliable. If plugin initialization fails or a dependency is unavailable, the runtime can roll back registrations that have already been completed.
Ideally, plugin initialization should have transaction-like behavior:
Begin loading plugin├── Register services├── Register tools├── Register events└── Register prompt extensionsIf everything succeeds: commitIf any step fails: roll back in reverse order
4. Spatial Composability: Responding Automatically to Dependency Changes
Another core challenge in a plugin architecture is handling dynamic dependencies between components.
Suppose a tool depends on a filesystem, a sandbox, and an approval service. A traditional implementation might pass these objects directly when creating the tool:
createTool(localFileSystem, localSandbox, approvalService)
This approach is simple, but the dependency relationships are relatively rigid. If the filesystem is replaced, the tool may need to be recreated. If the approval service is temporarily unavailable, the tool may need to handle the situation with extensive conditional logic.
A more flexible approach is to let the tool declare which capabilities it needs instead of holding a fixed implementation:
Tool dependencies:- filesystem.read- sandbox.execute- approval.request
The runtime is then responsible for notifying relevant components when a service becomes available, disappears, or is replaced. The tool programs against capability interfaces and does not need to know which provider currently implements them.
For example, a filesystem capability could be provided by any of the following:
- A local directory
- A remote file service
- A filesystem inside an isolated container
- An enterprise filesystem with access controls
- An in-memory filesystem for testing
As long as these implementations satisfy the same capability contract, the tools above them do not need to change.
This can be understood as “spatial composability”: components can be freely composed within the runtime space. Dependencies are not bound only once during construction; they respond to changes in service availability and state.
5. An Event System Is Not a Logging System
In an Agent runtime, events are not used only for logging. They also provide an important mechanism for decoupling components.
Common events may include:
agent.startedagent.stoppedmodel.requestedmodel.respondedtool.beforeExecutetool.afterExecutesession.updatedapproval.requiredsandbox.createdplugin.loadedplugin.unloaded
Through events, plugins can extend behavior without modifying the core execution flow. For example:
- An audit plugin can listen for tool execution events.
- A monitoring plugin can listen for model request and response events.
- A prompt plugin can listen for prompt assembly events.
- A security plugin can check permissions before tool execution.
- A metrics plugin can record invocation counts and execution time.
However, the event system must be governed carefully. At a minimum, the following rules should be defined:
- Event names and payload structures should have stable contracts.
- Synchronous and asynchronous events should be distinguished.
- The runtime should define how listener failures are handled.
- Plugins should not create implicit circular dependencies through events.
- High-frequency events should support sampling, rate limiting, or batching.
- Sensitive data should be redacted and protected by access controls.
Events are suitable for expressing “what happened,” while services express “what capability I need.” The two concepts should not be completely mixed. If all dependencies are hidden inside events, the system becomes difficult to reason about and test.
6. The Agent Loop Can Also Be Replaced
The Agent loop is usually treated as a core part of the system. In a highly modular design, however, it can also become a replaceable component.
Different scenarios may require different loop strategies:
- Single-turn question answering
- Multi-turn tool use
- Separate planning and execution
- Streaming responses
- Parallel tool calls
- Multi-Agent collaboration
- High-risk tasks that require human confirmation
- Checkpoint recovery for long-running tasks
If the Agent loop is hard-coded into the runtime kernel, every new strategy may introduce a large number of additional branches. By abstracting the loop as a plugin, different implementations can share the same model, tool, session, and approval services.
A general-purpose loop can be represented as follows:
Read current session state↓Assemble model input↓Call the model↓Parse model output├── Return the result directly├── Request tool execution├── Request human approval└── Continue to the next round
The runtime provides capabilities and a scheduling environment. The plugin determines which loop strategy is used.
7. Engineering Benefits of This Architecture
1. Greater replaceability
Models, storage systems, and tool execution environments can be replaced independently without rewriting the entire system.
2. Clearer testing boundaries
In-memory sessions, virtual filesystems, and mock models can be used to build fast test environments with less reliance on real external resources.
3. Better support for multiple deployment models
The same Agent logic can run in a local process, on a server, inside a container, or in a restricted sandbox. Only the underlying capability plugins need to change.
4. Easier enterprise governance
Permissions, auditing, monitoring, rate limiting, and approval workflows can be integrated as independent plugins without invading business logic.
5. Support for incremental evolution
A system can start with simple implementations and gradually replace them with remote services, distributed storage, or more sophisticated scheduling components.
8. Complexity That Must Be Addressed
Plugin architectures are not beneficial in every respect.
First, debugging becomes more difficult. A problem may originate from plugin initialization, dependency resolution, event ordering, service replacement, or leftover asynchronous tasks. Developers therefore need comprehensive runtime diagnostics.
Second, lifecycle management becomes more demanding. A plugin must not only initialize successfully; it may also need to support pausing, resuming, unloading, and rollback.
Third, dependencies can form a complex graph. The runtime must identify circular dependencies, missing dependencies, and incompatible versions.
Overusing plugins can also reduce readability. If every small function is wrapped as a plugin, the system may contain too many indirect calls, making it difficult for developers to understand the execution path quickly.
A practical principle is to modularize capabilities that change frequently, need to be replaced, have an independent lifecycle, or are reused across different scenarios. Stable components that provide fundamental runtime guarantees should remain in the kernel.
9. Practical Design Recommendations
When building this type of system, consider the following steps:
- Define capability contracts before designing concrete implementations.
- Specify the plugin initialization, execution, and unloading phases.
- Make every registration operation return a revocable handle.
- Provide observable notifications when service dependencies change state.
- Version event structures and contracts.
- Include configuration, permissions, and lifecycle information in a unified context.
- Maintain a resource inventory for each plugin to support cleanup and auditing.
- Provide rollback when plugin loading fails.
- Record the dependency graph, event flow, and source of each service.
- Use mock implementations to verify that plugins are genuinely decoupled.
Conclusion
The value of an “everything as a plugin” architecture is not limited to making an Agent easier to extend. It changes how an intelligent system is organized.
The runtime kernel manages context, dependencies, events, and lifecycles. Specific capabilities exist as composable, replaceable, and revocable plugins.
This design transforms an Agent from a fixed process into a dynamic capability runtime. The model is only one type of capability provider. Tools, sessions, filesystems, sandboxes, and Agent loops can all be integrated under the same rules.
For Agent systems that must evolve over time, run across multiple environments, and meet strict governance requirements, a microkernel-style architecture offers strong engineering value. Its success, however, depends on solving several difficult problems at the same time: dependency visibility, lifecycle consistency, debugging complexity, and clear boundaries between plugins.
