AI Agent Harness Architecture: Principles and Production Implementation

    When AI agent applications move from demo to production, the most common failures stem from software architecture rather than model parameters. The Harness architecture provides a stable structural layer that turns model generation into executable, auditable, and replayable task processes. This article explores the core principles of building a robust agent runtime, covering the separation of product and runtime, the "everything is a plugin" philosophy, execution boundaries including guards and sandboxes, and strategies for composability, event logging, and validation to ensure reliable production deployment.

    When agent applications transition from demos to production, the most common failures do not stem from model parameters but from software organization. The same prompt behaves completely differently when tools, permissions, or session strategies change, without a stable structure to make these differences explicit. The Harness (capability harness) is this structural layer. It does not replace model inference; instead, it constrains “generation” into an “executable, auditable, and replayable task process.”

    1. Separating Product from Runtime

    User-facing agent products solve scenarios: Q&A, office collaboration, R&D assistance, and process management. Runtimes solve mechanisms: what can be called in this turn, whether human confirmation is needed before calling, how to roll back on failure, where context is written, and from which state the next turn resumes.

    Mixing these into a giant script may work short-term but leads to three long-term problems:

    • Capability coupling: Changing model providers requires modifying the loop; adding a tool means changing the main flow; changing the session format invalidates all history replays.
    • Unclear boundaries: Model output is directly treated as an executable action, lacking validation, approval, and isolation. Risk and functionality are bound on the same path.
    • Inability to compare: The same model behaves differently under “read-only retrieval,” “executable code,” or “strict approval,” but teams lack standard combinations to reproduce experiments.

    A more robust approach is: The product layer declares goals and interactions, while the runtime layer declares capability combinations and execution strategies. The model adapter only translates unified messages and tool descriptions into specific inference interfaces, without owning the business process.

    2. Everything is a Plugin

    “Everything is a plugin” does not mean breaking code into pieces; it defines the minimum contract for extension. Each capability is a unit that is declarable, mountable, unmountable, and re-parsable by a dependency graph. Model access, tool registration, skill descriptions, session recording, loop strategies, and observability tracing all use the same combination mechanism rather than special branches in the main program.

    A plugin usually specifies four things:

    1. What it provides: For example, registering a set of tool descriptions, a skill description, or a session storage.
    2. What it depends on: For example, depending on the “current workspace,” “model client,” or “approval service.” Missing dependencies should not silently degrade to dangerous defaults.
    3. Lifecycle: What happens during load, ready, deactivate, and unload; how in-progress calls are drained during hot updates.
    4. Effect boundary: Whether it can write files, send network requests, or modify other plugins’ registries. Effects must be explicit, not implicit global variables.

    A Preset is a verified combination of plugins, not another prompt template. Mounting different presets on the same model equates to changing runtime capabilities, not changing the “persona.” It is recommended to prepare at least four control combinations for regression:

    • Standard combination: Tool calls, basic skills, session logs, and standard guardrails complete, serving as the daily baseline.
    • Programmatic combination: Allows executing generated code or scripts in a controlled environment, emphasizing isolation and resource limits.
    • Minimal combination: Almost only conversation and read-only context, used to determine if a problem originates from the model or the toolchain.
    • Creative combination: Relaxes formats and tools but tightens external side effects, suitable for drafting and scheme deduction.

    When comparing, fix the model, temperature, input tasks, and evaluation set, changing only the plugin set. Otherwise, it is impossible to tell if behavioral changes come from capability boundaries or random sampling.

    3. Two Planes and Three Extension Types

    The runtime can be divided into the Host Plane and the Agent Plane. The Host Plane manages processes, configurations, workspaces, secret management, logging, and plugin loading, with a lifecycle longer than a single task. The Agent Plane manages goals, messages, tool results, and loop state within a turn or session, with a short lifecycle that must be serializable.

    Scope Context clarifies “who can see what within which scope”: global configuration, workspace, session, single run, subtask. Tools and skills inherit the nearest scope by default, rather than reading process environment variables everywhere. Secrets are resolved only on the host side; capability handles, not plaintext credentials, should enter the model context.

    Extensions are divided into three layers based on proximity to execution, preventing all requirements from being stuffed into tool functions:

    • Skill: Procedural knowledge given to the model, explaining when to use a certain approach, I/O conventions, and fallbacks on failure. It changes decisions but does not directly cause side effects.
    • Tool: Typed operations on the external world. Descriptions must include parameter schemas, idempotency, read-only or write, timeouts, and error codes. The model can only initiate call intents; actual execution happens in the runtime.
    • Hook: Plugged into fixed points in the loop, such as before planning, before tool, after tool, and turn end. Suitable for truncation, desensitization, billing tags, and trajectory collection, but not for carrying complex business logic.

    A schematic registration method can remain framework-agnostic:

    1. register({
    2. name: "read_doc",
    3. effect: "read",
    4. scope: "workspace",
    5. schema: { path: "string" },
    6. before: ["guard", "approval"],
    7. handler: readWithinWorkspace
    8. })

    No vendor interfaces are bound here; it only emphasizes that effects, scope, schema, and pre-hooks are part of the declaration.

    4. Execution Boundaries: Guard, Approval, Sandbox

    The danger of generative loops is that the “next action is decided by the model.” Boundaries must be separated, not replaced by a single system prompt.

    Guard represents deterministic rules: whether parameters match the schema, whether paths escape the workspace, whether unregistered tools are called, and whether the output contains sensitive fragments that should not be returned. If a rule fails, execution is rejected and does not proceed.

    Approval represents policy and responsibility: high-risk writes, external sends, batch deletions, and other actions require explicit clearance from a human or upstream policy engine. Approval records must be kept alongside session events; otherwise, it is impossible to explain post hoc why something was executed.

    Sandbox represents isolation: when the combination allows executing code or commands, it limits the file system view, network, CPU, and time limit, and returns the result to the loop as a tool return value. A sandbox is not a prompt saying “please do not do dangerous operations.”

    The recommended fixed order is: Schema and Guard -> Approval (if needed) -> Execute in isolated environment -> Desensitize result before entering the next round of context. Failure at any layer should be written as a structured event, not just a natural language pop-up on the UI.

    5. Composable Runtime: Time, Space, and Fibers

    If plugins can only be hardcoded at startup, presets cannot be experimented with, and hot updates become impossible. Composable runtimes typically provide two types of composability.

    Temporal composability: Plugins join or exit by phase. For example, mount read-only tools first for reconnaissance, and mount write tools after confirmation. Phase transitions must re-parse dependencies to prevent old plugins from retaining handles they shouldn’t have in the new phase.

    Spatial composability: Multiple agent planes can coexist within the same host, each with its own plugin subset. Parent and child tasks do not share mutable registries; when collaboration is needed, they communicate via explicit messages or task handles, not implicit singletons in shared memory.

    The effect boundary turns “what side effects this plugin might cause” into a type or declaration. The runtime uses this to decide whether to allow it in a specific preset. Plugins without declared effects should not enter executable combinations.

    A Fiber can be understood as a logical thread of a run: it carries goals, messages, pending tool calls, cancellation signals, and checkpoints. The loop generates an event with each step forward; after a crash, it recovers from the latest checkpoint instead of throwing the entire conversation back to the model and hoping for the best. Cancellation must be able to propagate to tools and subtasks; otherwise, the “stop” the user sees is just a UI state.

    The baseline for hot updates is: in-progress fibers continue using the old combination until a turn boundary, while new fibers use the new combination. Replacing a currently executing tool implementation midway is the most common source of non-deterministic behavior.

    6. Loop, Event Log, and From Tool to Runtime

    The agent loop can be converged into an observable chain, rather than an infinite free conversation.

    1. Assemble context: System constraints, skills, summaries or raw text of historical events, current goal.
    2. Request model: Only allowed to return text, or text plus structured tool calls.
    3. Parse and validate: If parsing fails, log a failure event and retry or ask the user according to strategy.
    4. Execute or reject: Execute after passing guard, approval, sandbox.
    5. Write back event: Tool name, parameter summary, result summary, time consumed, error type.
    6. Determine termination: Goal achieved, step limit reached, user canceled, or consecutive failures.

    The session event log is the source of truth for the runtime. The chat bubbles in the UI are just projections. The log should at least distinguish: user input, model output, tool intent, execution result, approval decision, policy rejection, checkpoint. With it, you can replay, compare presets, and locate whether the model chose the wrong tool or the tool implementation didn’t match the contract.

    The gap from a single tool call to a complete runtime lies in state ownership. A tool is a stateless function; the runtime owns the loop, memory strategy, subtasks, and stop conditions. If a product only encapsulates “function call parsing,” it still needs to add step budgets, duplicate call detection, result truncation, and context compression, otherwise long tasks will lose control over tokens and costs.

    Advanced capabilities should also fall within the same plugin model, rather than forking into a second architecture.

    • Code mode: Delegates multi-step deterministic logic to a controlled execution environment. The model is responsible for generation and explanation, while the runtime handles limits and returns.
    • Sub-agent: The parent fiber spawns child fibers, which use narrower presets. The subtask returns conclusions and evidence references, not infinitely exposing all tool permissions upward.
    • Workflow: Express strongly sequential, compensable steps as explicit nodes, where the model only makes judgments inside the nodes. Side effects that can be expressed via a process should not be entirely handed over to an open loop.
    • Evolvable runtime: Allows registering new skills or tool descriptions under policy permission, but the registration itself must go through guards and approvals and be written to events. Running tasks are forbidden from silently rewriting their own permissions.

    7. How to Design and Validate When Self-Building

    When building a Harness yourself, don’t chase feature quantity first. Establish a minimal closed loop in the following order:

    • Define the event model and workspace boundary to ensure any action is recordable and confined.
    • Implement a read-only tool and a write tool, forcing the write to go through approval.
    • Make the model adapter a plugin; use a fake model (returns fixed tool calls) to run through the loop, then connect real inference.
    • Create two presets: minimal and standard. Compare steps, rejections, and boundary violations on the same set of tasks.
    • Add step limits, timeouts, cancellation, and checkpoints to fibers. Ensure it can stop first, then talk about intelligence.
    • Finally, add subtasks, code execution, and hot updates. For each addition, add a test for “what it cannot do.”

    Validation shouldn’t just look at whether the final answer is correct. Check at least: whether unregistered tools are rejected, whether path traversal fails, whether writes occur when approval is missing, whether logs can independently replay decisions, and whether permissions tighten according to the dependency graph after switching presets. These use cases explain whether the architecture holds better than subjective “usability.”

    If the team already has cloud container platforms, object storage, message queues, logging, and monitoring, they can place workspace files, event logs, and approval flows on corresponding general capabilities, but don’t let the cloud resource model inversely dictate the agent’s loop semantics. The runtime’s own state machine should remain clear; external systems are just for persistence and delivery.

    8. Trade-offs in Implementation

    Pluginization increases startup and understanding costs. In the prototyping phase, a single process and in-memory session can be used, as long as contracts are written as plugins, avoiding hardcoding shortcuts. After entering multi-tenancy or long tasks, add session persistence, cancellation propagation, and preset isolation.

    Don’t make all logic dynamically composable either. Authentication, tenant isolation, and secret management are suitable for controlled modules in the host, only making “replaceable capabilities” into plugins. Over-dynamization makes the dependency graph impossible to review manually.

    To judge if a Harness is qualified, ask four questions: Does changing the model require changing the loop? Is tightening permissions a config change or a code change? Can a failure be reviewed from the event log? Are dangerous actions structurally intercepted before execution? If all four answers point to the runtime rather than a specific prompt, this organizational approach stands firm.

    The core contradiction of agent software will not disappear: the model continuously generates uncertain next steps, while the business requires predictable side effects. The value of the Harness is using plugin combinations, scopes, guardrails, and replayable events to confine this uncertainty within designed boundaries, allowing teams to discuss, replace, and validate these boundaries using the same language.