Designing a Plugin-Based Agent Runtime
This article explains why agent runtimes fit a plugin-first architecture, how dynamic services and lifecycles address registration, rollback, scoping, and side effects, and how to compose models, tools, sessions, sandboxes, and UIs without a fixed business kernel.
As agent engineering moves from single LLM calls to long-running systems that can invoke tools, require approval, and execute in isolation, the runtime itself becomes part of the product. Model adapters, tool registration, session state, filesystem views, sandbox policies, loop scheduling, and interaction surfaces change frequently with each business scenario. If those capabilities live in an inseparable kernel, teams hit three problems: too few extension points, failures that cannot roll back cleanly, and no way to override behavior locally inside one process. A more thorough approach has been validated repeatedly: put all business capability in plugins, and keep the host limited to context, service registration, event dispatch, dependency activation, and side-effect cleanup.
Why agent runtimes fit a host with no fixed business kernel
Traditional desktop or middleware plugins extend at clear boundaries: menus, editors, protocol handlers. Agent runtimes are different. Change happens at every step on the timeline: a session needs extra tools, a loop needs a different approval policy, a sandbox needs a temporary read-only filesystem. Those needs are not covered by installing one large module. They require fine-grained, revocable, locally replaceable extensions.
The runtime should not prescribe which business components must exist. It should provide the construction semantics: who is activated and when, how dependencies are declared, how services are looked up, how events are broadcast, and how resources are reclaimed on unload. The domain layer then defines session, tools, model channels, agent loops, and similar services, and assembles the product from them. The relationship is closer to “runtime mechanics plus domain framework” than to “a generic plugin marketplace plus a bag of plugins.”
Historical experience: dynamic services and lifecycles are already mature
Plugins are not new. Early IDEs declared host extension points; other modules contributed menus and handlers through manifests. Modular specifications then configured install, start, stop, update, and uninstall for deployment units, and used a shared service registry for publish, lookup, and bind. When a service leaves the registry, dependents must handle the dynamic change or they keep dangling references.
Those designs leave a clear trail: dynamic services, lifecycle, registry, declarative dependencies, event notification. For in-process assembly of scripts and typed applications, heavy deployment-unit boundaries are unnecessary. An execution unit can shrink to a function or a service subclass; the extension surface can be typed services and events rather than a heavy structured manifest. That matters for agents: tools, prompt fragments, model adapters, and approval policies change quickly. If every extension must cross a heavyweight module boundary, teams bypass the framework and fall back to a few global arrays—the exact technical debt a plugin system is meant to avoid.
Four engineering pain points that must become runtime semantics
Being able to register is not enough. Practice keeps hitting four difficulties:
First, registration is easy, revocation is hard. Once tools, hooks, and routes are attached, leftover listeners and timers remain after unload, and sessions get dirtier over time.
Second, initialization is easy, failed rollback is hard. If one node in a plugin tree fails to construct, siblings that already took ports, file locks, or external connections must be reclaimed in reverse dependency order.
Third, global singletons are easy, local override is hard. Tests or canaries often need to replace a model channel or sandbox in one session without polluting the whole process.
Fourth, side effects are invisible. Log handles, temp directories, and event subscriptions that are not in a unified lifecycle cannot be released deterministically when a session ends.
Folding those difficulties into the runtime means activation and deactivation are first-class; the dependency graph is computable; scopes nest; unload must trigger symmetric cleanup. The domain layer then applies business constraints with sessions, agent instances, and presets—for example, “a class of tools is visible only after approval” or “a sandbox policy expires with the session.”
How spatiotemporal composition maps to code structure
Spatiotemporal composition has two axes. Space: plugins mount as a tree or graph; children see only services provided by ancestors, which naturally forms scope. Time: the same location can swap implementations at different moments; the old instance deactivates before the new one activates so observers see a consistent snapshot.
Common abstractions in practice:
- Context object: spans one activation, carrying scope, configuration, and cancellation.
- Service registry: publish and lookup by type and optional identity; emit change events when a service leaves.
- Dependency activation: declare required services; the runtime starts them in topological order; missing services fail and roll back.
- Event bus: typed events for extension instead of scattered callbacks.
- Side-effect accounting: file watches, child processes, and network connections are registered on the current execution unit and released together on stop.
Illustrative pseudocode (semantics only, not a specific framework API):
unit start(ctx):model = ctx.require(ModelChannel)tools = ctx.require(ToolRegistry)sub = ctx.events.on(TurnEnd, persist)ctx.onStop(() => sub.unsubscribe())session.scope.override(ModelChannel, MockChannel)session.activate(agentTree)
The keys are onStop and override: the former guarantees revocation, the latter local override. A test environment can inject a mock channel for a single session without changing the global default.
Pluginize models, tools, sessions, sandboxes, and UI
When the kernel no longer carries business logic, capability boundaries are defined by the plugin tree attached at startup:
- Model channel: request assembly, streaming, and retries; replaceable per vendor.
- Tools: declarative manifest plus executor; permission and argument checks are also plugins.
- Session: message history and memory policy, lifecycle bound to the user connection.
- Sandbox and filesystem: composable policies for which paths are readable and whether the network is allowed, not hard-coded in the loop.
- Agent loop and scheduling: think–act–observe cadence, concurrency caps, and timeouts should all be replaceable.
- UI: human confirmation and log panels are event-subscribing plugins, so headless and UI deployments share the same kernel mechanics.
In the cloud, object storage can hold session snapshots, message queues can schedule across instances, container platforms can isolate sandboxes, and logging plus alerting can observe plugin start/stop and failed rollback. Those are generic infrastructure categories; they do not change the principle that the runtime only manages composition semantics.
Engineering constraints: preset, session, and agent
A mechanism layer alone is too free. Three layers of business constraint are needed:
Preset: the default plugin tree and configuration—a versionable capability list.
Session: a scope for one user interaction, allowed to override some services from the preset.
Agent: binds goals, a tool subset, and loop policy inside the session.
Product change then means changing the tree, not the kernel. At release time, mechanism-layer source and domain layer can be locked to a known commit, with internal package-name mapping to avoid drifting external dependencies—a stability practice, not a new proprietary kernel.
Implementation advice and common mistakes
Start small: pluginize tool registration and the model channel first, then split sandbox and scheduling. Write deactivation tests for every execution unit; throw in the middle and assert no leaks. Do not keep global mutable arrays inside plugins. Document when services are provided and in what order they are destroyed, or spatiotemporal composition degenerates into implicit races.
Mistakes include treating plugins as arbitrary eval of dynamic scripts, using string conventions instead of typed services, and ignoring unload order so file locks remain. The right approach is for the type system to express the extension surface and for the runtime to express time and scope.
Conclusion
The value of “everything is a plugin” is not a slogan. It is making registration and revocation, initialization and rollback, global defaults and local override into reasoning-friendly runtime semantics. For continuously changing agent systems, a fixed business kernel ages quickly. A slim host that only maintains context, registry, events, dependencies, and cleanup, plus sessions and presets for constraint, balances evolution speed with engineering control. Design around the dependency graph, scopes, and side-effect accounting, and you can get a testable, canary-friendly, unloadable agent runtime without heavyweight module boundaries.
