Agent Runtime Framework Design and Implementation Guide
This article explains how an Agent Runtime acts as a middleware layer between large language models and business systems, and how to design one around a plugin-first architecture. It covers the core design principle of treating every capability as a plugin, model-agnostic normalization, four preset autonomy modes matched to task complexity, governance and security for plugin ecosystems, and the evolution path from prototype to autonomous execution. Readers will find practical guidance on rollback support, sandboxing, observability, and building similar capabilities in their own environments.
1. Why an Agent Runtime Middleware Layer Is Needed
A large language model can only take text as input and return text as output. It cannot perceive the real state of a file system, a database, a browser session, or an enterprise’s internal systems, and it cannot roll back its own actions when a task fails. Embedding the model directly into business code usually leads to three problems quickly: prompts become tightly coupled with business logic, tool-calling logic is scattered across the codebase, and every model upgrade requires broad refactoring. The Agent Runtime is the middleware layer designed to remove these three types of coupling: it hides model differences at the bottom and provides unified session, tool, permission, and observability capabilities at the top.
Its positioning can be understood through an identity relationship: the model provides reasoning and planning, the runtime provides environment access and execution, and only the two combined form an agent that can deliver a task. This positioning is at the same capability layer as common AI coding tools and cloud development environments in the industry; the difference lies in the implementation approach and the degree of openness.
2. Core Design Principle: Everything Is a Plugin
The essence of “everything is a plugin” is to turn every capability unit of the runtime itself into a replaceable extension point, rather than making only tools into plugins. It can usually be abstracted into six categories of extension points:
- Model adaptation: normalizing the interface protocols of different vendors into a unified inference call contract;
- Tools and skills: file read/write, command execution, retrieval, browser operations, and so on;
- Session and context: history compression, memory persistence, and context trimming strategies;
- Interaction entry points: command line, desktop client, instant messaging bot, and web console;
- Policies and governance: permission checks, auditing, rate limiting, and cost accounting;
- Lifecycle hooks: injecting conventions before a task starts and archiving artifacts after it ends.
The direct benefit of this design is a “minimal core”: the runtime kernel is responsible only for plugin discovery, dependency resolution, lifecycle scheduling, and the event bus, while all other capabilities are externalized. To evaluate whether a runtime is truly plugin-based, look at three points: whether adding a new tool requires no changes to kernel code; whether plugins can collaborate in a decoupled way through events; and whether the system can still start normally after a plugin is removed.
A sample plugin description structure (pseudocode, expressing only the contract concept):
plugin "file_ops" {version = "0.1.0"provides = ["tool.read", "tool.write"]consumes = ["event.task.started", "policy.check"]config {root_dir: string // Root directory allowed for access; anything out of bounds is rejectedmax_bytes: int = 1048576}}
3. Model Agnosticism: Making Replaceability an Architectural Constraint
Being model-agnostic is not simply “supporting multiple vendor interfaces”; it requires the kernel to be decoupled from any single model protocol. In engineering practice, this usually involves four layers of normalization:
- Protocol normalization: unifying message roles, tool declarations, streaming increments, and termination reasons;
- Capability declaration: using structured descriptions to indicate support for function calling, visual input, long context, and structured output;
- Fallback routing: automatically switching to a backup model according to the capability list when the primary model is unavailable or over quota;
- Cost observability: recording input and output tokens, latency, and failure reasons for each call to form an accountable ledger.
Once the model becomes a pluggable component, the evaluation approach should change accordingly: fix the prompts, tool set, and evaluation cases, run the same regression suite across different models, and compare them horizontally across three dimensions—task success rate, average number of steps, and token consumption—to avoid the hidden cost of “re-tuning prompts every time you switch models.”
4. Four Preset Modes and Matching Task Complexity
The value of preset modes is to turn the “degree of autonomy” into an explicit configuration rather than something scattered in prompts. The common industry layering can be summarized as:
- Standard mode: single-turn or few-turn, with limited tools, suitable for format conversion, summarization, and single-file edits;
- Programmatic tool-calling mode: the upper-layer program decides the call order, and the model only makes local decisions within nodes, suitable for batch processing with a fixed workflow;
- Minimal mode: retaining only read and retrieval capabilities, emphasizing low consumption and predictability, suitable for Q&A and retrieval augmentation;
- Creative mode: opening up tools and iteration counts, allowing self-verification and multi-round refactoring, suitable for building a project from scratch.
There is only one selection principle: the stronger the autonomy, the more supporting boundary constraints are needed. In creative mode, sandboxing, a write-operation allowlist, and artifact snapshots should be enforced; otherwise the cost of failure grows linearly with the number of steps.
5. Governance and Security for the Plugin Ecosystem
When third-party plugins grow from hundreds to tens of thousands, governance issues replace functional issues as the main contradiction. At least five mechanisms are recommended:
- Signature and source verification, refusing to load unsigned plugins;
- Least-privilege declaration, with tool-level authorization rather than global authorization;
- Sandbox isolation, limiting file access to a root directory and routing network access through an allowlist proxy;
- Supply chain auditing, locking dependency versions and generating a reproducible dependency manifest;
- Runtime observability, feeding plugin call chains, latency, and failure rates into logging services and monitoring alerts.
Circuit breaking should also be designed: a single plugin’s failure must not drag down the session, and the event bus needs to support isolation and timeout termination.
6. From Prototype to Autonomy: An Architecture Evolution Path
After plugin-based design and cross-platform capabilities stabilize, the runtime usually evolves toward a more autonomous form: introducing task decomposition and sub-agent orchestration, self-recovery from failures, experience reuse based on historical artifacts, and retaining human confirmation checkpoints. What is most easily overlooked during this evolution is “rollback capability”: creating artifact snapshots and operation logs for each task so that autonomous execution has the ability to be undone. This is a prerequisite for putting experimental capabilities into production.
7. Implementation Recommendations
If you plan to build similar capabilities in your own environment, you can refer to the following layering: use a container platform to host sandbox execution, use object storage to store artifacts and snapshots, use a message queue to decouple long-running tasks, and use logging services and monitoring alerts for auditing and capacity observation; keep the model access layer replaceable, and version the evaluation set and prompts in a repository. Baidu AI Cloud can serve as a hosting foundation for general capabilities such as containers, storage, and observability, while the runtime’s plugin contracts and governance policies are what truly determine the long-term evolution efficiency of the system.
