Architectural Lessons from a Plugin-Based Agent Runtime
This article explores the architectural principles behind agent runtimes built on an "everything is a plugin" model. It explains why a minimal kernel handling context, service registration, event dispatch, dependency-based activation, and side-effect cleanup enables safer dynamic extensibility than monolithic designs. Topics include making capabilities revocable rather than merely extensible, choosing lightweight execution units over heavy module boundaries, enforcing session, agent-loop, and preset constraints, designing scoped overrides and failure rollback, and a practical implementation checklist for teams building agent platforms.
Architectural Lessons from a Plugin-Based Agent Runtime
Over the past two years, agent systems have evolved from “single LLM calls” into continuously running systems with long sessions, multiple tools, approval workflows, and rollback support. Many teams initially stack capabilities into a single process: model adapters live in one module, tool calls in another directory, session state is scattered across global objects, and UI events are handled separately. This works when features are few, but as requirements grow, familiar symptoms appear: adding capabilities is easy, safely removing them is hard; the initialization path is clear, but failure recovery is vague; global sharing is convenient, but local overrides are painful.
The value of “everything as a plugin” is not fragmenting directories further—it is making “adding, replacing, pausing, and revoking capabilities” first-class runtime semantics. Some recent agent orchestration frameworks in the industry follow this approach: they keep no fixed kernel carrying business capabilities, only context, service registration, event dispatch, dependency-based activation, and side-effect cleanup. What the system can do depends entirely on the plugin tree mounted at startup. Stripping away any specific project name, what is truly worth discussing is a reproducible set of engineering methods.
From “Extensible” to “Revocable”
Traditional plugin mechanisms usually solve “how to be discovered” but rarely answer “how to be safely removed.” Registering a menu, a command, or a tool typically just appends an entry to a list. But when that plugin’s timers, file handles, network connections, subscriptions, or temporary permissions need to be reclaimed, the code often relies on author discipline. Early plugin-based desktop platforms established the paradigm of hosts declaring extension points and plugins contributing capabilities; enterprise-grade dynamic modularity solutions went further, emphasizing install, start, stop, update, and uninstall lifecycles, and requiring dependents to respond when a service disappears. These historical lessons show that the real difficulty of plugin systems is not extension—it is dynamism.
Agent scenarios amplify dynamism. Model providers may switch, tool sets vary by tenant, approval policies adjust with risk level, prompt fragments need gradual rollouts, and sandbox resources must be released on time. If every change requires crossing heavyweight module boundaries, teams will quickly bypass the framework and fall back to a few global arrays and hand-written switches. Conversely, only when the runtime makes revocation semantics thin and hard can the business layer dare to build capabilities as replaceable plugins.
The Fixed Kernel Steps Back, Runtime Semantics Step Forward
The core of this design is that the kernel holds no business capabilities. The kernel is responsible for exactly five things:
- Context: providing isolated key-value spaces with lifecycle boundaries for each session, task, or tenant.
- Service registration: capabilities are published as contracts, not hard-wired through object references.
- Event dispatch: state changes propagate via events; subscribers can unsubscribe, and publishers never assume subscribers exist.
- Dependency activation: plugins declare what they need; the runtime starts them in dependency-graph order and rejects or degrades when dependencies are missing.
- Side-effect cleanup: plugins return disposable handles; shutdown cleans up in reverse order, and failures roll back along the activated path.
A minimal skeleton can be expressed in language-agnostic pseudocode:
plugin define(name, requires[], activate, deactivate):registry.assertContracts(requires)ctx = context.child(name)resources = []try:for dep in topoSort(requires):ctx.inject(dep, registry.get(dep))handle = activate(ctx)resources.push(handle)registry.publish(name, handle.api, onLost: deactivate)return ok(dispose: () -> reverse(resources).each(close))catch err:reverse(resources).each(closeQuietly)ctx.destroy()return fail(err)
The point here is not the API shape—it is that the activate function must produce a “disposable object.” Any capability whose cleanup logic cannot be expressed in deactivate should not enter the plugin tree directly; it must first be wrapped in an adapter with timeouts, cancellation tokens, and resource limits.
Lightweight Execution Units Matter More Than Heavy Module Boundaries
In historical solutions, deployment units tend to be heavy: modules, lifecycles, services, and security policies are managed in layers, which suits large applications and strong governance environments. Agent runtimes face high-frequency, small-step changes: a tool function, a prompt fragment, a model adapter, or an approval rule can each become a plugin. If every change demands a full module manifest, an independent package boundary, and complex permission files, the cost of experimentation will swallow the architectural gains.
A more suitable granularity is the “lightweight execution unit”: a single function or a small class implementing a service contract can be plugged in. It has four properties simultaneously: locatable—it knows which node of the plugin tree it hangs from; dependent—it declares which services it consumes; replaceable—it can be locally overridden under the same contract; and disposable—it leaves no background side effects after stopping. Lightweight does not mean arbitrary: the boundary shifts from “files and packages” to “contracts and lifecycles.”
This explains why some frameworks describe themselves as “meta-frameworks” rather than product frameworks: they do not prescribe which components an agent, web service, or bot should have—they only provide the spatiotemporal semantics for assembling components. “Time” refers to the ordering of start, run, pause, failure, rollback, and unload; “space” refers to visibility isolation across global, session, tenant, and single-invocation scopes. Domain frameworks then define services such as sessions, tools, models, policies, and agent loops on top, and assemble the product.
Sessions, Agents, and Presets Complete the Business Constraints
Runtime semantics alone can guarantee “plugins can be correctly loaded and unloaded,” but not “loaded sensibly.” The domain layer must supply three categories of constraints.
First, session constraints. Each session holds an independent context, and plugin instances are derived per session by default, preventing one user’s file handles, approval tokens, and cached conclusions from leaking to the next user. Global services should hold only stateless or explicitly shared capabilities; stateful capabilities must declare their scope.
Second, agent loop constraints. Planning, tool selection, parameter construction, execution, observation, retry, and termination should all be treated as orchestrable stages. Any stage may be replaced by a plugin, but the loop itself must maintain invariants: any tool output must be sanitized before entering the model; any write operation must pass through policy evaluation; and every loop must have step, time, and cost limits.
Third, preset constraints. A preset is not a simple configuration item but a policy package defining “which plugins may enter the tree, how overrides are ordered, and how conflicts are resolved.” For example, a developer-assistant preset opens code search but disables production write APIs; a customer-service preset allows knowledge-base reads but mandates human approval for outbound messages; an offline-evaluation preset pins model versions and records the complete event trace. Presets turn the plugin tree from “can be assembled” into “can be assembled according to governance goals.”
Design Points for Scoped Overrides and Failure Rollback
Global singletons are easy; scoped overrides are hard, because overrides change dependency resolution results. Usable rules should be explicit: nearer scopes take precedence; multiple implementations of the same contract must be explicitly named; overrides affect only instances created after the override point; and already-running instances keep referencing the old implementation until they finish naturally, avoiding half-new, half-old states. For long sessions, you must also decide the “hot-swap strategy”: should it take effect on the next message immediately, only at task boundaries, or only after user-confirmed migration?
Failure rollback should proceed in reverse activation order and distinguish three failure types. Startup failures should prevent the plugin from entering the available registry. Runtime failures should be isolated to the current task and trigger degradation. Unload failures must enter resource-leak monitoring—you must not pretend cleanup succeeded just because an object is unreachable. In practice, it is advisable to unify the cleanup interface, the cancellation token, and the timeout budget, and to record every activation and release as an audit event. When integrating general-purpose cloud capabilities, audit records can go to a logging service, resource watermarks to monitoring and alerting, long-running tasks to a container platform, and artifacts to object storage—these are all generic categories and should not be bound to specific proprietary interfaces.
Implementation Checklist
- Does every plugin depend only on contracts, not on globally reachable paths to concrete implementations?
- Does activate always return a corresponding dispose, and is dispose idempotent?
- Are there any polls, callbacks, or child processes that cannot be cancelled at stop time?
- Do override rules support tenant-level, session-level, and single-task granularity?
- Are event subscriptions automatically unsubscribed when their context is destroyed?
- Are tool write operations forced through approval and parameter validation?
- Can presets express whitelists, version pinning, conflict resolution, and degradation chains?
- Are startup, runtime, and unload failures recorded separately and replayable?
- Can critical state be rebuilt from the event stream rather than trusting only in-memory snapshots?
- Does performance observability distinguish plugin initialization time, waiting time, and external call time?
Conclusion
Building an agent system as “everything is a plugin” essentially means migrating change from the release window into the runtime, and migrating part of the trust from code review into executable constraints. It is no silver bullet: contract design moves earlier, debugging relies more on event tracing, and testing must cover combinatorial explosion. But when tools, models, policies, and interfaces are all changing rapidly, an architecture with registration, dependencies, events, lifecycle, and cleanup as its minimal kernel tends to outlive a feature-rich but irrevocable monolith. For teams building intelligent coding, knowledge Q&A, or operations automation platforms, what is truly worth borrowing is not any particular name, but this principle: capabilities can be pluginized; responsibilities must be kernelized.
