Agent Harness Architecture: A Practical Guide to Building a Thin Kernel with Pluggable Components
This article explains the Agent Harness architecture, the runtime layer that connects language models to real-world execution through tool calls, external data access, state persistence, sandboxing, and retry logic. It covers why a thin kernel limited to scheduling, approval, and planning is more maintainable than hardcoding capabilities into business code, and describes five replaceable component layers: model, tool, memory, sandbox, and agent strategy. You will also find the default-deny control loop, model abstraction patterns, tool risk tiers, a three-layer memory design, sandbox and human-in-the-loop approval practices, explicit task plans for recoverability, a four-dimension selection framework with a phased rollout path, and common anti-patterns to avoid.
1. The Problem: Why Agents Need a Thin Kernel
Two years of agent engineering practice have shown the same thing repeatedly: what sets the ceiling of a system is usually not the parameter count of the model, but the runtime structure built around it. The industry commonly calls this structure the Harness. It is what connects model capability to the real world: invoking tools, reading and writing external data, persisting intermediate state, isolating untrusted code, and retrying or rolling back on failure.
The early approach was to hardcode these capabilities into business code. The result: swap the model, add a tool, or change a permission, and the entire system has to be modified. A more sensible direction is to keep the kernel as thin as possible, retaining only three responsibilities that cannot be replaced:
- Scheduling: decompose user intent into steps, decide which model and which tool each step calls, and manage context and result write-back.
- Approval: pause before executing irreversible or high-impact actions, request human confirmation, and produce an auditable authorization record.
- Planning: maintain an explicit, readable, persistable task plan so that long-running flows are recoverable and observable.
Everything else is pushed down into plugins. The value of this tradeoff is a stable kernel with an active ecosystem: upgrading a component does not require touching the mainline logic.
2. Overall Architecture: Five Pluggable Component Types and One Control Loop
A mature agent runtime typically contains five replaceable component types:
- Model layer: onboarding models of different modalities and sizes for text generation, image generation, video generation, and embedding.
- Tool layer: search, data queries, code execution, file operations, and external API calls.
- Memory layer: short-term context, long-term vector retrieval, and structured fact storage.
- Sandbox layer: an isolated environment for untrusted code and file changes.
- Agent strategy layer: planning approach, reflection mechanism, termination conditions, and multi-agent collaboration patterns.
The control loop can be abstracted as:
User request→ Planner creates/updates the task plan→ Scheduler selects model and tools→ Sandbox execution→ Result validation→ High-risk action? → Human approval→ Memory write→ Done? → No, back to scheduling
The key design principle of this loop is “default deny, explicit allow”: tool inventories are whitelisted, permissions are minimal, and every action that crosses a boundary leaves a log.
3. Model Integration: Hiding Differences Behind a Unified Abstraction
The model layer should be abstracted behind a unified interface that hides differences between providers in authentication, parameter naming, and streaming responses. A sketch of the definition:
class ModelPlugin:def chat(self, messages, **options): ...def embed(self, texts): ...def generate_image(self, prompt, **options): ...
Practical recommendations:
- Manage providers, keys, and quotas centrally in configuration. Read keys only from environment variables or a key management service; never commit them to the codebase.
- Bind different models to different tasks: a strong reasoning model for planning, a low-cost model for bulk extraction, a dedicated embedding model for vectorization.
- Record the model identifier, latency, and token consumption of every call uniformly, so cost can be attributed and quality regressions can be tracked.
4. Tools and Memory: Making the Agent Able to Work and to Remember
The core of the tool layer is not quantity but description quality. Each tool needs a clear name, purpose, parameter schema, and error semantics so the model can select it correctly. Tag tools with a risk level in three tiers: read-only, writable, and irreversible. The latter two must go through approval.
The memory layer is best split into three tiers:
- Working memory: intermediate results of the current task, reclaimed when the session ends.
- Episodic memory: summaries of past interactions, used for continuity across turns.
- Semantic memory: cleaned facts and a vector index, used for retrieval augmentation.
For write strategy, distinguish “raw records” from “distilled conclusions” so noise does not pollute retrieval results over the long term. Also design masking and expiration cleanup for sensitive fields.
5. Sandbox and Approval: Engineering the Security Boundary
The sandbox handles two kinds of isolation: isolation of the filesystem write scope and isolation of network egress. A common approach is containerized execution, mounting the base image read-only, restricting accessible directories, applying domain-level allowlisting for outbound traffic, and setting limits on execution duration and resources.
Approval should achieve three things: actions are previewable (show the command to be executed or the diff of the change), authorization is scoped (one-time, per-session, or a long-term allowlist), and the process is traceable (who approved what, and when). Sketch of the logic:
if tool.risk in ("write", "irreversible") and not policy.allow(session, tool):plan.pause(approval=ApprovalPreview(tool, arguments))
6. Task Plans: The Source of Recoverability for Long Flows
An explicit plan yields three benefits. First, recoverability: after a process restart, execution resumes from the plan. Second, intervention: a human can insert or skip a step. Third, evaluability: the deviation between plan and actual execution is a good quality metric. A plan item should include the goal, dependencies, status, output location, and acceptance criteria, and should stay in human-readable plain text so it can be version-controlled and reviewed.
7. Selection and Adoption Path
Score candidate components on four dimensions: capability coverage, replaceability, permission granularity, and observability. Adopt in three phases: first get a read-only scenario working (search plus summarization), then introduce writes and sandbox execution, and finally add long-term memory and self-improvement mechanisms. Each phase should come with an evaluation set and a regression baseline, to avoid “looks smarter, actually less controllable.”
8. Common Anti-Patterns
- Turning approval into an after-the-fact log, which loses its interception value.
- Vague tool descriptions, which lead to wrong selections and duplicate calls by the model.
- Memory that is only written and never cleaned, so retrieval quality decays quickly over time.
- Plans hidden inside the model context, which cannot be persisted or recovered.
- Granting permissions all at once, with no minimization or revocation mechanism.
Conclusion
A thin kernel plus pluggable components moves complexity from the mainline to the edges: the kernel provides order, and plugins provide capability. When the model, tools, memory, sandbox, and strategy can each be replaced independently, the agent system becomes capable of continuous evolution, while approval and planning keep that evolution on a track humans control.
