Pluggable Agent Architecture: A Practical Guide to Plugin Design

    This article explores how to build a pluggable agent architecture where the runtime acts as a host and product capabilities are layered in as plugins. It covers the assembly mechanism and ordering semantics, the key replacement points that make the core swappable, observability as the single source of truth, context governance for longer sessions, and a step-by-step rollout plan with a risk checklist. The core takeaway is that value comes not from the number of plugins but from four enforced constraints: start with an empty tree, layer in a strict order, keep the core replaceable, and make logs fully reconstructable.

    1. Background: Why Agent Products Need to Be Pluggable

    In real engineering practice, agent products often face a conflict: business teams want to customize behavior quickly, while the platform team must guarantee runtime stability and auditability. The traditional approach hard-codes prompts, tools, and orchestration logic into a monolithic service. As a result, every customization requires changing core code, regression costs are high, and issues are hard to locate.

    A more mature approach is to make the runtime a “host” and build product capabilities as a stackable plugin layer. The core convention is simple: when the host starts, it keeps an empty plugin tree, and all capabilities are layered in according to a defined order. In implementation, the configuration file is rewritten to an empty list during startup, and the product shape is determined entirely by the layering order:

    1. # Forced to reset to empty at startup to avoid any implicit default capabilities
    2. plugins: []

    The benefits are explicit: clear capability boundaries, controllable load order, and rollback by unloading. The rest of this article covers four layers: the assembly mechanism, replacement points, observability, and context governance.

    2. Assembly Mechanism: Layered Stacking and Ordering Semantics

    The key to a plugin system is not “many plugins” but “strict stacking semantics.” Engineering practice usually divides this into three layers:

    1. Base layer: Inject the minimum viable capability set once, for example scheduled tasks, model invocation seams, session management, local persistence queries, agents and loops, tools and system prompts, sandbox, approval policies, skills, goals, plan mode, context compaction, sub-agents, workflows, and retrieval capabilities. This layer aims to “run a full loop out of the box.”
    2. Shape layer: Layer capabilities differently for different interaction shapes. For example, an interactive terminal shape and a browser shape have different tool requirements; the latter often disables some tool rows from the base layer and then inserts its own set of tool rows. This means shape-specific tools do not live in the host tree but take effect in the preset mounted for each session.
    3. User layer: User patches are layered last, used to override policies, inject business tools, and adjust prompts and approval thresholds.

    Order is semantics, which brings two constraints that must be enforced. First, a later-loaded item can override a same-named item loaded earlier, so “who comes later” is the final arbiter. Second, after unloading a capability, any capability that depends on it must fail explicitly at creation time rather than silently degrade. For example, the loop scheduler itself is a factory registered in a side-effect hook. Once it is removed, the slot is empty, and creating an agent should directly report “unregistered agent factory,” exposing the problem at startup rather than at runtime.

    3. Replacement Points: Making the “Core” a Plugin Row Too

    The standard for judging whether an architecture is truly pluggable is whether the core is replaceable. Mature implementations typically make the following four categories into plugin rows:

    • Model adaptation: Model integrations with different protocols and authentication methods exist as adapters. Replacing the adapter switches the backend without touching orchestration logic.
    • Loop scheduling: The reasoning-action-observation loop is registered by a factory. Replacing the factory changes the execution strategy (such as multi-round reflection or parallel branches).
    • Tool sets and sandbox: Tool declarations and execution isolation policies are separated, making it easy to reuse the same tool definitions across different trust domains.
    • Sub-agent sources: Multiple built-in sub-agent providers are available, and external AI coding tools can be treated as “parts,” launched as child processes through their service protocols or integrated through official SDKs. The essence is to mount external agents into your own plugin tree as components, rather than a simple configuration import.

    The analogy for this design is a “data-driven sandbox world”: blocks, creatures, rendering, and physics rules are all data and can be rewritten down to the core. Similarly, loops and model adapters in the runtime are replaceable plugin rows, and the same host can grow agents with completely different shapes.

    4. Observability: Logs as the Single Source of Truth

    After pluginization, the biggest risk is “invisibility.” Engineering practice should establish one iron rule: model-visible if and only if logged (Model-visible ⟺ Logged). This means anything that enters the model context must be fully reconstructable from logs, with runtime assertions to verify it and prevent a black hole where “the model saw it but the logs did not.”

    Around this iron rule, the first layer of the plugin ecosystem is always observability:

    • Context perspective plugin: Provides cross-session insight pages, context tabs, side panels, and slash commands, and uses a “fleet page” to draw a real-time card for the current agent, its parent, and each sub-agent. It is effectively a dashboard for the logs.
    • Cost metering plugin: Tracks session cost, daily cost, budget caps, and balance, and supports peak/off-peak pricing. It extends “observability” from a technical metric to a business metric.

    Selection advice: Prefer read-only observability plugins that do not rewrite context, to avoid the observation behavior itself polluting the source of truth.

    5. Context Governance: Determining How Long a Session Can Run

    The second layer is the context layer, which directly determines the usable duration and cost curve of a single session. The core technique is layered summarization: compress consumed conversation into multi-level summaries, retaining decisions and constraints while discarding redundant pleasantries and repeated observations.

    When evaluating such plugins, do not just look at the marketing claim of “saving X times the tokens.” Instead, look at two engineering metrics:

    1. Prefix cache hit rate: A healthy session should stay in the 95%–97% range over the long term. A low hit rate means compaction has broken prefix stability and actually increased costs.
    2. Compaction overhead: The cost of the compaction action itself should be kept within 2%; otherwise the gains are eaten up.

    Illustrative decision logic:

    1. if prefix_cache_hit_rate < 0.95: disable auto-compaction, switch to manual compaction by stage
    2. elif compaction_cost_ratio > 0.02: reduce compaction frequency or switch to a lighter summarization model
    3. else: keep layered summarization + plan mode working together

    6. Rollout Roadmap and Risk Checklist

    The recommended approach is four steps:

    1. Establish the source of truth first: Connect logs and runtime assertions to ensure model-visible content is reconstructable.
    2. Add observability next: Deploy context perspective and cost metering to form a “technical + business” dual dashboard.
    3. Then govern context: Introduce layered summarization, using hit rate and compaction overhead as the two gate metrics.
    4. Finally, differentiate shapes: Mount shape-specific tools via presets to avoid polluting the host tree.

    The risk checklist is equally clear: lack of version management for plugin stacking order leads to behavior drift; failing to explicitly fail when unloading core capabilities causes runtime null pointers; observability plugins writing back to context break the source of truth; conflicts between compaction strategy and plan mode cause goal loss. For each of these, it should be locked down at startup with assertions or validation.

    In summary, the value of a pluggable agent architecture lies not in the number of plugins but in whether these four constraints are strictly enforced: start with an empty tree, layer in order, keep the core replaceable, and make logs reconstructable. Putting observability and context governance first, before discussing shape and tool extensions, allows the same runtime to stably host multiple agent product shapes and lays the foundation for unified operations on common cloud capabilities such as container platforms, log services, and monitoring and alerting.