Pluggable Agent Runtime Architecture: Design and Practice
This article explains how to design a pluggable agent runtime by treating the main agent loop itself as a replaceable component, rather than only exposing tool slots. It covers a layered architecture with dependency inversion, reversibility constraints for plugins, sandbox and execution security, session persistence and recovery, and how to build an evaluation baseline. It also outlines which teams are suited to adopting this approach and which scenarios are not.
1. Background: Why Agent Frameworks Are Moving Toward Replaceability
Since 2026, intelligent coding and general-purpose agent frameworks have entered a period of rapid iteration. A common pattern is that most solutions treat “tool calling” as the only extension point, while the main loop, model integration, and session storage are hard-coded inside the framework. This creates three engineering pain points.
First, lock-in risk. Once models, runtimes, and storage are coupled to the framework, replacement becomes costly, making evaluation and canary rollouts difficult.
Second, uncontrolled side effects. After plugins write files, register tools, or modify configuration, uninstalling them often leaves dirty state behind.
Third, no self-extension. An agent cannot add capabilities for itself without restarting or breaking the session.
The core premise of a pluggable runtime is to treat the main loop itself as a replaceable component, not just to open up tool slots.
2. Layered Design: Making the Loop a Plugin Too
A mature runtime is typically divided into five layers, each independently replaceable:
Access layer (model adapters) -> Orchestration layer (agent loop) -> Capability layer (tools/plugins)| | |Session and state store <---- Sandbox and execution <---- Scheduling and observability
The key point is dependency inversion: the orchestration layer depends only on abstract interfaces and does not need to know about specific model vendors or storage implementations. A sample interface is shown below (for general illustration only, not a specific product API):
class ModelAdapter(Protocol):async def complete(self, messages, tools) -> Response: ...class Loop(Protocol):async def run(self, ctx: Context) -> Result: ...class Store(Protocol):async def load(self, sid: str) -> Session: ...async def commit(self, sid: str, delta) -> None: ...
When model adapters, loop strategies, and storage backends are all defined as protocols, replacement becomes “registering an implementation” rather than modifying the main codebase.
3. Reversibility: A First-Class Constraint for Plugins
“Reversibility” should be a first-principles design rule: every side effect produced by installing a plugin must be fully reclaimed when it is uninstalled. This can be implemented through four constraints.
- Declarative registration. A plugin declares the tools, configuration items, routes, and storage namespaces it registers through a manifest.
- Namespace isolation. Each plugin has its own prefix, and cross-namespace writes are prohibited.
- Transactional lifecycle. Install, enable, disable, and uninstall correspond to rollback-capable transactions; any failure triggers a full rollback.
- Side-effect ledger. External impacts such as files, environment variables, and network listeners are recorded and cleaned up according to the ledger during uninstall.
Only after these four conditions are met can an evolutionary pattern emerge in which “an agent installs capabilities for itself during a conversation, and those capabilities remain after reopening the session.” The essence is to treat the plugin system as a persistent capability repository, not a temporary in-process registry.
4. Execution Security and Sandbox Governance
The stronger the capabilities, the more boundaries are needed. Least privilege is recommended by default:
- Mount the filesystem with a workspace allowlist, and route writes through a temporary layer;
- Allow network egress on demand, with deny by default;
- Set timeout, concurrency, and quota limits for tool calls;
- Require secondary confirmation or manual approval for dangerous operations (deletion, privilege escalation, external transmission).
The sandbox can be a containerized runtime or a lightweight isolated process; the key is that it is “disposable, rebuildable, and snapshot-capable,” so that failures can quickly roll back to a clean state.
5. State Persistence and Recoverability
Long-running tasks need to be recoverable. It is recommended to split a session into three types of data: the message stream, the tool-call trace, and the plugin capability manifest. For persistence, object storage can hold large objects, a relational or document database can hold structured metadata, and a message queue can decouple asynchronous tasks. On recovery, first rebuild the capability manifest, then replay the trace, and finally resume the loop. This way, even if the process crashes, execution can continue from the most recent checkpoint.
6. Performance and Experience: Do Not Treat a Preview as a Finished Product
Early preview versions generally have rough interfaces, compatibility that may change, and occasional loop errors and long runtimes on complex tasks. Engineering teams should build their own evaluation baseline rather than relying on promotional figures:
Metrics: task success rate / average steps / runtime per task / rollback rate / residual count after plugin uninstallMethod: fixed task set + repeated runs + recording failed traces
For general tasks, simple code generation usually completes in tens of seconds, while large tasks such as long-document translation take minutes; actual numbers vary widely with the model, hardware, and implementation, so self-testing should be the reference.
7. Suitability: Who Should Start Now
- Suitable: teams that want to do secondary development, need to freely replace models and storage, and are willing to write plugins and debug the runtime.
- Not yet suitable: scenarios that expect out-of-the-box use, direct replacement of mature intelligent coding assistants, or production-grade stability.
The conclusion is clear: this type of runtime is about “building the stage,” not “providing a ready-made performance.” If the goal is fast delivery, choosing a mature finished tool is safer; if the goal is to build your own agent platform, the pluggable plus reversible architecture direction is worth investing in. Baidu AI Cloud can provide infrastructure support for such self-built runtimes through general capabilities such as container platforms, object storage, log services, and monitoring and alerting.
