Agent Runtime Architecture: From Plugin-Based Systems to Self-Rewriting Harnesses
This article breaks down the distinction between the agent client and the runtime kernel, explains the limits of the traditional monolithic agent loop, and describes a microkernel design built on spatial and temporal composability, isomorphism, and reflection. It walks through how Create Mode performs self-modification in six controlled steps, outlines the cloud infrastructure and observability practices needed to run such a runtime, and closes with a governance checklist covering change control, least privilege, and cost limits.
1. Where the Confusion Starts: Two Layers That Get Mixed Up
The most common misconception in discussions about agent technology is treating the “interaction client” and the “runtime kernel” as the same thing. What most people picture as an agent product is a complete application you can download, log into, and immediately use for coding and retrieval tasks. The interface, account system, billing panel, and task orchestration are bundled together, so users perceive a single whole.
If you think of the large model as a horse, the user-facing application is closer to the carriage: it handles the riding experience, navigation, and dispatch. What actually determines whether the horse can be driven is the saddle, the reins, and the linkage between them. That layer is where the runtime (the harness) sits. An operating system analogy makes it clearer still: the runtime is the hardware abstraction layer plus the kernel, offering a stable capability contract upward while hiding implementation differences downward.
This separation matters because the two layers evolve on completely different schedules. The client layer chases experience and distribution, so a flood of near-identical wrappers can appear in a very short time. The kernel layer chases correctness of abstraction, extensibility, and governability, and maturing it takes far longer. Operating system history is instructive: years, sometimes a decade, separated a minimal working kernel from character interfaces and then from mass adoption of graphical interfaces. Agent runtimes will likely diffuse in layers the same way, only faster. It is worth stressing that most usable agent clients today already embed a fairly complete runtime internally. Proposing an independent runtime abstraction is not a rejection of those implementations; it extracts mechanisms that are currently coupled inside applications and turns them into reusable infrastructure.
2. The Traditional Agent Loop: A “Soldered Microcontroller”
To see the value of a new architecture, you first have to look clearly at the shape of mainstream implementations. The core of most agent systems is a fixed-structure loop with inlined logic, which can be sketched as follows:
# Sketch: a typical monolithic agent loopsystem_prompt = build_role_prompt(role="engineer")tools = [ReadFile(), WriteFile(), RunShell(), WebSearch()]schema = json_schema(tools)messages = [system_prompt]while True:reply = llm(messages, tools=schema) # model inferenceif not reply.tool_calls:breakfor call in reply.tool_calls: # intercept calls locallyresult = dispatch(call, tools) # execute local codemessages.append(to_text(result)) # feed results back as text
The problem with this loop is not whether it runs, but that every key decision is hardcoded in the host program: the role is a fixed long prompt, the tool set is fixed at startup, the tool schema descriptions are serialized once and never change, and the execution policy (concurrency, retries, truncation, approval) is baked into the dispatch function. The model can only reason along predetermined tracks. It cannot perceive its own structure, let alone modify it. In engineering terms, this is a “microcontroller”: a while loop plus a pile of soldered logic.
Three typical pain points follow. First, context bloat: as turns accumulate, history and tool descriptions pile up and the density of useful information drops. Second, rigid capabilities: adding a capability requires changing host code and republishing, with no way to load it dynamically mid-task. Third, no policy introspection: the system cannot answer at runtime “what capabilities do I currently have, which policy is in effect, which stage did the failure occur in,” which makes adaptive optimization difficult.
3. Target Capabilities: Spatiotemporal Composability and Runtime Self-Rewriting
The design goal of a next-generation runtime can be summarized as “spatiotemporal composability”: capabilities can be freely combined along both time and space. The spatial dimension means capabilities coexist as plugins and can be swapped and nested. The temporal dimension means plugins can be loaded, unloaded, upgraded, or rolled back at any stage of the lifecycle without restarting the whole system.
On top of that, the runtime needs two properties drawn from classical language theory. Isomorphism means the structure of the system is identical to its own representation: the plugin tree exists as a readable and writable data structure, so “modifying the program” and “modifying data” are the same operation. Reflection means the system can read its own state at runtime and adjust behavior accordingly. Only when the two combine does “the model rewrites its own plugin tree at runtime” stop being a slogan and become an achievable capability.
The concrete form is a microkernel with lifecycle management. The microkernel keeps only minimal responsibilities: plugin registration and resolution, dependency and capability negotiation, the lifecycle state machine, invocation routing, and events and logs. Everything else — file access, command execution, retrieval, code indexing, test runs — is a plugin. The kernel and plugins communicate through a stable capability contract: each plugin declares what capability it provides, what preconditions it requires, and in which phases it can be mounted.
Plugin descriptor (sketch)- id: fs.readprovides: capability.fs.readrequires: [capability.policy.evaluate]phases: [runtime, task]hooks: [on_load, on_invoke, on_unload]state: serializable, versionable
4. Create Mode: How Self-Modification Actually Runs
Runtime self-modification is usually enabled by an explicit switch, and its essence is promoting “writing your own structure” to a first-class operation. A typical self-rewrite runs through six steps: observe (read the current plugin tree and execution trace), diagnose (locate the failing stage, for example a wrong tool choice or an overly strict policy), propose (generate a new plugin tree description rather than editing code directly), validate (run static checks and capability dependency resolution on the proposal), canary (load the new configuration in a restricted sandbox and verify with a small-sample regression), and commit or roll back (keep a version snapshot and revert quickly on anomalies).
One boundary needs particular clarification: self-rewriting does not mean letting the model generate and execute arbitrary code at will. The engineerable approach limits changes to declarative configuration and a controlled set of plugins, with every change passing policy validation, permission checks, and an audit trail. Sketch:
{"change_id": "c-20240813-001","op": "replace_plugin_set","target": "task.retrieval","add": ["retrieval.hybrid", "rerank.light"],"remove": ["retrieval.keyword_only"],"guard": { "sandbox": true, "budget_tokens": 200000, "approval": "policy" },"rollback_to": "v17"}
5. Engineering Essentials for Running It in the Cloud
When deploying this kind of runtime in a cloud environment, six general capability categories are worth attention: a container platform to host the runtime and plugin sandboxes for isolation and elasticity; object storage for plugin packages and version snapshots; a message queue to decouple events and asynchronous tasks; logging, monitoring, and alerting services for end-to-end observability; key and configuration management to hold credentials; and policy and permission components to handle change approval and least-privilege control. Baidu AI Cloud offers corresponding capabilities in each of these general categories and can serve as the infrastructure foundation for building such an architecture.
Observability needs to revolve around the plugin tree, not only around requests: record every load and unload, every self-rewrite proposal and its outcome, and every capability route hit along with the reason for each failure. The evaluation system should have three layers: plugin-level unit tests, a task-level regression suite, and before/after comparison experiments for self-rewrites, so that “it got worse after the change and nobody noticed” cannot happen.
6. Risk and Governance Checklist
Self-rewriting amplifies three kinds of risk: uncontrolled change (the plugin tree is rewritten repeatedly and behavior drifts), privilege overreach (a plugin requests capabilities beyond what the task needs), and unpredictable cost (loops and retries compound consumption). The corresponding controls are versioning plus a change budget, least privilege plus an approval gate, and spending caps plus a circuit breaker. The conclusion: the value of a runtime abstraction is not “more freedom” but “composability, observability, and rollback.” Get those three solid, and an agent system becomes a candidate for production rather than a demo.
