Agent Runtime Architecture: Encapsulated vs. Pluggable Design — How to Choose

    Over the past year, the focus of discussion around AI agents has shifted from comparing foundation model benchmark scores to evaluating runtime environments. The same model can show very different task completion rates, token consumption, and safety behavior depending on its runtime (often called the harness). This article explains why the runtime increasingly determines real-world performance, compares the two main architectural approaches—encapsulated runtimes and composable, plugin-based runtimes—provides a structured selection framework, and illustrates the core ideas of a plugin-based runtime with pseudocode, along with practical recommendations for adoption.

    Over the past year, the focus of discussion in the AI agent space has shifted noticeably. In the past, the industry mainly compared foundation models by their scores on benchmark suites. Now, more and more teams have discovered that the same model, placed in different runtime environments, can differ significantly in task completion rate, token consumption, and safety behavior. The layer responsible for turning a model’s reasoning ability into an executable, controllable, and auditable task process is commonly called the agent runtime, or the harness.

    Why the Runtime Is Starting to Determine Outcomes

    A rough formula the industry broadly agrees on is: Agent = LLM + Runtime. The model handles intent understanding, step planning, and generating tool-call parameters. The runtime handles loop scheduling, tool invocation, context management, permission checks, and process logging. The two have distinct responsibilities, and the quality of the runtime directly affects whether the model’s capabilities can be fully realized.

    Runtimes differ notably in the following areas:

    • Loop control: when to continue, when to terminate, and how to retry after failure—these determine whether a task gets stuck in unproductive loops.
    • Context management: how to trim history and compress intermediate results—these determine token costs and the stability of long-running tasks.
    • Tool-call boundaries: how tool parameters are validated, how timeouts are handled, and how errors are returned—these directly affect task completion rates.
    • Security isolation: the access scope for files, networks, and system commands—these determine the blast radius of accidental operations.

    Therefore, when evaluating an agent system, looking only at the model’s benchmark scores is incomplete. You also need to observe how the runtime performs on real tasks.

    Two Main Technical Approaches

    Current runtime designs fall roughly into two categories.

    1. Encapsulated Runtimes

    This type of solution provides the main loop, sandbox isolation, context compression, human approval, and audit trails as built-in capabilities. Users integrate it into business systems through configuration, SDKs, or service-based deployment, and generally do not need to modify the core logic.

    Its advantages include:

    • Relatively complete security mechanisms with conservative default configurations, suitable for fast go-live.
    • Validated at considerable engineering scale, with comparatively high stability and lower operational burden.
    • A clear integration path that requires less team effort.

    Its constraints include:

    • The core loop cannot be modified; unusual business processes can only be worked around.
    • Model adaptation is usually optimized around a specific model family; integrating other models may require additional development.
    • The pace at which external contributions are accepted depends on the maintainer’s iteration plan.

    You can think of this type of solution as a move-in-ready home: utilities and security infrastructure are already in place, so you can settle in quickly, but there is limited room to alter the structural walls.

    2. Composable Runtimes

    This type of solution centers on a microkernel, designing the scheduling loop, sandbox, storage, memory, model adapters, and interface layers as replaceable plugins. Developers can swap any module as needed, and can also incorporate existing agents as sub-agents under a unified scheduling system.

    Its advantages include:

    • High flexibility, capable of covering complex business processes and non-standard models.
    • Easy switching across multiple models, reducing dependence on a single vendor.
    • Teams can evolve independently around the plugin ecosystem without waiting for upstream releases.

    Its constraints include:

    • The more freedom you have, the more design and security responsibility the team assumes.
    • Interface contracts between plugins must be strictly maintained, and version compatibility is costly.
    • Default security policies usually need to be configured by the team; there are no extensively validated defaults.

    This type of solution is more like a set of standardized building modules plus structural blueprints—suited to teams with independent design and implementation capabilities.

    Comparison Dimensions and Selection Approach

    When making a selection, you can do a structured comparison along the following dimensions:

    Dimension Encapsulated Composable
    Time to production Fast Depends on plugin development progress
    Customization freedom Limited High
    Default security Relatively complete Relies on your own configuration
    Model replaceability Usually optimized for specific models Achieved via adapters
    Maintenance cost Lower; depends on upstream iteration Higher; borne by the team
    Audit and compliance Built in Must be built in-house

    You can follow four steps in your evaluation:

    1. Define the scenario: list task types, concurrency scale, data sensitivity levels, and compliance requirements.
    2. Draw the boundaries: decide which components must be under your own control and which can accept a standardized implementation.
    3. Benchmark: using the same set of real tasks under the same model, compare different runtimes on completion rate, latency, and token consumption.
    4. Assess evolution cost: consider the refactoring cost of switching models or expanding the business over the next one to two years.

    A Minimal Sketch of a Plugin-Based Runtime

    The following code illustrates the core ideas of a plugin-based runtime: the scheduling loop depends only on abstract interfaces, every tool call passes through a policy check, and the entire process is written to an audit log. The example is a generic pseudo-implementation and does not correspond to any specific product API.

    1. from dataclasses import dataclass, field
    2. from typing import Protocol, Any
    3. class Tool(Protocol):
    4. name: str
    5. def run(self, args: dict[str, Any]) -> str: ...
    6. class Policy(Protocol):
    7. def allow(self, tool_name: str, args: dict[str, Any]) -> bool: ...
    8. @dataclass
    9. class Runtime:
    10. model: Any # Model adapter implementing a unified generate method
    11. tools: dict[str, Tool]
    12. policy: Policy
    13. max_steps: int = 10
    14. trace: list[dict] = field(default_factory=list)
    15. def execute(self, task: str) -> str:
    16. context = [{"role": "user", "content": task}]
    17. for _ in range(self.max_steps):
    18. action = self.model.generate(context) # Returns the next action or final answer
    19. if action["type"] == "final":
    20. self._log("final", action)
    21. return action["content"]
    22. name, args = action["tool"], action["args"]
    23. if not self.policy.allow(name, args):
    24. observation = "Action rejected by policy"
    25. elif name not in self.tools:
    26. observation = f"Unknown tool: {name}"
    27. else:
    28. try:
    29. observation = self.tools[name].run(args)
    30. except Exception as exc:
    31. observation = f"Tool execution failed: {exc}"
    32. self._log("tool", {"name": name, "observation": observation})
    33. context.append({"role": "tool", "content": observation})
    34. return "Max steps exceeded; task terminated"
    35. def _log(self, kind: str, payload: dict) -> None:
    36. self.trace.append({"kind": kind, **payload})

    This code reflects several engineering principles:

    • Decoupling: the model and tools are isolated through interfaces, so swapping models only requires replacing the adapter.
    • Unified authorization: every tool call passes through a policy check, and permission boundaries are enforced centrally at the scheduling layer.
    • Self-healing on errors: exceptions are converted into observations and returned to the model instead of interrupting the task, allowing the model to correct itself.
    • Controllable cost: the maximum step limit prevents infinite loops and directly sets an upper bound on token cost.
    • Auditability: the entire process is logged, facilitating security audits and post-incident reviews.

    Practical Recommendations

    1. Build evaluation first, then choose. Establish a baseline with real business tasks rather than relying solely on public leaderboards.
    2. Put security first. Regardless of which approach you choose, define least-privilege access for files, networks, and command execution, and keep human approval checkpoints for high-risk operations.
    3. Control context costs. For long tasks, use segmented summarization and externalized result storage to reduce the history repeated in each round.
    4. Keep models replaceable. Isolate business code behind a unified model adapter layer, leaving room to switch models or mix multiple models later.
    5. Invest in observability. Consistently log the inputs, outputs, latency, and token counts of every step—this is the foundation for troubleshooting and cost optimization.

    Making the Choice

    Choosing a runtime is fundamentally a trade-off among efficiency, flexibility, and control. Encapsulated solutions suit teams that want to go live quickly and have strong needs for standardized security capabilities. Composable solutions suit teams with strong engineering capabilities that need deep customization or multi-model coordination. The final answer depends on the team’s business shape, staffing structure, and risk tolerance.