Agent Architecture Explained: Model Plus Harness Engineering Practices

    This article breaks down the common "Model + Harness = Agent" abstraction and explains why a production-grade AI agent is the result of a reasoning core working together with an outer orchestration layer. It covers the four core responsibilities of the harness—context management, tool calling, task planning, and file/state persistence—along with non-functional production concerns such as observability, cost control, concurrency isolation, human-in-the-loop review, and security boundaries. It also highlights common anti-patterns and offers a layered design approach for building stable, scalable, and auditable agent applications.

    1. Why Split an Agent into “Model + Harness”

    In an engineering context, a usable agent is not a natural extension of a single model’s capabilities. It is the result of a reasoning core and an outer orchestration framework working together. A widely used abstraction in the industry is:

    1. Model + Harness = Agent

    The model is responsible for understanding intent, generating candidate actions, and making semantic judgments about results. The harness places the model in a controlled, observable, and recoverable runtime environment, handling context organization, tool registration and invocation, task decomposition and state progression, reading and writing files and external resources, permissions, and auditing.

    The engineering value of this split is that model capabilities iterate quickly but their interfaces remain unstable, while the harness must run reliably over the long term and carry business semantics. Once the two are decoupled, the model becomes a hot-swappable component, and the harness becomes a lasting technical asset for the organization.

    It is important to note that improvements in model capability do not automatically remove the complexity of the harness. A longer context window only raises the capacity ceiling; it does not solve engineering problems such as which information should enter the context, how tool results should be compressed, or how failed tasks should be rolled back.

    2. Four Key Responsibilities of the Harness

    2.1 Context Management

    Context is the scarcest resource for an agent. A mature approach is to divide context into layers, each with its own eviction and compression policy:

    • System layer: role constraints, safety boundaries, and output format conventions that stay resident over the long term;
    • Task layer: goals, acceptance criteria, the current plan, and completed steps, which need to be stored in a structured form;
    • Interaction layer: multi-turn dialogue and tool returns, trimmed by time window and importance;
    • Retrieval layer: snippets pulled on demand from a knowledge base or object storage, released once used.

    A common engineering mistake is to stuff the raw content of tool returns back into the context, which amplifies noise and drives costs out of control. A more robust approach is to produce a structured summary first, then decide whether to keep a reference to the original text.

    2.2 Tool Calling

    Tools are the only channel through which an agent reaches the real world. Three constraints are recommended in the design: a single semantic purpose per interface, strongly typed parameters, and classifiable errors. An illustrative tool description can be written as:

    1. {
    2. "name": "query_metrics",
    3. "description": "Query aggregated metric values by time range",
    4. "parameters": {
    5. "metric": "string",
    6. "start": "string(date-time)",
    7. "end": "string(date-time)",
    8. "granularity": "enum(1m,5m,1h,1d)"
    9. },
    10. "errors": ["INVALID_RANGE", "NO_DATA", "RATE_LIMITED"]
    11. }

    The point of error classification is to let the model choose the right recovery action: parameter errors should be retried with corrections, rate limits should back off and wait, and no data should change the query strategy rather than repeat the same call.

    2.3 Task Planning

    The essence of planning is turning a vague goal into verifiable intermediate states. In practice, a three-stage “plan-execute-verify” flow is recommended, with acceptance conditions defined for each step. When a step fails, prefer local replanning over starting from scratch, which significantly reduces wasted inference overhead.

    A simplified state progression logic looks like this:

    1. plan = planner.decompose(goal, constraints)
    2. while not plan.done():
    3. step = plan.current()
    4. result = executor.run(step, tools)
    5. if verify(step, result):
    6. plan.advance()
    7. else:
    8. plan = planner.replan(goal, plan, failure=result.error)

    2.4 File I/O and State Persistence

    The file system is both a workspace and a memory carrier. It is advisable to manage “temporary artifacts,” “deliverable artifacts,” and “audit logs” in separate directories, and to write via a temporary file followed by an atomic rename to avoid half-finished products after an interruption. All write operations should pass a path allowlist check to prevent unauthorized access.

    3. Production-Oriented Non-Functional Design

    • Observability: bring every model call, tool call, and context snapshot into a unified logging service, with monitoring and alerting to locate long-tail latency;
    • Cost control: distinguish high-frequency lightweight inference from low-frequency deep inference, routing the former to a fast, smaller-parameter model and the latter to a more capable model;
    • Concurrency and isolation: when running multiple tasks in parallel, assign each task an independent workspace and quota to avoid cross-contamination of contexts;
    • Human-in-the-loop: introduce confirmation and editable drafts at key points, so people can directly correct intermediate artifacts instead of restating requirements;
    • Security boundaries: apply least privilege to tool permissions, require a second confirmation for sensitive operations, and keep end-to-end traces for retrospection.

    4. Common Anti-Patterns

    The first is treating prompts as architecture, lacking a state machine and persistence, which becomes unmaintainable as tasks multiply. The second is tools with too coarse a granularity, where a single tool takes on too many responsibilities and the model struggles to choose correctly. The third is the absence of a verification stage, so errors only surface at the end of the chain and rework becomes very costly. The fourth is ignoring the context budget, so quality declines monotonically as turns accumulate.

    5. Conclusion

    The key to engineering agents is not pursuing the limit of a single model’s capability, but making the harness solid: clear context layering, tool contracts with explicit semantics, a verifiable planning flow, and reliable file and state management, plus complete observability and cost strategies. Baidu AI Cloud also emphasizes combining model capabilities with platform-based runtime and governance in its related engineering practice, an approach consistent with the layered design direction of this article. With these methods, teams can build stable, scalable, and auditable agent applications at a low trial-and-error cost.