Agent Runtime Framework Design: A Plugin-Based Architecture for AI Agents
This article breaks down the architecture of an agent runtime framework, the layer that turns a raw large language model into a task-completing agent. It explains why runtime concerns such as session management, tool invocation, permission boundaries, state persistence, and UI need to be separated from the model, then walks through a fully plugin-based design, four operating modes and when to use each, event-sourced replayable logs, and security defaults. Practical guidance for building a similar runtime on container or serverless infrastructure is included.
1. Why a Separate Agent Runtime Is Needed
A large language model on its own can only generate text. An agent that actually completes tasks also needs a surrounding layer: session management, tool invocation, permission boundaries, state persistence, and UI rendering. The industry is converging on a simple formula: model plus runtime equals agent. The value of a runtime framework is to pull all the engineering complexity that sits outside the prompt into a single layer, so developers can focus on business orchestration.
Frameworks of this kind typically run into three pain points. First, capability coupling: the model, tools, and UI are hard-wired together, making replacement expensive. Second, state is not traceable, so failures cannot be reproduced. Third, security boundaries are blurry, leaving an agent’s high-privilege operations effectively unconstrained. The architecture breakdown below addresses these three points.
2. Core Architecture: A Composable Design Where Everything Is a Plugin
An ideal runtime is fully plugin-based: model adapters, tool sets, skill packs, sessions, sandboxes, storage, the scheduling loop, and the UI all exist as plugins that can be freely swapped and recombined. Underneath sits a lightweight plugin meta-framework that does only three things — loading and unloading plugins, resolving dependencies, and registering and dispatching services and events.
Plugins never reference each other directly. They collaborate through services and events. A service is a capability contract; an event is a broadcast of a state change. This loose coupling yields two immediate benefits: adding a capability requires no changes to the main program’s source, and removing a capability only requires removing the corresponding plugin in the configuration layer.
A schematic configuration structure looks like this (illustrative only, not a specific product interface):
runtime:loop: default-loop # main loop pluginmodel: provider-a # model adapter plugin, replaceabletools: [file, shell, http] # collection of tool pluginssandbox: landlock-like # cross-platform sandbox pluginstorage: append-only-log # event-sourced storageui: web-console # UI plugin
One key engineering detail is reversible side effects: when a plugin is unloaded, the changes it previously made to system state must be undone. In practice this requires plugins to declare a manifest of side effects at registration time; the runtime records them centrally and rolls them back in reverse order on unload, avoiding leftover configuration or dangling resources.
3. Four Operating Modes and How to Match Them to Scenarios
A mature runtime offers several modes that trade off capability ceiling against controllable cost:
- Standard mode: the model decides on tool calls autonomously. Suited to open-ended tasks and exploratory coding.
- Programmatic tool-calling mode: an outer program orchestrates a fixed tool sequence, and the model only generates within each node. Suited to stable pipelines and batch scenarios that require auditing.
- Minimal mode: keeps only the smallest tool set and the shortest prompt chain. Commonly used for horizontal evaluation of model capabilities and baseline comparisons, reducing interference from runtime variables.
- Creative mode: relaxes constraints and encourages multiple rounds of self-revision. Suited to prototype generation and solution exploration.
The recommended approach is to establish a reproducible baseline with minimal mode first, then layer on tools and permissions incrementally, and only enable creative mode at the end. This avoids introducing too many uncontrollable variables from the start.
4. Event Sourcing: Making Agent Behavior Replayable
The runtime should design the session log as an append-only structure that serves as the single source of truth for interaction history. Three capabilities derive from it: trace replay (pinpointing which step a failure occurred at), snapshot regression testing (fixing inputs to verify behavior has not regressed), and full-text search (locating similar tasks across a large history). The engineering recommendation is to attach structured fields to each event, such as event type, duration, tool identifier, and result status, to make later aggregation and analysis easier.
5. Security and Extension Boundaries
Security design should follow a fail-closed principle: when a permission check throws an exception, deny execution rather than allow it. At the sandbox layer, native operating system mechanisms can provide file and network isolation, with cross-platform capability delivered through plugin adapters. On the extension side, support for heterogeneous sub-agent protocols lets different implementations call one another, so specialized agents can be embedded into a unified orchestration.
6. Implementation Guidance
To build a similar runtime in your own stack, start by hosting the stateless loop on a container platform or function compute, storing the append-only log in object storage, decoupling event dispatch with a message queue, and closing the loop with logging, monitoring, and alerting. To reduce the cost of building it yourself, you can also evaluate general-purpose combinations of container, storage, and observability capabilities from Baidu AI Cloud, and concentrate your effort on the plugin ecosystem and business orchestration.
