Microkernel Design and Practice in Plugin-Based AI Agent Frameworks

    This article explains how a plugin-based AI agent framework is organized around a microkernel. It covers the plugin contract, tool access with policy enforcement, task orchestration with tracing and cancellation, multi-model adapters, and interaction interfaces. It also explains why the "everything is a plugin" approach raises engineering complexity.

    Moving agent systems from demos to production often exposes a common misconception: that wrapping model calls is the whole framework. A model provides reasoning and generation. What determines whether a system can complete complex tasks is the runtime around the model. That runtime connects to real environments such as the file system, command execution, browsers, and code editors. It records what the agent has done, limits what the agent may not do, and decides whether to retry, degrade, or cancel when errors occur.

    The plugin-based agent framework discussed in this article is built around this runtime layer. It is neither a new model nor a chat client. It is an SDK and application framework for building, running, and extending agents. This article does not focus on a specific product. Instead, it looks at the general design problems of this class of frameworks, explains how “everything is a plugin” works in practice, and shows why it increases engineering complexity.

    1. Conceptual Boundary: From Model Client to Agent Runtime

    An agent framework must first be distinguished from a model client. A model client sends requests, receives responses, and handles streaming output. An agent runtime connects model capabilities to a workable system and imposes constraints on the entire process. The industry often compares such a runtime to a “harness” or a “constraint device.” One end connects to the model’s power, and the other end connects to external capabilities such as the file system, command execution, browsers, and editors. The runtime also handles recording, restriction, retries, and cancellation. This analogy points to three core design goals: connectability, controllability, and auditability.

    A complete framework usually includes a multi-model adapter layer, a tool integration layer, a task orchestration layer, a permission policy layer, a trajectory and logging layer, and several interaction entry points. The model adapter layer lets the framework switch between model providers. The tool integration layer wraps capabilities such as reading and writing files, running controlled commands, managing tasks, and assigning subtasks as callable tools. The interaction layer may support a web UI, a full-screen terminal, a headless command-line interface, and an automation protocol at the same time. Implementing these capabilities as plugins, instead of hard-coding them into the core, is the basic principle behind “everything is a plugin.”

    2. Microkernel: Keeping Only the Contracts That Cannot Be Plugins

    “Everything is a plugin” does not mean “there are no boundaries.” The more thoroughly a system uses plugins, the more precisely the microkernel must define its minimum contract. The kernel should not care how a tool executes, how a model is called, or how an interface is rendered. It should only handle plugin registration and discovery, lifecycle management, message routing, context passing, policy enforcement, and basic observability. Model adapters, tools, interfaces, protocols, and schedulers can all exist as plugins. The kernel, however, must keep control of permissions, resource quotas, the event bus, and audit entry points.

    A practical plugin contract typically includes an identifier, a version, capability declarations, lifecycle hooks, and event handling. Capability declarations matter most. Declaring a capability does not automatically grant permission. The plugin declares which scopes it requests, and the policy layer decides whether to allow them. The following pseudocode illustrates this:

    1. interface Plugin {
    2. id: string
    3. version: string
    4. capabilities: Capability[]
    5. onLoad(ctx: PluginContext): Promise<void>
    6. onEvent?(event: KernelEvent): Promise<void>
    7. onDispose?(): Promise<void>
    8. }
    9. interface Capability {
    10. kind: "tool" | "model" | "ui" | "protocol" | "scheduler"
    11. name: string
    12. scopes: string[]
    13. }

    After loading plugins, the kernel should build an index of plugins, capabilities, and scopes. Plugins should not hold global resources directly. All tool calls should pass through a single entry point that performs permission checks, parameter validation, timeout control, logging, and error mapping. With this design, adding a tool means adding a plugin, adding a model provider means adding an adapter, and adding an interaction mode means adding an entry plugin. The kernel rarely needs to change.

    3. Plugin Categories and Lifecycle: Extensibility Comes From Stable Boundaries

    The extensibility of a plugin-based framework comes from a stable lifecycle and clear plugin categories. Common plugin types include model adapters, tool plugins, interface plugins, protocol plugins, and scheduling plugins. Model adapters unify message formats, tool call requests, streaming events, and error semantics. Tool plugins wrap external capabilities as callable units with parameter schemas. Interface plugins display trajectories, approvals, and result previews. Protocol plugins convert external automation requests into kernel events. Scheduling plugins handle plan generation, subtask assignment, retries, and cancellation propagation.

    The lifecycle should include at least the loading, initialization, running, pausing, and disposal stages. During loading, a plugin receives a restricted context and cannot directly access arbitrary files or networks. After initialization, the kernel grants handles based on the plugin’s capability declarations and policies. While running, the plugin communicates with the kernel through events. On disposal, the plugin releases its resources and writes to the audit log. The main difficulty is not the number of interfaces. It is keeping boundaries consistent. Every plugin must access resources through the same context. Otherwise, the permission model and observability can be bypassed.

    4. Tool Integration and Constraint Layer: Connecting Capabilities to Real Environments

    The value of an agent framework lies in letting a model read projects, modify files, run controlled commands, manage tasks, and assign subtasks. The more capable the agent, the more important the constraints become. The tool integration layer should include three kinds of control. First, capability declarations: each tool must state whether it is read-only, writable, executable, or network-enabled. Second, policy checks: path allowlists, command allowlists, network domain policies, file read and write scopes, and resource quotas should all be checked before a call. Third, approval and auditing: high-risk operations can require manual approval, and every call should record its inputs, outputs, duration, result, and call chain.

    A common mistake is to write “do not delete files” in the prompt without enforcing it at runtime. A prompt is a suggestion. Policy is the boundary. The tool call entry point should apply logic like the following:

    1. function invoke(plugin, tool, args, ctx) {
    2. assert(plugin.capabilities.allows(tool))
    3. assert(ctx.policy.allows(tool, args))
    4. const span = ctx.trace.start(tool, args)
    5. try {
    6. return await ctx.sandbox.run(tool, args, ctx.quota)
    7. } catch (error) {
    8. return ctx.policy.onError(error)
    9. } finally {
    10. span.end()
    11. }
    12. }

    Sandboxing, least privilege, and default deny should be the default configuration. For file modifications, patch-based writes and diff previews are preferred. For command execution, limit the working directory, timeout, and output size. For network access, authorize by domain and purpose. These measures increase development cost, but they significantly reduce uncontrolled risk in long-running tasks.

    5. Task Orchestration: Turns, Steps, Trajectories, and Cancellation Propagation

    When an agent performs a complex task, its work is usually organized into turns, steps, and trajectories. A turn represents one user goal or one follow-up instruction. A step represents one model inference or one tool call. A trajectory is the observable record of the entire process. The orchestration layer maintains a loop of planning, execution, observation, and correction, and supports subtask assignment. A subtask is not just a split string. It is a schedulable unit that encapsulates its goal, dependencies, inputs, outputs, and cancellation signal.

    Cancellation and retries are the most underestimated parts of orchestration. A user may append instructions or cancel a task at any time. When a step is cancelled, its subtasks, tool calls, streaming output, and approval requests must all receive the cancellation signal. Retries must distinguish retryable errors from non-retryable ones to avoid duplicate writes, duplicate charges, or repeated side effects. Tools with side effects should use idempotency keys and operation logs. Long-running tasks should support checkpoints and recovery. Only when these mechanisms are part of the kernel contract do plugins avoid implementing inconsistent cancellation logic on their own.

    6. Multi-Model Adaptation and Interaction Modes: Unifying Semantics, Not Implementations

    The goal of the multi-model adapter layer is not to make all models behave the same. It is to confine their differences inside the adapters. Upper-layer orchestration only needs unified messages, tool calls, streaming events, usage information, and error categories. Adapters map the responses from different providers to these unified events. As a result, switching model providers does not require rewriting tools or orchestration logic. Developers only need to replace the adapter plugin and verify its capability differences.

    Interaction modes should also be pluggable. A web UI suits displaying trajectories, approvals, and result previews. A full-screen terminal suits developers who work interactively. A headless command-line interface suits automation scripts. An automation protocol suits connecting external system requests to the kernel. All entry points should share the same task state and audit log. This prevents situations where the UI can cancel a task but the command line cannot.

    7. Engineering Complexity: Why “Over-Design” Is a Necessary Cost

    When an agent searches several files at once, runs tests, accepts follow-up instructions, and allows cancellation at any time, the system quickly exposes concurrency, race conditions, idempotency, resource isolation, and auditing problems. In this situation, plugin contracts, policy layers, trajectory recording, and cancellation propagation may look like over-design. Yet they often become the components that incident investigators most wish they had. Large collaborative projects may involve hundreds of workspace members, and the amount of code and the number of edge cases grow at the same time. This is not about pursuing architectural elegance. It is a necessary condition for stable long-running tasks.

    8. Lessons From a Single-Prompt, Long-Task Demonstration

    In a controlled demonstration, a framework of this type driven by a smaller-parameter model completed two single-prompt tasks. The first task was generating a runnable first-person shooter web game. It required no manual intervention and produced a finished product in about thirty minutes. The trajectory showed about three turns and 127 steps, covering runtime and network environment checks, project planning, asset acquisition, rendering scene setup, and game logic implementation. The second task was reproducing a classic three-dimensional animation clip from a text description. With the same prompt, the output of a general-purpose baseline AI coding tool was less complete. These observations suggest that the constraint layer, tool integration, and orchestration strategy significantly affect how well a long task is completed. However, the results should not be attributed to the model alone, and they do not constitute a general performance guarantee.

    9. Implementation Checklist

    When building this type of framework, start by defining the minimum kernel contract, then expand the plugin ecosystem. Default the permission model to deny, and require approval for high-risk operations. Prioritize observability over feature accumulation, and design trajectories, logs, metrics, and audit records together. Give plugins versions and a compatibility policy to prevent the ecosystem from becoming unmanageable. Implement cancellation, retries, idempotency, and checkpoints uniformly in the orchestration layer. Multi-model adapters should unify semantics without hiding capability differences. All interaction entry points should share task state.

    If deployed on Baidu AI Cloud, a general-purpose container platform, object storage, a log service, and monitoring and alerting can serve as the runtime foundation. The core, however, remains the framework’s own plugin contract and constraint capabilities. Only when “connectable, controllable, and auditable” are built as kernel-level capabilities does “everything is a plugin” become a maintainable engineering system rather than a slogan.