← Back to the journal

build · September 2026

Harness Engineering for AI Agents

Why the system around the model may matter as much as the model itself—and how to engineer context, tools, state, verification, recovery, and control as one reliable execution environment.

Harness Engineering for AI Agents

For several years, the default way to improve an AI application was to reach for a better model, a better prompt, or better retrieval. Those choices still matter. But once a system can plan, call tools, modify an environment, wait for external events, and continue over many steps, the foundation model is only one part of the engineering problem.

The surrounding execution system determines what the model sees, which actions it may take, how progress survives interruption, when work is accepted, and how failures are contained. That surrounding system is the agent harness.

What is an agent harness?

An agent harness is the model-external system that turns a request into a controlled execution trajectory. It assembles context, exposes tools, chooses orchestration patterns, preserves state, enforces policy, records evidence, and decides whether the task should continue, pause, recover, or stop.

Side-by-side comparison of a simple LLM application that produces one response and an enterprise agent surrounded by context, state, planning, tools, memory, routing, verification, recovery, permissions, observability and evaluation
A simple LLM application produces a response. An enterprise agent operates through a harness that manages goals, actions, state, evidence, controls, and iteration.
Model responsibilityHarness responsibility
Reason about ambiguity and choose a next action.Define the available actions, their contracts, and their permissions.
Interpret evidence supplied in context.Retrieve, filter, prioritize, and format that evidence.
Propose a plan or decision.Validate structure, enforce budgets, and require approvals.
Adapt after observing a result.Persist state, prevent duplicate effects, and classify failures.
Generate or evaluate semantic content.Run deterministic tests, record traces, and decide whether acceptance criteria are met.

This distinction matters because many failures blamed on “the model” are actually system failures: irrelevant context, ambiguous tool descriptions, missing state, unsafe permissions, weak stopping conditions, or a verifier that never tested the result.

Why harness engineering has become important

A short assistant interaction can often fit inside one context window and end with a draft for a human to review. An operational agent may run for hours, call remote services, create irreversible side effects, delegate work, and recover after infrastructure failures. The engineering center of gravity therefore shifts from response quality to execution quality.

  • Long-running work: progress must survive context limits, process restarts, and human delays.
  • Large tool catalogs: the system must expose the right capabilities without flooding the model with schemas.
  • Consequential actions: identity, authorization, approvals, and argument validation must sit at the tool boundary.
  • Variable behavior: plans, state transitions, outputs, and stopping criteria need explicit structure where repeatability matters.
  • Operational accountability: teams need trajectories, costs, policy decisions, and evidence—not only the final answer.
Five-stage autonomous agent loop moving from a goal to an agent decision, a tool call, observation of the tool result, and a new decision that repeats until the goal is achieved
Autonomy is produced by the execution loop: decide, act, observe, update state, and repeat within defined limits.

The loop explains how autonomy unfolds, but it does not by itself create reliability. Execution quality is an end-to-end property: context, tools, control flow, state, verification, and recovery can each become the limiting factor.

System capability shown as the combined effect of model capability, context quality, tool quality, execution strategy, state management, verification and recovery
A capable model helps, but dependable work depends on the quality of the complete system around it.

This is a heuristic, not a literal equation. Its value is architectural: a severe weakness in any layer can dominate the outcome even when the model is excellent.

The eight load-bearing layers

1. Context engineering

Context engineering decides what the model should know at this moment. Good context is selective and structured: the current goal, relevant evidence, recent observations, applicable policy, available actions, and a concise representation of progress. More context is not automatically better; irrelevant history competes with the information that actually drives the next decision.

An AI agent receiving context from system instructions, conversation history, business rules, a user profile, task state, retrieved documents, files, tool descriptions, tool results, memory, other agents, previous plans, errors and environment state
Context is assembled from many sources. The harness must select what is relevant now rather than loading everything indiscriminately.

2. Tool engineering

Tools are the agent’s action surface. Their names, descriptions, schemas, error semantics, and permission boundaries directly shape behavior. Strong tool contracts are narrow, typed, observable, and explicit about side effects. With a large catalog, retrieval or routing can expose only the tools relevant to the current task rather than placing every schema in context.

Dynamic tool-selection workflow in which a task searches a large tool catalog, retrieves a relevant subset, lets the model choose among those tools, executes the selected tool and returns the result for the next action
Dynamic retrieval keeps large tool catalogs out of the working context while still giving the agent access to the capabilities it needs.

3. Planning

Planning makes intent inspectable. A structured plan can define steps, dependencies, expected evidence, budgets, and completion criteria before tools execute. Recent preprint evidence suggests that schema-validated planning can improve reproducibility in some model-task combinations, while also showing that constraints can reduce performance or increase latency when poorly matched. Planning therefore needs evaluation, not ceremony.

Planner creates a structured sequence of steps, tools, inputs and expected outputs, then an executor carries out the plan against external systems, tools, data and applications
Separating planning from execution makes intent inspectable while allowing the executor to handle tools, results, errors, and retries.

4. Orchestration

Orchestration determines how work is decomposed and coordinated. Useful patterns include prompt chaining, routing, parallel workers, orchestrator-worker systems, and evaluator-optimizer loops. The simplest pattern that meets the requirement is usually the best starting point. Multi-agent designs are justified when specialization, parallelism, or independent judgment creates measurable lift.

A request enters a classifier and router that applies intent, context and policy rules before directing it to a support, finance or technical specialist agent
Routing is useful when requests need different expertise, policies, models, or tool sets.
PatternUse it whenWatch for
Sequential workflowThe process has clear, dependent stages.Rigid flows can fail on exceptions or novel tasks.
RouterTasks vary by difficulty, domain, model, or tool set.Routing errors can outweigh model or cost gains.
Parallel workersSubtasks are independent and synthesis is well defined.Duplicate work, contradictory findings, and higher cost.
Planner–executorThe system benefits from separating intent from implementation.Plans can become stale or over-prescriptive.
Generator–evaluatorQuality requires skeptical, criteria-based review.The evaluator itself must be calibrated and tested.

Routing selects one specialist for a request. Parallel orchestration solves a different problem: it assigns genuinely independent subproblems to multiple workers, then reconciles their evidence through an explicit synthesis step.

A research orchestrator delegates work to three parallel specialist agents and then combines their findings through a synthesis step
Parallel agents help when subtasks are genuinely independent and the synthesis contract is explicit.

5. State and memory

Working context, workflow state, persistent memory, artifact state, and execution state are different things. Treating chat history as the database for all five creates fragile systems. Compaction can preserve continuity when recent conversational detail still matters; a context reset is safer when accumulated history has become noisy, provided the next session receives a structured handoff. Long-running work benefits from progress artifacts that record the goal, completed work, current state, changed artifacts, known failures, constraints, and next steps.

Comparison of two context-management strategies: compaction summarizes a large conversation while retaining recent context so work can continue, while context reset converts an old noisy session into a structured handoff and starts a fresh session with only that curated information
Compaction preserves conversational continuity. A reset deliberately clears accumulated noise and resumes from a structured handoff. The right choice depends on whether the old context still improves the next decision.

In either case, continuity should come from an explicit state artifact rather than the hidden memory of a particular conversation. That artifact becomes the contract between sessions: what was completed, what changed, what remains open, and what the next run must verify before continuing.

A multi-session workflow where session one performs work, saves a progress artifact and resets context, then session two reads the saved artifact and continues from the recorded state
Structured progress artifacts let a fresh session continue without relying on an overloaded conversation history.

6. Durable execution

Memory does not prevent a purchase order, email, or deployment from being performed twice after a crash. Durable agents need familiar distributed-systems mechanisms: checkpoints, persisted workflow state, bounded retries, timeouts, idempotency keys, pause and resume, and compensation for partially completed operations. The runtime increasingly resembles a workflow engine plus a model runtime plus a state store.

7. Recovery engineering

A useful recovery policy distinguishes transient failures from semantic failures. A network timeout may justify a bounded retry. An invalid tool choice may require replanning. Conflicting evidence may require clarification. A policy violation should stop or escalate. Every loop needs budgets for steps, retries, elapsed time, and external cost.

The common recoverable paths are retry and replan, as shown below. They are not universal continuation rules: exhausted budgets, unsafe requests, unclear intent, and policy violations must leave the autonomous loop for escalation or termination.

Tool-call recovery flow where a failed call is classified as transient or semantic: transient failures use bounded backoff and retry, while semantic failures revise the plan, inputs or tool choice before execution continues
Classify before recovering: retry transient infrastructure failures within a strict budget; replan semantic failures; escalate or stop when neither path can safely restore progress.

8. Human control

A mature harness knows when autonomy should end. High financial impact, irreversible actions, low confidence, policy exceptions, missing information, and security signals should trigger an exact interruption: preserve the proposed action and execution state, obtain approval or rejection, then resume the same run. The human should approve a specific action—not a vague continuation.

Verification must be independent from generation

Asking one agent to create an artifact and then casually judge its own work often produces lenient evaluation. A stronger architecture separates creation from acceptance. The verifier can be another model tuned to skeptical criteria, but it can also be unit tests, integration tests, schema validators, simulations, security scanners, business rules, or a human reviewer.

Iterative generation workflow moving from a planner and specification to a generator, artifact, independent evaluator and structured feedback that loops back to improve the generator output
Separate creation from judgment: define criteria first, evaluate the artifact independently, and return specific feedback through a bounded repair loop.

Anthropic’s 2026 long-running application experiments illustrate both the upside and the cost. A planner–generator–evaluator harness produced a much more functional application than a solo run in one comparison, but consumed dramatically more time and money. The lesson is not “always use three agents.” It is to separate creation from judgment when the measured improvement justifies the overhead.

Guardrails belong at the action boundary

An agent can propose an action; the harness decides whether that proposal reaches the environment. Tool allowlists, identity checks, scoped credentials, argument validation, approval rules, rate limits, sandboxes, network controls, and data-loss prevention should be enforced where the side effect occurs.

  • Before execution: authenticate the actor, authorize the action, validate arguments, and check whether approval is required.
  • During execution: enforce time, cost, network, and resource limits.
  • After execution: capture the result, update state, record policy and tool versions, and verify the outcome.
  • On failure: classify the error and choose retry, replan, compensate, escalate, or stop.

Observability is the feedback system

A final response cannot explain a long-running agent. Teams need the trajectory: model calls, retrieved evidence, plans, tool selections, arguments, results, handoffs, guardrail decisions, retries, approvals, and state transitions. Traces let engineers locate the failing layer instead of rewriting the prompt by instinct.

Metrics for the harness—not only the answer

OUTCOMETask success

Acceptance criteria, business result, and reproducibility.

TRAJECTORYExecution quality

Tool correctness, steps, retries, recovery, and invalid actions prevented.

EFFICIENCYOperational cost

Tokens, latency, elapsed time, external spend, and human escalations.

RESILIENCEState recovery

Resume success, duplicate effects prevented, and evidence completeness.

Engineer the harness empirically

A six-step cycle: establish a minimal baseline, inspect traces, classify failure, add one intervention, compare quality cost and latency, then remove components that do not help
Harness design should follow observed failures. Add one intervention, measure it, and remove components that are no longer load-bearing.
  • Establish a baseline: begin with one capable model, minimal tools, and the simplest loop that can complete the task.
  • Study realistic failures: inspect trajectories and classify failures by context, planning, tools, state, verification, recovery, or control.
  • Add one intervention: introduce a router, structured plan, external state, verifier, approval gate, or durable workflow for a specific failure mode.
  • Run the same evaluation: compare success, quality, cost, latency, retries, and operational risk.
  • Perform ablations: remove the component and confirm that performance falls. If it does not, delete the component.
  • Repeat when models change: a harness designed around one model’s weaknesses may become unnecessary—or actively harmful—after a model upgrade.

Five useful harness families

ArchitectureBest fitPrimary trade-off
Minimal agent loopShort, open-ended, low-consequence tasks.Maximum flexibility; weak durability and control.
Workflow-constrained harnessRepeatable business processes and regulated operations.Predictability and auditability; less flexibility.
Planner–executor–verifierComplex work with testable outcomes.Better separation of concerns; more calls and latency.
Multi-agent harnessSpecialized or parallel work with strong synthesis.Potential quality lift; coordination and cost overhead.
Durable agent harnessHours-long tasks, approvals, external events, and transactions.Operational resilience; distributed-systems complexity.

Adaptive harnesses are an emerging research direction. September 2026 preprints such as JIT-Agent and HarnessDev treat the harness itself as a configurable or generated artifact. The early results are promising but mixed: generated harnesses can compete in some domains, yet mature human-engineered systems remain stronger in others and improvements do not always transfer between models or tasks. Enterprises should treat this as active research, not a replacement for architecture ownership.

Build or buy?

Frameworks increasingly provide agent loops, tool interfaces, sessions, guardrails, approvals, tracing, orchestration, and durable-execution integrations. Those capabilities can accelerate delivery, but a framework is an implementation choice—not the architecture. The design should first name the responsibilities and boundaries, then decide which platform owns each one.

Consider owning in-houseOften reasonable to adopt
Business context and knowledge accessBase model interfaces and inference infrastructure
Identity, permissions, and tool contractsGeneric workflow and state primitives
Routing policy and business rulesTracing transport and operational plumbing
Evaluation datasets and success criteriaFramework adapters and protocol support
Observability schema and governance evidenceCommodity storage, queues, and scheduling

From prompt engineering to agent systems engineering

The expanding engineering scope
01Prompt engineering
02Retrieval and context engineering
03Tool-using agents
04Harness engineering
05Human–agent systems engineering

Prompts, retrieval, tools, and models do not disappear. They become components inside a larger system that must plan, act, remember, recover, verify, and improve. That changes the unit of evaluation as well: serious comparisons should describe the model + harness + tools + environment, not present a model score as though the surrounding system were irrelevant.

The durable advantage may therefore sit less in access to one model checkpoint and more in the organization’s context, knowledge, tool contracts, workflow state, evaluation data, policies, and feedback loops. The model remains essential. The harness is what makes its intelligence operational.

Primary sources and further reading

PRIMARY SOURCES

Research and implementation guidance

Engineering guidance

Runtime documentation

Runtime documentation
OpenAI Agents SDK

Agent loops, tools, handoffs, sessions, guardrails, human approval, and tracing.

Runtime documentation
Dapr Agents

Durable workflow, state, resiliency, and distributed execution concepts for agents.

Emerging research · preprints