Pluggable Agent Architecture: Plugin Design and Practice

    This article explains how to build a pluggable agent runtime where capabilities are assembled from plugin entries instead of being hardcoded into a monolith. It covers the empty-tree startup model, order-dependent loading, capability disabling and factory replacement, observability and cost plugins, context governance metrics, sub-agent orchestration, logging consistency, and practical pitfalls to avoid.

    1. Why Agent Products Need to Be Assembleable

    Over the past year, agents have moved from demos into production, and engineering complexity has risen quickly: tool counts keep growing, context overflows fast, invocation costs are hard to control, subtasks are difficult to parallelize, and behavior is hard to reproduce. The traditional approach hardcodes all of these capabilities into a single monolithic framework, so any single change ripples across the whole system and teams cannot evolve in parallel.

    A more reasonable approach is to treat the agent runtime as an assembleable foundation: the foundation provides only lifecycle management, dependency injection, and plugin loading, while concrete capabilities are layered on as plugin entries. Product shape is then determined not by code branches but by which plugins are loaded and in what order.

    2. Core Mechanism: Start from an Empty Tree and Layer in Order

    A typical pluggable runtime resets the configuration root to an empty list at startup, so no preset product definition is inherited implicitly:

    1. # After the runtime starts, the root config is always rewritten as empty
    2. plugins: []

    The product is something layered on top. The base layer inserts a few dozen capability entries at once, covering: timers, the model invocation seam with two types of adapters, session management, structured query storage, agents and the main loop, tool sets and system prompts, sandbox isolation, approval policies, skills, goals, plan mode, context compaction, sub-agents, workflows, and web retrieval.

    Three architectural constraints matter:

    1. Order is semantics. Load order determines dependency visibility, and a later entry can disable or replace the capability entries of an earlier one.
    2. Capabilities can be disabled. An upper layer can explicitly turn off a number of tool entries from the base layer and insert its own implementations. For example, a layer targeting web scenarios disables more than twenty tool entries from the base layer and inserts sixty-plus of its own; this means the web-side tools do not live in the host tree but in the agent preset mounted for each session.
    3. Factories can be replaced. The main loop is usually registered as a factory in a side-effect context; once it is unloaded, the slot is empty and agent creation fails immediately with an “agent factory not registered” error. This fail-fast behavior is an advantage: it surfaces missing dependencies at startup rather than silently degrading at runtime.

    3. Observability Plugins: See First, Optimize Later

    All governance begins with visibility. The first category worth recommending is context-inspection plugins, which typically provide a cross-session insights page, a context tab, a sidebar panel, a slash command, and a “formation view” that draws a live card for the current agent, its parent, and each sub-agent. Their value is pairing the logs, the source of truth, with a dashboard that makes token distribution, tool call frequency, and failure points clear at a glance.

    The second category is cost metering plugins, responsible for session cost, daily cumulative spend, budget caps, and balance display, with support for peak and off-peak pricing. In engineering terms, the budget should be an executable guardrail: trigger compaction or model downgrade near a threshold, and reject new tasks when the limit is exceeded, rather than reflecting this only in after-the-fact reports.

    4. Context Governance: What Determines How Long a Session Can Run

    Context is a scarce resource. A layered summarization plugin compresses consumed conversation into multi-level summaries while keeping traceable references. When evaluating such capabilities, two metrics matter more than “saves several times the tokens”:

    • The prefix cache hit rate for healthy sessions should stay above 95%.
    • The overhead of the compaction action itself should be kept within 2% of total consumption.

    A sharp drop in cache hit rate means compaction broke prefix stability; excessive compaction overhead means summaries are triggered too often or the summarization model is too heavy. The practical recommendation is a “stable prefix plus tail increments” structure, with summaries triggered only at session boundaries or thresholds, and tool output trimmed structurally rather than rewritten in natural language.

    5. Sub-Agent Orchestration: Treat External Implementations as Parts

    A mature runtime ships with several sub-agent providers, two of which are instructive: one launches subprocesses through the server-side protocol of an external coding agent, and another connects through an official agent software development kit. Their significance is not “compatibility with a configuration format” but mounting external implementations into your own plugin tree as replaceable components in orchestration.

    This yields three engineering benefits: heterogeneous capabilities can coexist in the same session tree; tasks can be routed to different implementations by characteristic; and any implementation can be replaced without affecting upper-layer workflows. Implementation requires attention to process isolation, timeout and cancellation propagation, structured result return, and peer-level permission boundaries.

    6. Logging and Consistency: If the Model Can See It, It Can Be Rebuilt

    The logging rule can be condensed into one sentence: the model sees something if and only if it is logged. That is, anything entering the model context must be fully reconstructable from the logs, and runtime assertions should validate this continuously. This guarantees three things: failures can be reviewed, evaluations can be replayed, and audits can be delivered.

    In implementation, attach a session identifier, level identifier, content hash, and causal pointer to each record to form a traceable chain; for lossy operations such as compaction and tool trimming, keep the original references so they can be read back on demand.

    7. Implementation Advice and Common Pitfalls

    1. Build observability and logging first, then plugin expansion; otherwise optimization has no basis.
    2. Drive load order with a capability list, and write “disable then replace” as explicit configuration to avoid implicit overrides.
    3. Make budget, sandbox, and approval policies non-bypassable foundation capabilities.
    4. Pitfall one: more plugins is better. The real goal is for one runtime to grow different agents.
    5. Pitfall two: judging quality by compression ratio. Look at cache hit rate and task success rate instead.

    In engineering practice on cloud platforms such as Baidu AI Cloud, you can combine a container platform to host the runtime, logging services with monitoring and alerting to close the observability loop, and object storage to keep replayable corpora, so the pluggable architecture lands stably in production.