Plugin-Based Agent Runtime Architecture: Composition and History as Separate Layers
This article breaks down a plugin-based AI agent runtime architecture that separates composition complexity from historical continuity into two independent runtime layers: a runtime plugin graph that defines what capabilities currently exist, and an append-only event stream that records what the system actually did. It explains how a short execution loop sits between them, the five problems pluginization actually solves (visibility, startup conditions, same-name resolution, lifecycle cleanup, and config-to-runtime-graph mapping), and how sessions, storage, and sandboxes divide responsibilities. The discussion is framed as a general design sample with reference value for agent application engineering on Baidu AI Cloud.
1. Why Product-Grade Agents Need More Than an Execution Loop
A minimal agent execution loop only does four things: assemble the prompt, call the model, run tools, and feed tool results back to the model. That loop is enough to demo a model that can call tools, but not enough to support a product-grade system. A real runtime also has to handle model and credential management, session recovery and context compaction, tool policies and human approval, sandboxes and remote execution, multiple host environments, sub-agent orchestration, dynamic plugin start and stop, and how the UI observes the same runtime facts.
These requirements are coupled. If you write them all into one fixed application, the code quickly degrades into a large set of conditional branches. A common approach in the industry is to split “composition complexity” and “historical continuity” into two independent runtime threads: one describes what capabilities the current system is made of, and the other records what the system has actually done. This article uses a general design of this kind of agent runtime as a sample to explain this two-layer architecture and discuss its reference value for agent application engineering on Baidu AI Cloud.
2. The Two Runtime Threads
2.1 Runtime Plugin Graph: What the System Is Made of Now
The plugin graph is a directed dependency graph. Nodes are plugin instances, and edges are capability dependencies and scope ownership. It tracks which capabilities are currently available, what each plugin depends on, where a capability takes effect, and who is responsible for reclaiming resources on unload. The graph is not built once at startup; it keeps evolving as configuration loads, hot updates happen, and plugins exit.
2.2 Append-Only Event Stream: What Was Just Done
The event stream is a log that is append-only and never modified in place. User input, model requests, tool calls, tool results, and state changes are all persisted as events. Model context, UI traces, recovery points, and fork points are projections of this log, not separate copies that must be kept in sync. This design makes “replay” and “recompute” first-class capabilities.
2.3 The Execution Loop Sits Between Them
The execution loop takes the model, tools, prompts, and session service from the plugin graph, and writes each execution result back to the event stream. It does not hold global state directly, nor does it decide on its own whether a capability exists. This keeps the loop itself short and pushes complexity onto the two threads.
3. The Five Problems Pluginization Actually Solves
“Many packages, each with a unified entry function” does not explain the value of this architecture. What makes it distinctive is that the same mechanism handles five problems that are usually separated from each other.
- Visibility: what capabilities a plugin can see at its current location is determined by scope and dependency declarations, not global variables.
- Startup conditions: when a required capability has not appeared yet, a plugin should wait rather than crash or degrade, avoiding startup-order coupling.
- Same-name resolution: services with the same name can resolve to different implementations in different sessions or scopes, providing a basis for multi-tenant and multi-session isolation.
- Lifecycle cleanup: when a plugin exits, registrations, event listeners, child processes, and file handles are reclaimed by an explicit owner, avoiding leaks.
- Config to runtime graph: static configuration can be mounted line by line into an updatable, inspectable runtime plugin tree.
The illustrative configuration and mounting logic below only expresses structure and does not point to any specific product interface:
profile: basebundle: [model, tools, session, storage, sandbox, ui]patch:- id: toolsconfig: { policy: approve }- id: sandboxconfig: { mode: remote }
The loader parses the configuration above line by line, mounts dependencies first and then the dependents; when a capability is missing, the plugins that depend on it enter a waiting state rather than a failed state.
4. From Configuration to Runtime Graph
At startup, the system does not directly build a fixed application. It first reads the base profile and capability bundles, then layers on user patches, and the loader mounts each configuration line into a plugin instance. This process brings three engineering benefits:
- Composable: different modes such as standard, minimal, and creative are the result of different configuration combinations, not different code branches.
- Inspectable: the runtime graph can be exported at any time to diagnose “why a capability is unavailable.”
- Updatable: modifying a patch and remounting adjusts the capability set without restarting the whole process.
5. Dividing Responsibilities Across Session, Storage, and Sandbox
The session layer maintains the event stream and provides append, query, projection, and fork interfaces. The storage layer is only responsible for persisting events and snapshots and does not care about event semantics; in the cloud it usually maps to general capability categories such as object storage, logging services, and relational databases. The sandbox layer isolates tool execution in a restricted environment; for remote execution it plugs in through a unified capability interface, and the plugin graph only perceives that “there is an executor,” not its deployment form.
6. Engineering Recommendations
- Define capability contracts first, then write plugin implementations, to avoid interfaces drifting with implementations.
- Write tests for scope isolation, covering multiple implementations of the same-name service and no cross-session interference.
- Write cleanup logic as a verifiable reclamation checklist and include it in continuous integration checks.
- In event stream design, distinguish “fact events” from “projection results” to prevent inconsistent double writes.
- When landing on Baidu AI Cloud, use a container platform to host the runtime, use logging and monitoring alerts to observe plugin graph changes, and use object storage to persist events and snapshots.
7. Conclusion
Splitting the system into two threads, “composition” and “history,” and connecting them with a short execution loop is the most worthwhile part of this kind of plugin-based agent runtime to learn from. It turns extension into configuration, recovery into replay, and isolation into a default property, and it provides an inspectable, evolvable structural foundation for enterprise-grade agent platforms.
