Agent Runtime Architecture: The Design Principles Behind "Everything Is a Plugin"

    This article explains how to structure an AI agent runtime around a strict "everything is a plugin" constraint. It covers why a harness layer is needed between a token-generating model and a task that must deliver results, how a host plane and an agent plane are connected by nested scope contexts, the boundaries between skills, tools, hooks, guards, approvals, and sandboxes, and how temporal and spatial composability enable hot mounting and dependency re-resolution. It also describes the main loop, the session event log, advanced forms such as code mode, subagents, and workflows, and a practical order for building and validating your own harness.

    Agent Runtime Architecture: The Design Principles Behind “Everything Is a Plugin”

    1. The Starting Problem: Models Produce Tokens, Agents Must Deliver Results

    Any discussion of how agent software should be organized has to begin with a plain but often ignored fact: a large language model does exactly one thing — it predicts and generates a sequence of tokens from the given context. It has no stateful memory, no execution permissions, no knowledge of the current time, and no awareness of what the previous tool call returned. Yet when we say “get the tests in this repository passing,” we expect a task loop with a clear beginning and end, one that is observable and can be rolled back.

    The gap between those two expectations is the reason the so-called Harness exists. The harness is not the model, and it is not any specific application. It is the engineering layer that places the model inside a controlled execution environment: assembling context, exposing tools, intercepting dangerous actions, recording events, driving the loop, and retrying or converging after failures.

    A common failure mode in the industry is hardcoding this layer into a monolithic application: model adapters scattered across the codebase, tool registration done through hardcoded wiring, session history coupled to business logic, and a requirement to modify core code just to switch inference backends. As capabilities grow, the code quickly degrades into a pile of glue that is hard to test. So the central question of this article is: can a single, unified set of composition rules express all of these capabilities as pluggable units?

    2. The Core Principle: Everything Is a Plugin

    “Everything is a plugin” is not a marketing slogan but a strict architectural constraint: there are no special-case components in the system. The model adapter is a plugin. The tool set is a plugin. The session record is a plugin. Hooks and approval policies are plugins. Even the main loop that drives the whole task is a plugin.

    This principle yields three direct benefits:

    • Replaceability: any capability can be swapped for another implementation with the same contract, without touching the caller.
    • Composability: a product form (a Preset) degrades into a plugin manifest plus configuration, rather than a branch of code.
    • Verifiability: an individual plugin can be tested in isolation, and composed behavior can be observed by comparing different manifests.

    There is a simple test for whether a design truly achieves “everything is a plugin”: if adjusting a capability requires modifying the kernel, then it is not a plugin but an implicit kernel. Real pluginization requires the kernel to keep only a very small number of invariants — for example, how dependencies are resolved, when scopes are created and destroyed, and how events flow.

    3. Two Planes and the Scope Context

    Once every capability is pluggable, you must answer “who can see whom, and when.” The more mature approach is to split the runtime into two planes:

    • Host Plane: process-level and long-lived, carrying infrastructure such as plugin loading, configuration parsing, logging, and resource pools.
    • Agent Plane: task-level and short-lived, carrying the model adapter, the visible tool set, message history, and loop state for a single session.

    The two planes are bridged by a Scope Context. A scope context is essentially a nestable visibility tree: a child scope inherits the services provided by its parent but can override or mask any of them. A sketch:

    1. Host Scope (process level)
    2. ├── Configuration and plugin registry
    3. ├── Logging / metrics
    4. └── Agent Scope (task level)
    5. ├── Model adapter (switchable backend)
    6. ├── Visible tool set (subset pruning)
    7. ├── Session event log
    8. └── Sub Scope (subtask)
    9. └── Restricted tool set + stricter approval policy

    The value of this structure is that permission narrowing becomes a scope operation instead of conditional checks scattered through business code. A subtask can only see the capabilities explicitly delegated by its parent scope.

    4. Three Layers of Extension: The Boundaries of Skill, Tool, and Hook

    After pluginization, you still need layering; otherwise “everything can be extended” means “nothing can be constrained.” A fairly common split in the industry is three layers:

    1. Skill: the knowledge and method layer, usually injected into context as documents, templates, or process descriptions, telling the model “how to approach this kind of problem.” It does not change execution permissions.
    2. Tool: the capability and side-effect layer, a deterministic function the model can call, with a clear input schema, output structure, and error semantics. Tools are the only channel that actually produces side effects on the outside.
    3. Hook: the governance and observability layer, inserting interception logic before and after tool calls and between loop iterations, used to record, rewrite, reject, or compensate.

    Three execution boundaries must be kept distinct, or the security model is useless:

    • Guard: static, deterministic rule checks such as parameter schema matching, path allowlists, and command blocklists. It should be fast and side-effect free.
    • Approval: a decision that requires an external party to intervene, typically “pause the loop — wait for a human or policy service decision — resume execution.” It is stateful and must be included in the session event log so it can be replayed.
    • Sandbox: the isolation boundary of the execution environment, limiting filesystem, network, and process visibility. It assumes both Guard and Approval can be bypassed, and is the last line of defense.

    A common mistake is to conflate the three: using a prompt to tell the model “do not run dangerous commands” (handing Guard to Skill), or relying on approval in an environment with no isolation (handing Sandbox to Approval). The correct order is: Guard performs fast rejection, Approval handles gray-area decisions, and Sandbox limits the blast radius as a fallback.

    5. The Runtime: Dynamic Composition, Lifecycle, and Dependency Re-resolution

    What really makes the plugin system work is the composability the runtime provides in two dimensions:

    • Temporal Composability: plugins can be mounted, unmounted, and hot-updated at runtime without restarting the process. Typical cases include switching the inference backend while running, dynamically registering a batch of new tools, or temporarily tightening the approval policy.
    • Spatial Composability: a plugin’s scope of effect is bounded by the scope context, so the same plugin presents a different visible surface under different scopes.

    Lifecycle management is usually built around a Fiber-style execution unit: each mount point corresponds to a suspendable, resumable, cancellable execution context, with states including pending initialization, ready, running, suspended, and destroyed. Dependencies are not fixed once at startup but are re-resolvable: when a plugin is unmounted or replaced, the runtime recomputes the dependency graph and performs reverse-order destruction and forward-order rebuilding on the affected nodes.

    1. Mount A (model adapter) → Mount B (tool set, depends on A) → Mount C (loop, depends on A+B)
    2. When unmounting A:
    3. 1. Mark C and B as pending re-resolution
    4. 2. Destroy in reverse order C → B → A (release side effects and resources)
    5. 3. Mount A' (new implementation)
    6. 4. Rebuild in order B' → C', restoring the session event log and loop position

    The key engineering constraint here is the Effect Boundary: a plugin must explicitly declare which operations are irreversible external effects (writing files, sending requests, incurring charges), and the runtime decides the replay strategy accordingly — reversible parts are rebuilt directly, while irreversible parts require an idempotency key or human confirmation.

    6. The Main Loop and the Session Event Log

    On top of the structure above, task execution reduces to a readable loop: read context → model generates → parse tool call intent → validate through Hook and Guard/Approval → execute in the sandbox → write the result back to context → decide whether it has converged.

    Supporting all of this is the session event log: every generation, every call, every interception, and every approval is recorded as an event with a sequence number and a causal chain. It serves four purposes at once: replay debugging, cost accounting, audit compliance, and position recovery after a crash. An agent system without an event log is essentially unoperable in production.

    The chain can be summarized as:

    1. User input → scope resolution → context assembly → model generation (tokens)
    2. → tool call intent → Hook pre-processing → Guard → Approval → Sandbox execution
    3. → event persisted → result written back → loop decision → converged output / continue iterating

    7. Advanced Forms: Code Mode, Subagents, and Workflows

    Once the basic loop is stable, more advanced forms can be layered on the same plugin system without changing the kernel:

    • Code Mode: let the model emit executable code to orchestrate multiple tool calls, replacing several round trips with a single generation and reducing loop overhead, but it must be paired with a stricter sandbox and resource limits.
    • SubAgent: launch a restricted instance in a sub scope, isolating context length and tool permissions, suitable for parallelizable exploratory tasks.
    • Workflow: solidify a deterministic process as an orchestration plugin, where the model makes only local decisions inside nodes, used for scenarios with high stability requirements.
    • Self-modifying runtime: allow the runtime to adjust its own plugin composition within a controlled range; this is a high-privilege capability and must be combined with approval and explicit declaration of irreversible effects.

    8. The Designer’s View: How to Build and Validate Your Own Harness

    To implement a similar structure in your own stack, the recommended order is:

    1. Define the invariants first: make it clear that the kernel is only responsible for dependency resolution, scope creation, and event flow, with everything else externalized.
    2. Then define the contracts: define stable interfaces and error semantics for model adapters, tools, and hooks respectively, keeping interface width as small as possible.
    3. Establish an observability baseline: have the event log and metrics in place before attempting dynamic mounting; hot updates that cannot be observed are uncontrollable.
    4. Validate through composition comparison: prepare several minimal and enhanced plugin manifests and observe how the same model behaves differently under different combinations; this is the most effective regression method.
    5. Do isolation last: make the sandbox and resource limits a default rather than an option.

    At the infrastructure level, this kind of runtime can usually be implemented on general cloud capabilities — for example, using a container platform to host sandbox execution, object storage to hold sessions and artifacts, a message queue to asynchronously decouple approvals and tasks, and logging and monitoring services for auditing and anomaly detection. When selecting components, focus on contract stability and replaceability, and avoid binding governance logic to any specific implementation.

    Conclusion

    The contradiction that “models only generate tokens while agents must deliver results” is ultimately resolved by engineering structure rather than prompt techniques. Making every capability a plugin, using two planes and scope contexts to narrow visibility, using three layers of extension to separate knowledge, capability, and governance, and then having a runtime with temporal and spatial composability handle mounting and re-resolution — all of this serves a single goal: making agent behavior replaceable, observable, rollback-able, and verifiable.