AI Agent Architecture: From Model to Execution Harness
This article breaks down the engineering architecture of AI agents, using the formula "Agent = Model + Harness" to explain why a stronger model alone is not enough for real production work. It defines the responsibilities of the execution harness, details key modules such as context management, tool calling, loop control, security and isolation, and observability, and presents a reusable layered architecture. It also lists common anti-patterns and concludes that determinism must be handled on the engineering side.
1. Introduction: Why a “Smart Brain” Is Not Enough
In recent technical discussions, an AI agent is often reduced to “a more capable model.” But in real engineering environments, a system that can only generate text cannot perform any work with side effects: it cannot read your files, invoke your services, or retry after a failure. The industry has gradually converged on a simple formula:
Agent = Model + Harness
The model handles reasoning and generation and acts as the decision-making core. The execution framework (referred to here as the Harness) is the “body” that turns decisions into actions. The original material uses the metaphor of “brain and body”; this article expands it into an engineerable structure: the execution framework is not an accessory, but the key layer that determines whether an agent can be trusted, reproduced, and governed.
2. Defining the Responsibilities of the Execution Harness
Stating responsibilities clearly matters more than piling up features. A mature execution harness typically handles six categories of work:
- Session and context organization: deciding “what the model can see.” This includes history trimming, summary compression, retrieval result injection, and structured memory reads and writes.
- Tool integration and invocation: abstracting external capabilities into a unified callable interface description, and handling parameter validation, timeouts, retries, and idempotency.
- Planning and loop control: managing the multi-turn “think-act-observe” loop, and defining termination conditions, maximum steps, and budget caps.
- State and recovery: saving intermediate artifacts during long tasks, supporting resume after interruption and rollback on failure.
- Security and permissions: least-privilege granting, secondary confirmation for sensitive operations, sandbox isolation, and audit trails.
- Observability and evaluation: recording the input, output, latency, and cost of each step to form a replayable execution trace.
A common mistake is to cram all six categories into the model prompt. A prompt can constrain behavioral tendencies, but it cannot provide deterministic guarantees. Any capability that must “definitely happen” should be pushed down into the execution harness.
3. Engineering Details of Key Modules
3.1 Context Management: The Most Underestimated Cost Center
Context is both the upper bound of capability and a source of cost. The recommended engineering approach is layered handling:
- System layer: role, boundaries, and output specifications. Keep it short and stable for cache reuse.
- Task layer: the current goal, constraints, and acceptance criteria. Replace it as the task switches.
- Evidence layer: retrieval snippets, file contents, and API responses. Load on demand and annotate with source and timestamp.
- Memory layer: cross-session preferences and historical conclusions. Deduplicate and resolve conflicts before writing.
Illustrative context assembly logic:
def build_context(system, task, evidence, memory, budget=8000):parts = [system, task]used = estimate_tokens(parts)for item in sorted(evidence, key=lambda x: x.score, reverse=True):cost = estimate_tokens(item.text)if used + cost > budget:breakparts.append(item.render())used += costif used < budget:parts.append(memory.render(limit=budget - used))return "\n\n".join(parts)
The key is “budget first, sort by value, and truncate explainably,” rather than simply concatenating all history.
3.2 Tool Calling: Caging Uncertainty
Tools are the agent’s only point of contact with the real world, and also the entry point for risk. Recommended practices include:
- Unified description specification: name, purpose, parameter schema, return structure, and error codes, all explicitly declared.
- Upfront parameter validation: complete schema validation and business validation before actual execution, to avoid passing dirty parameters downstream.
- Separate timeouts from retries: distinguish “safe to retry” (read operations, idempotent writes) from “not retryable” (side-effecting and non-idempotent).
- Result trimming: for large objects, return only a summary and locator information; store the full content in object storage for the model to fetch on demand.
{"name": "query_order_status","parameters": {"order_id": "string", "region": "string"},"idempotent": true,"timeout_ms": 3000,"max_retry": 2,"auth_scope": ["read:order"]}
3.3 Loop Control and Budget
A multi-turn loop must have explicit boundaries: maximum steps, total elapsed time, token and cost budget, and repeated-action detection. When the model produces two equivalent calls in a row, it should trigger reflection or forced convergence instead of continuing to consume budget. Termination conditions should include three types: “task achieved,” “budget exhausted,” and “risk threshold reached.” Exit on any one of them and output the current progress.
3.4 Security, Permissions, and Isolation
- Least privilege: grant temporarily per task, and revoke as soon as the task ends.
- Tiered confirmation: read-only operations execute automatically; write and delete operations require explicit confirmation or two-person review.
- Sandboxed execution: code and commands run in an isolated environment, with restricted network egress and filesystem scope.
- Full audit: who did what, to which resource, with what parameters, and at what time must be queryable.
3.5 Observability and Evaluation
Treat the execution trace as a first-class citizen: record the plan, call, observation, and decision rationale at each step. Evaluation has three layers: the result layer looks at task success rate, the process layer looks at step count and rework rate, and the cost layer looks at time and cost per task. Only when the process is replayable can problems be located.
4. A Common Deployment Architecture
A reusable layered structure is as follows:
Access layer (chat / events / scheduled triggers)↓Orchestration layer (task decomposition, loop control, budget)↓Capability layer (tool registry, retrieval, code sandbox)↓Resource layer (object storage, message queue, container platform, logging, monitoring and alerting)
The access layer unifies multiple entry points; the orchestration layer is where the “brain and body” connect; the capability layer stays stateless for horizontal scaling; and the resource layer carries state and observability data. If running in a cloud environment, you can use a container platform to host sandboxes, object storage to save intermediate artifacts, a message queue for asynchronous decoupling, and logging and monitoring systems for tracing and alerting, thereby converging engineering complexity into the orchestration layer.
5. Common Anti-Patterns
- Prompt omnipotence: relying on wording for permissions, retries, and idempotency.
- Unbounded context growth: no budget or compression, leading to out-of-control costs and diluted attention.
- Tools with too coarse a granularity: one tool doing too much, with complex parameters and hard-to-locate errors.
- No termination condition: the loop relies on the model’s “self-discipline” and easily spins idle.
- Evaluating only results, not process: an acceptable success rate but an abnormally high step count, leading to an unacceptable bill at scale.
6. Conclusion
The value division between “model + execution harness” is essentially about leaving uncertainty on the model side and pulling determinism into the engineering side. For developers, what really determines whether an agent can go to production is often not the model parameters, but the “unsexy” parts: context budget, tool contracts, permission boundaries, and observability. Making these four things solid first, and then pursuing capability improvements, is a more reliable evolution path.
