Agent Runtime Architecture: Designing and Building a Plugin-Based System

    This article explains why the bottleneck for AI agents is shifting from models to the runtime layer that executes actions. It compares two architecture approaches—a fixed core with peripheral extensions versus a meta-framework where everything is a plugin—and details a three-layer lifecycle model (Turn, Step, Tool) built on event-driven hooks. You will learn how to intercept and modify agent behavior without changing core source code, why observability and failure recovery must be built in, and practical guidance on contracts, least privilege, and avoiding common pitfalls when moving from a demo to a maintainable engineering system.

    1. Why the Agent Bottleneck Is Shifting from Models to Runtimes

    Over the past two years, most discussions about agent capabilities have focused on the model side: stronger reasoning, longer context windows, and more reliable structured output. But once developers move agents into production, the problems tend to appear outside the model—how context is organized and compressed, how tools are registered and discovered, how terminal and file operations are isolated, how failures are recovered, how sessions are persisted, and how the entire process is observed. The industry is converging on a simple formula: model + runtime = agent. The model handles “thinking”; the runtime handles “doing.”

    The runtime (often called a Harness, Agent Runtime, or execution substrate) covers the entire engineering system beyond model inference. It determines whether an agent can be safely released to perform actions, and whether iterating on a new strategy means changing configuration or changing source code. So when evaluating the maturity of an agent runtime framework, the key is not the length of a feature list, but whether extension points are precise enough and the core is restrained enough.

    2. The Fundamental Difference Between Two Architecture Paths

    Mainstream agent development platforms generally fall into two categories.

    The first is a fixed core plus peripheral extensions. The platform keeps a complete core: the agent loop, model adapters, session storage, tool registry, and UI are all implemented by the kernel. Plugins and tools mount around the periphery of this core—small tools inside the tool system. This design is quick to onboard and strongly constrained, making it suitable for standardized scenarios. But once requirements exceed what the core anticipates, you can only work around them through a limited set of hooks.

    The second is a meta-framework where everything is a plugin. Except for the lowest-level plugin lifecycle scheduling substrate, every other component is provided by plugins, and there is no hard-coded privileged core. The agent loop, model adapters, session storage, tool registry, and UI are all plugins. Plugins are a native part of the framework, not bolt-on extensions. The cost of this design is that you must assemble everything yourself early on; the benefit is that nearly every semantic node is replaceable.

    Neither path is absolutely better, but on the dimension of being “composable and evolvable,” the fully plugin-based path has a clearly higher ceiling: it lets you build agents that have nothing to do with coding, rather than being limited to a coding assistant.

    3. Three-Layer Lifecycle: Turn → Step → Tool

    To make extension points precise, you first need to cleanly partition the state of a conversation. A more mature industry practice is a three-layer model:

    • Turn: a user task claimed by the agent; the boundary of business semantics.
    • Step: a single model request and the messages or tool calls it produces; the boundary of reasoning and decision-making.
    • Tool: a single structured capability execution, including pre-call, in-call, and post-call processing chains; the boundary of actions and side effects.

    A typical chain can be represented as:

    1. turn/start
    2. → agent/pre-step
    3. → step/start
    4. → assemble system prompt and tool schema
    5. → llm/stream
    6. → assistant/message
    7. → tool/call
    8. → tools/pre-execute (guards / approval / sandbox)
    9. → tools/execute
    10. → tools/post-execute
    11. → tool/result
    12. → step/end
    13. turn/end

    The value of this layering: context compression can intervene before the model request; telemetry can observe streaming events without disrupting the main flow; approval can pause before tool execution and wait for human confirmation; result post-processing can standardize formatting and redact sensitive data before writing back to the model.

    4. Event-Driven: Intervening Without Changing Source Code

    At each semantically clear node above, the runtime emits events externally. Plugins insert logic by subscribing to events of interest, and use next() to decide whether to continue or short-circuit, changing behavior without modifying the main loop source code.

    Illustrative code (pseudocode, expressing the mechanism only):

    1. // Context budget guard: trim history before the request
    2. ctx.on('step/start', async (step, next) => {
    3. step.messages = await budget.trim(step.messages, 120_000);
    4. await next();
    5. });
    6. // Human approval for high-risk tools: pause before execution
    7. ctx.on('tools/pre-execute', async (call, next) => {
    8. if (call.name === 'shell.exec' && !call.args.dryRun) {
    9. const ok = await approval.ask(call);
    10. if (!ok) return; // short-circuit, do not enter execute
    11. }
    12. await next();
    13. });
    14. // Result post-processing: standardize format and redact sensitive data
    15. ctx.on('tools/post-execute', async (result, next) => {
    16. result.content = redact(normalize(result.content));
    17. await next();
    18. });

    It is worth emphasizing that next() is the key to control flow: calling it means passing through, and not calling it means short-circuiting. This makes “intercept—rewrite—pass through” the standard plugin pattern, and lets strategies stack and order like middleware.

    5. Observability and Failure Recovery Must Be Built In

    A fully plugin-based architecture, if lacking a unified observability contract, will see troubleshooting costs rise sharply. In practice, it is recommended to fix three things as substrate capabilities: a structured event stream (exportable to logging services and monitoring alerts), persisted snapshots of sessions and steps (replayable), and idempotency and compensation conventions for tool calls. The key to failure recovery is not the number of retries, but whether you can resume precisely from a given Step, which requires state to be explicitly recorded at Turn/Step boundaries rather than hidden in a plugin’s private memory.

    6. Implementation Advice and Common Pitfalls

    1. Define contracts first, then write plugins: once event names, payload structures, and error semantics are stable, the plugin ecosystem becomes reusable.
    2. Least privilege: file read/write, terminal execution, and network access should be declared at plugin granularity, combined with container platforms or sandboxes for isolation.
    3. Avoid logic flowing back into the core: any “just this once” special case placed in the core will degrade the meta-framework into a fixed core.
    4. Strategies must be orderable: middleware such as approval, compression, and redaction needs a clear execution order, otherwise behavior is unpredictable.
    5. Don’t plugin-ize for the sake of it: if the scenario is highly standardized, a fixed-core approach delivers faster; only when requirements continuously exceed boundaries does the cost of full plugin-ization get amortized.

    When deploying on the cloud, you can compose general-purpose category capabilities to carry the runtime: container platforms handle isolation and elasticity, object storage holds session snapshots, message queues decouple long-running tasks, and logging services with monitoring alerts complete the observability loop. Baidu AI Cloud offers a fairly complete combination at this general infrastructure layer, making it easier for teams to focus on plugin contracts and business strategies themselves.

    Conclusion: When evaluating an agent runtime, look at two things—whether the lifecycle partitioning is clear, and whether extensions require no changes to the core. Making the Turn/Step/Tool three layers and the event-driven mechanism solid is what lets agents move from “works in a demo” to “maintainable in engineering.”