Agent Framework Architecture: How a Plugin-Based Runtime Works
This article analyzes the architecture of a plugin-based AI agent runtime framework that follows an "everything is a plugin" design. It explains three underlying mechanisms—a service container for dependency injection, typed events for cross-plugin coordination, and rollbackable side effects—and shows how the startup process stacks plugins into a tree without a privileged core. It also covers package splitting in a large monorepo, the six checkpoints a tool call passes through, context compression and sub-agent orchestration, the framework's engineering constraints, and practical lessons for building a controllable and observable agent platform on cloud infrastructure.
Agent Framework Architecture: How a Plugin-Based Runtime Works
Why the Runtime Layer Deserves Attention
Over the past two years, the focus of agent engineering has been shifting from model capability to runtime capability. The model only generates the next action. What actually determines whether a system is controllable, observable, and extensible is the outer structure that hosts the model: how sessions are persisted, how prompts are assembled, how tools are registered and authorized, how a failed call is rolled back, and how multiple subtasks are isolated and merged.
A recently released open-source agent runtime framework, now available as a developer preview, has a clear positioning: a runtime built on an “everything is a plugin” philosophy, driven underneath by a dependency injection and lifecycle management framework. This article uses it as a sample to abstract its architectural paradigm, discussing how packages are split, how the main loop runs, which checkpoints a single tool call must pass, and the engineering discipline the framework sets for itself. No specific product is recommended here, and all command-line examples and package names have been neutralized.
Three Underlying Mechanisms Shape Everything Above
1. Service Container: Dependencies Resolved as Services
The framework abstracts capabilities into services that can be registered and injected. A plugin declares which services it needs, and the container resolves and wires them during startup. The benefit is that plugins do not import each other’s concrete implementations directly; they depend only on service contracts, so swapping an implementation requires no changes on the caller side.
2. Typed Events: Decoupling Through Events, Not Function Calls
Cross-plugin collaboration relies heavily on an event bus. Events carry type definitions, so editors can autocomplete and the compiler can validate them. A typical use case is a cross-cutting concern such as prompt assembly: multiple plugins each append fragments to the prompt pipeline, and the main flow does not need to know where each fragment came from.
// Example: a plugin participates in cross-cutting logic through eventsctx.on('prompt/section', (sections) => {sections.push({ name: 'tooling-guide', content: renderToolGuide() })})
3. Rollbackable Side Effects: Turning Actions into Reversible Records
Tool calls, file writes, and command execution are all side effects. The framework introduces recording and rollback semantics for side effects, so that after a task fails, the system can return to a consistent state instead of leaving behind a half-finished environment. This is the key dividing line between an agent that works as a demo and one that is actually usable.
Startup Stacks a Tree: No Privileged Kernel
The startup process essentially stacks plugins in dependency order into a tree. The tool registry, prompt assembly, and even the main loop itself are ordinary nodes on that tree, at the same level as a concrete command execution plugin. This means:
- There is no single “core file” that can be patched to bypass constraints;
- To change the main loop strategy, you only replace the corresponding plugin;
- The difference between the CLI form and the GUI form lies only in which set of plugins is stacked.
Four typical entry points (interactive terminal, one-shot headless execution, graphical interface, and automation integration) share the same plugin layer, which provides the structural basis for reusing one set of capabilities across multiple surfaces.
Package Splitting: Fine Granularity Is a Prerequisite for Pluginization
The repository is a multi-package monorepo with roughly two hundred packages, the vast majority of which are product-level packages. The grouping dimensions are worth borrowing:
- Core group: sessions, system prompts, tools, and the main loop;
- Capability group: model access, file system, terminal, language services, and sandbox;
- Orchestration group: sub-agents, context compression, skills, and workflows;
- Integration group: external protocol access and client communication;
- Frontend group: dozens of browser-side packages, with the UI also split into plugins rather than a single large page application.
At the same time, the underlying framework source code is vendored into the repository as a renamed copy, for auditability, patchability, and behavior locking. This is a common “supply chain control” practice in large platform projects.
Which Checkpoints Does a Tool Call Pass Through
Drawing on general engineering practice, a tool call can be abstracted into six checkpoints:
- Registration and discovery: at startup, a plugin declares tool metadata (name, parameter schema, permission requirements);
- Model-side selection: the model emits a structured call intent;
- Parameter validation: parameters are validated against the schema, and a failure returns a repairable error message;
- Policy and approval: permission checks, confirmation of dangerous operations, and rate and quota limits;
- Execution and sandbox isolation: the call runs in a restricted environment with limited network and file scope;
- Result write-back and side-effect registration: the result enters the context and is recorded for rollback.
The value of the checkpoint model is that security policies, audit logs, and observability metrics can all hook into fixed positions instead of being scattered across business code.
Context Compression and Subtask Orchestration
Long tasks inevitably hit context growth. A common solution is layered compression: summarizing earlier turns, trimming tool output, and preserving key conclusions in a structured form. Sub-agents isolate independent subtasks into separate sessions and return only conclusions, which keeps the main context size under control. Both fit naturally with pluginization: compression strategies and orchestration strategies are replaceable plugins.
The Engineering Constraints the Framework Sets for Itself
- Full module standardization, a clear minimum runtime version, and unified dependency management;
- Breaking changes are allowed during the preview period, but changes must be traceable;
- The framework layer is decoupled from the product layer, with capabilities exposed as service contracts;
- Secure defaults come first: the default is to listen only on the loopback address, and sensitive operations require explicit confirmation.
Lessons for Building Your Own Enterprise Platform
To reuse this paradigm in your own agent platform or cloud-based solution, focus on four points. First, define the service contracts and event model clearly before worrying about the number of plugins. Second, make tool calls a checkpoint-based pipeline so that security and auditing have a place to land. Third, side effects must be rollbackable; otherwise automation cannot enter production. Fourth, pluginize the frontend as well to avoid coupling the UI to backend capabilities. Combined with common cloud capabilities such as container platforms, object storage, logging services, and monitoring and alerting, you can build a controllable and observable agent runtime foundation relatively quickly.
