Building a Plugin-Based Agent Runtime: Composable and Auditable Design
This article explains how to design a composable agent runtime built from plugins: a layered assembly model with base bundles, override bundles, and session-level mounts; a swappable agent loop factory; a logging principle that guarantees every model-visible input can be reconstructed; and a pattern for integrating external agents as sub-agent components. It closes with practical recommendations for keeping agent systems maintainable across multiple products and entry points.
Why Agents Need a Plugin-Based Runtime
The differences between agent products increasingly come down to how they combine tool sets, reasoning loops, model integrations, and safety policies. If every product writes its own orchestration logic from scratch, both feature reuse and team collaboration suffer. The plugin-based runtime approach works like this: the runtime itself is an empty plugin tree, into which a set of feature bundles is installed in order, followed by user patches. The result is a concrete agent product. The runtime defines the slots and lifecycle; a product is simply a set of choices made over those slots.
This structure delivers three immediate benefits. First, capabilities can be trimmed on demand—the same kernel can power a CLI assistant, a web assistant, and background batch jobs. Second, replacement costs stay low: swapping a model adapter or loop strategy leaves upper-layer tools and session management untouched. Third, configuration becomes structure—teams can describe, in versioned declaration files, which modules compose a product, making review and rollback straightforward.
Layered Assembly: Base Bundles, Override Bundles, and Session Mounts
Assembly order determines the final shape. Typically there are three layers.
Base bundle: provides general-purpose capabilities such as timers, model invocation interfaces, session management, persistent queries, the agent loop, tool registration, system prompts, sandboxing, approval policies, skills, goal management, plan mode, context compression, sub-agents, and workflows. The base bundle usually carries most of the slot declarations and forms the trunk of the plugin tree.
Override bundles: tailor behavior for a specific entry point. For example, a web client may disable several base-bundle tools unsuitable for a browser environment and mount its own interaction tools. The key to overriding is precise removal rather than wholesale replacement—otherwise shared capabilities that other modules depend on can be lost.
Session mounts: capabilities tied to a particular session, such as that session’s agent preset, should be mounted when the session is created, not hardcoded into the global tree. This way a single runtime can serve multiple entry points without interference, and resources can be released when a session ends.
The following sketch illustrates the structure (pseudocode only; it shows assembly order, not any concrete interface):
runtime = createEmptyTree()runtime.install(baseBundle)runtime.install(webBundle, overrides = ["tools.shell", "tools.fileWrite"])runtime.patch(userPatch)session = runtime.createSession(presetForWeb)
The Agent Loop as a Replaceable Factory
The agent loop is the most critical part of the system. Register it as a factory rather than a hardcoded singleton. The runtime only specifies that “creating an agent requires a loop factory”; the concrete loop implementation is supplied by a plugin. When the factory is missing, fail fast at creation time with a clear message such as “agent factory not registered,” instead of crashing later with an opaque null reference at runtime.
This design also simplifies testing. In tests, you can register a fake factory that returns a fixed sequence of actions, allowing unit tests to cover loop edge cases—tool call failures, rejected approvals, context limits—without depending on a real model.
Logs as Ground Truth: Everything the Model Sees Must Be Reconstructable
In agent systems, logs are often treated as a debugging afterthought, which is risky in production. A useful principle: everything visible to the model must be fully reconstructable from the logs. Every system prompt, tool result, user input, and compression summary that enters the model’s context should have a corresponding log record; conversely, anything not recorded in the logs should not appear in the model’s context.
This principle can be enforced with runtime assertions. For example, before each model request is constructed, compare the request contents against the log projection; on mismatch, abort the call and raise an alert. During incident retrospectives, the team can then replay exactly what the model saw directly from the logs, without relying on guesswork.
Integrating External Agents as Sub-Agent Components
The sub-agent mechanism lets a primary agent delegate subtasks to specialized executors. The executor does not have to be the same codebase—it can be an entirely separate agent program. By launching a subprocess over an inter-process protocol or calling its official SDK, an external agent can be wrapped as a component with a uniform interface. The main loop only cares about inputs, outputs, and state, and needs no knowledge of the executor’s internals.
Three things matter when integrating. First, permission boundaries: a sub-agent’s file and network access should be constrained by the parent session’s approval policy. Second, timeouts and cancellation: the subprocess must be interruptible and reclaimable to avoid zombie processes consuming resources. Third, result normalization: different executors emit different output formats, so the adapter layer should convert them into structured results before handing them to the main loop.
Practical Recommendations
- Define slots before writing implementations. Nail down the interface contracts for model integration, tools, loops, storage, and approvals, then develop the concrete plugins.
- Mount session-scoped capabilities at the session layer; keep only capabilities shared by all entry points in the global tree.
- Write regression tests for override operations so that a base-bundle upgrade cannot silently break overrides.
- Build a consistency check between logs and model context, and include it in your continuous integration pipeline.
- Put external components behind a unified adapter layer that centralizes permission control, timeouts, and result formatting.
The payoff of pluginization comes from clear boundaries. When every component has well-defined slots, permissions, and logs, an agent system can remain maintainable across multiple products and entry points.
