Agent Architecture Best Practices: A Guide to Decoupling Models from the Harness
This article explains why monolithic agents become hard to maintain and how a layered architecture solves the problem by separating the model from the harness. You will learn the core principle that an agent equals a model plus a harness, the capability boundaries of five pluggable component layers (model, tool, memory, sandbox, and planning), and a step-by-step approach to building a replaceable agent with tool contracts, provider abstraction, isolated execution, approval gates, and explicit plans. It also covers subscription-based provisioning, budget governance, common anti-patterns, and a pre-launch acceptance checklist.
Agent Architecture Best Practices: A Guide to Decoupling Models from the Harness
1. The Problem: Why “All-in-One Agents” Are Hard to Maintain
Over the past two years, most agent projects have followed the same curve: a prototype runs in two weeks, but maintenance costs rise sharply once it enters real production. The cause is usually not insufficient model capability, but an architecture that piles too many responsibilities into a single layer. When reasoning, tool invocation, state persistence, execution isolation, and flow control are all coupled within one process, any change triggers a chain of modifications: swapping the model requires rewriting prompts and parsing logic, adding a tool means touching the main flow, and switching to a new memory approach forces changes to business code.
The pain points tend to cluster in four areas. First, model lock-in: the business is bound to a single inference interface and cannot select models by task cost-benefit tiers. Second, tool sprawl: as plugins grow, there is no unified registration, authentication, or rate limiting, making failed calls hard to diagnose. Third, disordered memory: conversation history, task state, and long-term knowledge are mixed together, so the context keeps growing while effectiveness drops. Fourth, execution risk: once an agent that can write files, send requests, and modify configurations makes a wrong judgment, the blast radius is uncontrollable.
This is exactly the value of layered decoupling: separate the “thinking part” from the “execution framework” so each can evolve independently.
2. Core Principle: Agent = Model + Harness
The industry is converging on a simple formula: an agent equals a model plus a harness. The model handles understanding, reasoning, and generation; the harness handles scheduling, constraints, and state maintenance. The two communicate through well-defined interfaces, so replacing either side does not affect the business semantics of the other.
A sufficiently “thin” harness typically does only three things:
- Scheduling: route user intent to the model, route the tool-call requests produced by the model to the corresponding implementations, and feed the results back into the context.
- Approval: pause execution before irreversible or high-impact operations, request human confirmation, and keep a complete decision record.
- Planning: maintain an explicit task list that marks completed, in-progress, and blocked items, making long-running tasks recoverable.
The harness is deliberately kept lightweight to avoid baking volatile business rules into the core. Composability, replaceability, and extensibility should live in slots, not in modifications to the main trunk.
3. Capability Boundaries of Five Pluggable Components
Splitting an agent into five component types is the key to controlling complexity. Each type solves only one class of problem, and clear boundaries allow independent evolution.
- Model layer: provides omni-modal capabilities such as text generation, image generation, video generation, and vectorization. In engineering, it is advisable to tier by task—for example, hard reasoning goes to large-parameter models, batch extraction and classification go to lightweight models, and vectorization goes through a dedicated embedding interface.
- Tool layer: wraps external system capabilities as functions with explicit signatures, including name, purpose description, parameter structure, and return structure. Description quality directly determines how accurately the model selects tools.
- Memory layer: distinguishes short-term context, task state, and long-term knowledge, using different storage and retrieval strategies for each.
- Sandbox layer: provides isolated environments for code execution, file read/write, and network access, with limits on resources and permissions.
- Planning layer: replaces implicit chains of thought with explicit plans, supporting decomposition, reordering, rollback, and resume from breakpoints.
4. Implementation Steps: Building a Replaceable Agent from Scratch
Step one: define the tool contract first. If the contract is unstable, every later replacement will fail.
# Illustrative code: tool contract and registryfrom dataclasses import dataclassfrom typing import Callable, Any@dataclassclass ToolSpec:name: strdescription: strparameters: dict # parameter structure descriptionhandler: Callable[..., Any]risk: str = "low" # low / medium / highREGISTRY: dict[str, ToolSpec] = {}def register(spec: ToolSpec) -> ToolSpec:REGISTRY[spec.name] = specreturn spec
Step two: connect model providers. The mainstream approach is a provider abstraction plus custom integrations, switching inference backends through unified configuration. The business side depends only on a unified interface and stays unaware of the specific implementation.
Step three: connect memory. Keep only necessary fragments in short-term context, write long-term knowledge to a retrieval store, and persist task state separately, avoiding cross-contamination among the three types of information.
Step four: add a sandbox. All code execution and file operations happen in an isolated environment with no external network by default, read-only mounts, and explicit timeout and memory limits.
Step five: embed approval into the scheduling loop. Risk levels are declared by the tool contract, and the harness intercepts before execution:
def dispatch(tool_name: str, args: dict, approver):spec = REGISTRY[tool_name]if spec.risk == "high" and not approver.confirm(spec.name, args):return {"status": "rejected", "reason": "user_declined"}return {"status": "ok", "data": spec.handler(**args)}
Step six: maintain an explicit plan. The plan is structured data rather than natural language, making it easy to validate and recover:
{"goal": "Generate a quarterly data summary","steps": [{"id": 1, "action": "query_data", "state": "done"},{"id": 2, "action": "render_chart", "state": "running"},{"id": 3, "action": "publish_report", "state": "blocked", "risk": "high"}]}
5. Subscription-Based Provisioning and Budget Governance
Once the components are in place, the second bottleneck is quota and cost. Purchasing model, retrieval, and storage quotas item by item scatters the bill and makes attribution difficult. A more robust approach is unified subscription with unified quota deduction: one subscription covers model calls and consumption of all framework components, quotas are accounted centrally, and budgets are allocated by project or environment.
Three governance measures are needed alongside this. First, call-level quotas that cap the maximum number of steps and maximum consumption per task. Second, tiered degradation that automatically switches to lightweight models or skips non-critical retrieval when quota is tight. Third, observability that writes every tool call, approval, and model request to a logging service with monitoring and alerting configured, forming a traceable chain. If artifacts and datasets are involved, they can land in object storage; asynchronous tasks can be decoupled through a message queue. Use only generic capability categories here; specific choices should be evaluated against the corresponding products of your own cloud platform.
6. Common Anti-Patterns and an Acceptance Checklist
Anti-patterns include: writing business rules into the harness core; vague tool descriptions that cause wrong invocations; using conversation history alone as memory; high-risk operations without approval; plans hidden in natural language that cannot be validated; and missing failure retry and idempotency design.
Before launch, run through this checklist item by item: can you swap the model without changing business code; does adding a tool require only registration; do high-risk actions have confirmation and auditing; can the process recover according to the plan after an interruption; does the sandbox default to least privilege; can quota be attributed to tasks; is the full chain observable. If all pass, the layering is truly working, and the agent is capable of long-term evolution.
