Everything as a Plugin: Composable Runtime Architecture for Agent Harnesses
This article explores an “everything as a plugin” architecture for Agent Harnesses. It explains how to move from a fixed core to a composable runtime built on context, service registration, events, and lifecycle management; discusses spatial and temporal composability; and outlines practical governance boundaries for building flexible, safe, and operable agent runtimes.
In Agent-facing applications, the truly complex part is usually not a single model call but the complete runtime built around the model: how tools are registered, how files are accessed, how sessions are isolated, how tasks are scheduled, how approvals intervene, how exceptions are recovered, and how different Agents share or override capabilities.
If all these capabilities are written directly into a fixed core, the system may look simple early on, but as features grow, the core code expands rapidly. Model adapters, tool executors, context managers, permission validators, logging modules, and user interfaces reference one another, eventually forming a dependency network that is hard to separate. Any local change can affect the entire runtime.
The “everything as a plugin” idea is a remodelling of this problem: instead of predefining which business capabilities the system must include, it treats models, tools, sessions, sandboxes, file systems, Agent loops, scheduling mechanisms, and even UI as runtime units that can be installed, replaced, and composed. The core is responsible only for providing the basic semantics needed to compose these units.
1. From a Fixed Core to a Composable Runtime
Traditional architectures often use a “core plus extensions” approach. The core handles the main flow, and extension modules add capabilities. For example, the core may directly include:
- model invocation flow;
- tool registry;
- session state management;
- task execution loop;
- file read/write logic;
- error handling and log output.
This design has clear entry points and intuitive debugging, but its drawbacks are also obvious. Once the core takes on too many responsibilities, three problems appear.
First, the core becomes strongly coupled to business capabilities. Adding a model or a tool often requires modifying the central scheduling logic rather than simply adding an independent module.
Second, lifecycle management becomes difficult. A successfully initialized module does not mean the whole system has initialized successfully. If a later module fails to start, previously created connections, timers, temporary directories, and event listeners need to be cleaned up one by one.
Third, local customization becomes costly. A test environment may want to replace a model, an Agent may want to override a tool, or a session may want to use a different approval policy; each case may require special branches.
A plugin-based runtime turns these problems into composition problems. The system no longer assumes that “there must be a global tool table” or that “a fixed model must be used.” Instead, at startup, a plugin tree determines which capabilities the current instance has.
The overall relationship can be abstracted as:
Runtime instance├── Context├── Service registry├── Plugin tree│ ├── Model plugin│ ├── Tool plugin│ ├── Session plugin│ ├── Sandbox plugin│ └── Scheduling plugin├── Event system└── Lifecycle management
The key here is not the name “plugin,” but whether capabilities can be independently installed, replaced, revoked, and composed.
2. The Core Provides Mechanisms, Not All Business Logic
For a lightweight runtime suitable for Agents, the core layer can maintain only a few basic mechanisms.
1. Context
Context describes the runtime environment in which the current plugin operates. For example, it may contain the current scope, parent context, configuration, logger object, cancellation signal, and registered services.
The value of context is that services do not need to depend on global variables. A tool can obtain the model, permission policy, and file system from the current context instead of directly importing a singleton.
type RuntimeContext = {parent?: RuntimeContextconfig: Record<string, unknown>signal?: AbortSignalget<T>(key: string): T | undefinedprovide<T>(key: string, value: T): void}
The actual implementation does not necessarily use the interface above, but it should provide similar semantics: dependencies are resolved from the current environment, and child scopes can override some services from the parent scope.
2. Service Registration
Plugins usually publish capabilities through a service registry. Models, tools, session managers, and approvers can all become services.
interface Service {start?(ctx: RuntimeContext): void | Promise<void>stop?(ctx: RuntimeContext): void | Promise<void>}
A service registry is not just a dictionary. It also needs to handle the following questions:
- whether multiple instances of the same service are allowed;
- whether a child scope can override a parent scope;
- how dependents are notified when a service is revoked;
- how already started services are reclaimed if service initialization fails;
- whether services support lazy creation;
- whether services need to start by priority or dependency order.
Therefore, a registry is essentially a dynamic dependency environment, not a simple global container.
3. Event Dispatch
State changes in Agent systems are very frequent, such as model generation starting, tool invocation, tool completion, approval waiting, task cancellation, and session closure. An event mechanism can reduce direct calls between modules.
Events should clearly describe their data structure, trigger timing, and error strategy. For example:
type ToolEvent =| { type: "tool:start"; name: string; input: unknown }| { type: "tool:end"; name: string; output: unknown }| { type: "tool:error"; name: string; error: Error }
Event listeners also need cancellation support, so that listener relationships are not retained after a session ends, causing memory leaks or duplicate processing.
4. Lifecycle
The installation, startup, stop, and uninstall of plugins must follow a clear order. A typical process can be divided into:
- create the context;
- install plugins and declare services;
- resolve dependencies;
- start in dependency order;
- execute business tasks;
- trigger the stop flow;
- release resources in reverse order;
- destroy the scope.
Reverse-order release is important. Suppose a tool depends on a sandbox, and the sandbox depends on a file system. When stopping, the tool should be stopped first, then the sandbox, and finally the file system. Otherwise, the tool may continue executing after its dependency has already been destroyed.
3. What Does “Spatial and Temporal Composability” Mean?
“Spatial and temporal composability” can be understood along two dimensions.
Spatial Composition: Multiple Capabilities Cooperate in the Same Runtime
Spatial composition describes the structural relationships between plugins. An Agent can simultaneously have a model, tools, a file system, and an approver; a session can inherit host capabilities while overriding one service.
For example:
Host scope├── Default model├── Shared logging├── Shared configuration└── Agent scope├── Dedicated tools├── Restricted file system└── Overridden approval policy
A child scope does not need to copy all capabilities. It only needs to inherit from the parent scope and replace the parts that need to change. This mechanism is especially suitable for multi-Agent systems: different Agents can share infrastructure but use different tool sets and permission boundaries.
Temporal Composition: Capabilities Change Dynamically During Runtime
Temporal composition describes how plugins change over their lifecycle. Capabilities are not necessarily permanent after startup; they may be dynamically installed, temporarily enabled, replaced, or revoked.
For example:
- a tool is exposed only after approval;
- a model switches to a fallback model after reaching a quota;
- a temporary file system is automatically destroyed when a session ends;
- when a task is cancelled, its associated background executor stops immediately;
- when a plugin fails to initialize, the entire scope rolls back.
This means the runtime must treat “change” as a normal condition rather than an exception. When a service leaves the registry, components that depend on it should receive notification and take action, rather than continuing to hold stale references.
4. Why Agent Harness Is Especially Suited to a Plugin Architecture
The runtime process of an Agent Harness is usually not a fixed pipeline but a continuous loop:
Read context↓Invoke model↓Parse model output↓Decide whether to call tools↓Execute tools and collect results↓Update session state↓Continue the loop or end
In this loop, almost every step has room for variation:
- the model can be replaced;
- the tool set can change by task;
- tool parameters need permission validation;
- the file system may be a local directory, a temporary directory, or remote storage;
- sessions may need persistence or isolation;
- the loop may be interrupted by timeout, budget, or manual approval;
- the UI may subscribe to real-time events.
If a central class handles all these variations, it will eventually become a huge set of conditional branches. A plugin architecture can split each change point into an independent capability and connect them through context and events.
More importantly, an Agent’s capability boundary should often be determined by startup configuration rather than a fixed list in code. Different tasks can load different plugin trees, thereby forming different security boundaries and execution capabilities.
5. Solving Four Common Problems in Traditional Plugin Systems
1. Easy to Register, Hard to Revoke
Many systems focus only on “how to add a plugin” and ignore “how to safely remove a plugin.” Truly complete plugin semantics should record all side effects created by a plugin, including:
- service registration;
- event listeners;
- timers;
- background tasks;
- temporary files;
- child processes;
- network connections.
When a plugin stops, the runtime should reclaim resources uniformly according to the resource manifest, rather than requiring each business module to remember every cleanup action on its own.
2. Easy to Initialize, Hard to Roll Back on Failure
Plugin startup may fail at any stage. For example, the model may already be connected and tools may already be registered, but sandbox creation fails. At this point, the system cannot simply throw an exception; it must also undo the operations that have already been completed.
One reliable strategy is to maintain a cleanup stack for each plugin:
const cleanup: Array<() => void | Promise<void>> = []try {const connection = await connect()cleanup.push(() => connection.close())const listener = subscribe()cleanup.push(() => listener.dispose())} catch (error) {for (const dispose of cleanup.reverse()) {await dispose()}throw error}
The runtime can encapsulate this pattern uniformly, making it easier for plugin developers to follow consistent resource management rules.
3. Easy to Use Global Singletons, Hard to Override Locally
Global singletons are suitable for rapid development but not for multi-tenant, multi-session, and multi-Agent scenarios. Local scopes allow the same type of service to have different instances in different contexts.
For example, the host provides a default file system, one Agent uses a read-only file system, and a temporary task uses an isolated directory. The caller only needs to obtain the service from the current context and does not need to know which layer the service comes from.
4. Implicit Dependencies, Hard Fault Localization
Dependencies between plugins should be declared explicitly wherever possible. Explicit dependencies help the runtime perform:
- startup ordering;
- missing dependency detection;
- circular dependency identification;
- stop order calculation;
- fault scope determination.
When a tool fails to start, the system should be able to answer which services it depends on, which service failed to initialize, and which plugins were skipped as a result, instead of returning only a vague “startup failed.”
6. Governance Boundaries for Engineering Implementation
“Everything as a plugin” does not mean that all code should be split into plugins. Over-pluginization introduces new complexity, including longer debugging chains, weaker type relationships, harder-to-understand dependency graphs, and higher startup costs.
In practice, several principles can be followed.
First, stable and irreplaceable mechanisms should stay in the core, such as context, lifecycle, cancellation propagation, and error handling.
Second, capabilities that change frequently or require multiple implementations should become plugins, such as model adapters, tools, storage, approval, and UI.
Third, plugin interfaces should remain small and stable, avoiding exposing a large amount of internal detail to extension developers.
Fourth, plugins must have clear resource boundaries. Any connection, listener, task, and temporary file that is created should have a corresponding release path.
Fifth, security capabilities cannot rely only on plugin self-discipline. Tool calls, file access, process execution, and network access should all have permission constraints at the runtime layer.
Sixth, monitoring information should cover the plugin lifecycle, including installation, startup, stop, failure, reload, and resource reclamation. Only then does a dynamic system become operable.
7. Conclusion
“Everything as a plugin” is not about splitting code into more files. It is an architectural approach centered on runtime composition. It decouples business capabilities from a fixed core and distills context, service registration, event dispatch, dependency activation, lifecycle, and side-effect reclamation into general mechanisms.
For Agent Harness, this design is especially valuable. Models, tools, sessions, sandboxes, file systems, and scheduling strategies are all constantly changing. The system needs to support local overrides, dynamic start and stop, failure rollback, and scope isolation. The plugin tree provides a way to organize capabilities, while runtime semantics ensure that these capabilities can be composed and revoked safely.
Ultimately, a mature plugin-based Agent system should have the following characteristics: the core is small enough, capabilities are flexible enough, dependencies are clear enough, resource release is reliable enough, and runtime changes are controllable enough. Only when these conditions hold at the same time will “everything as a plugin” avoid becoming mere module splitting and truly become an architectural foundation for complex intelligent applications to evolve continuously.
