Plugin Architecture for AI Agents: A Practical Guide to Pluggable Runtime Design

    This article explains how to design a pluggable runtime (harness) for AI agents so that capabilities can be added, replaced, or reordered without rewriting the core. It covers starting from an empty configuration tree, layering bundles and patches in order, replacing the agent loop and model adapters, reusing external agents as components, observability through logs, context management with layered summarization, cost and budget controls, sandboxing and approvals, and a recommended order for adopting each layer.

    1. Why Agents Need a Pluggable Runtime

    A common challenge in agent engineering is that as you add more capabilities, the code becomes harder to change. Tool registration, prompt assembly, session management, approval workflows, and subtask spawning become tightly coupled, eventually forming a monolith that can only be replaced as a whole. The goal of a pluggable runtime (harness) is to break these capabilities into independent plugin units that can be stacked in order, so the product can “grow” on top of the core rather than being “written into” it.

    A mature plugin-based design usually rests on three premises:

    • The core provides only lifecycle management and dependency assembly, with no built-in business capabilities.
    • All capabilities are described through declarative configuration and merged in order at startup.
    • Any capability can be disabled, replaced, or reordered, and failures can be traced.

    2. Core Mechanism: Start Empty and Layer in Order

    The key convention of a pluggable runtime is to “start empty.” When the process starts, the root of the configuration is forcibly reset to an empty list, then base capability bundles and user patches are layered on in a fixed order. The benefit is reproducibility: regardless of what state the previous run left behind, the starting point for this assembly is always identical.

    A schematic configuration looks like this:

    1. # Reset to an empty list at startup to ensure reproducibility
    2. root: []
    3. # Layer order defines priority; later layers can override or disable earlier ones
    4. layers:
    5. - bundle: base # Base capabilities
    6. - bundle: webPreset # Session-level preset
    7. - patch: user.overlay # User patch

    A base capability bundle typically brings in about a dozen modules at once: scheduled tasks, a model invocation abstraction layer with several adapters, session management, structured query storage, the agent and reasoning loop, tool sets and system prompts, sandbox isolation, approval policies, a skill library, goal and plan modes, context compression, subtasks, workflow orchestration, retrieval augmentation, and more.

    One notable design is the “session-level preset override.” When a preset for browser interaction is mounted, it disables a batch of tool entries from the base bundle and then inserts its own set of tools. This means the same runtime exposes a different set of capabilities to the model depending on the mount point—tools do not live in the host tree, but in the preset assembled for each session.

    3. Replaceable Reasoning Loop and Model Adapters

    The reasoning loop (agent loop) itself should be implemented as a factory and registered during the side-effect assembly phase. Once this plugin is uninstalled, the factory slot is empty, and creating an agent throws an “unregistered agent factory” error directly. This kind of explicit failure is better than silent degradation, as it surfaces configuration problems immediately.

    The model adapter layer works the same way: wrap the invocation protocols of different vendors as adapter plugins, and the core depends only on a unified abstraction. Adding a new model service then requires only a new adapter and its configuration, without touching the loop logic.

    4. Reusing External Agents as Components

    An interesting engineering practice is to build in multiple sub-agent providers: some connect to external agent runtimes as subprocesses through a standard protocol, while others connect through official SDKs. The essence is to plug external capabilities into your own plugin tree as parts, rather than merely “importing configuration.”

    This brings two takeaways:

    1. Capability boundaries are defined by protocols, not by code coupling.
    2. Reusing mature external implementations can significantly reduce in-house development costs while keeping the overall architecture consistent.

    5. Observability: Logs as the Source of Truth

    As the number of plugins grows, the biggest risk is “not being able to see.” A strong rule is: visible to the model if and only if logged. Anything that enters the model’s context must be fully reconstructable from logs, backed by runtime assertions.

    Implementation suggestions:

    • Log an input context snapshot, tool calls and returns, and approval decisions for each request.
    • Add assertions for key invariants, such as the tool whitelist and context length limits.
    • Connect logs to a general logging service and monitoring alerts to form a traceable chain.

    6. Context Management: Deciding How Long a Session Can Run

    The bottleneck for long sessions is often not compute, but context. Layered summarization is a common approach: compress consumed conversation into multi-level summaries, keeping decisions and constraints while discarding redundant details. When evaluating, do not just look at “how many tokens were saved”; focus on two metrics:

    • Whether the prefix cache hit rate can stay at a high level (a healthy session can usually maintain over 90%);
    • Whether the overhead of compression itself is low enough (generally kept within single-digit percentages).

    Pseudocode:

    1. def on_turn_end(session):
    2. if session.tokens > HIGH_WATER:
    3. summary = summarize(session.recent, keep=["goal", "constraints"])
    4. session.history = [summary] + session.recent[-KEEP_N:]
    5. session.cache_hint = "prefix_stable" # Keep the prefix as stable as possible

    Keeping the prefix stable is key to improving the cache hit rate; the compression strategy should avoid frequently rewriting the earliest context segments.

    7. Cost and Budget: Accounting at the Session Level

    Cost plugins typically cover session cost, daily cumulative totals, budget caps, and balance alerts, and support time-based pricing. Design recommendations:

    • Aggregate by both session and user dimensions to make it easier to locate high-consumption sources.
    • Use tiered alerts for budget thresholds; automatically downgrade the model or trigger compression when approaching the limit.
    • Connect cost data with logs to achieve a “reproducible bill.”

    8. Permissions, Sandboxing, and Approvals

    The stronger the tools, the more boundaries are needed. The sandbox isolates the execution environment, and the approval policy decides whether high-risk actions require human confirmation. The recommended approach is to deny by default and allow as needed, and write approval records into logs to form a complete audit chain.

    • Layer 1, observability: context inspector panel, real-time card view, cost metering.
    • Layer 2, context: layered summarization, prefix stability optimization.
    • Layer 3, capability expansion: skill library, plan mode, subtasks, and workflows.
    • Layer 4, ecosystem integration: reuse external runtimes through standard protocols.

    10. Conclusion

    The value of a plugin-based approach lies not in “having many plugins,” but in a core that can be replaced and capabilities that can be recombined in a data-driven way. When the reasoning loop, model adapters, and tool sets all exist as plugin entries, the same runtime can grow agents of very different shapes. If you are designing your own agent platform, start with these three principles: start empty, layer in order, and logs as the source of truth.