What Is an Agent Harness? Building Reliable Long-Running Agents

What Is an Agent Harness

Table of content

A capable model, given a long, ambiguous task and left to run unsupervised, tends to fail in predictable ways. It loses track of what it already tried. It declares a job finished when it isn’t. On a task that runs for hours, it fills its context window and then loses the thread entirely. None of this is a reasoning failure in the usual sense, because the model keeps producing coherent, plausible text the whole time. It is an infrastructure failure, and the layer built to prevent it is the agent harness. So what is an agent harness, exactly? The sections below cover what it manages that the model can’t, the problems that appear once an agent runs for hours or days, what Anthropic published on long-running coding agents, and why a good harness lets you switch models per task.

The Missing Layer Between “Capable Model” and “Working System”

For a long time the industry treated agent reliability as a model problem that smarter models would solve on their own. Production experience did not bear that out. Teams kept hitting the same failures whichever frontier model sat underneath. Context overflowed on long tasks. Agents graded their own work and called it done. Tool calls fired out of order, and an interrupted task had to start over because nothing recorded where it had stopped. A LangChain engineering post from March 2026 summed this up as an equation: agent = model + harness. The model supplies the reasoning. Everything else (memory across sessions, tool execution, error recovery, checking the model’s output) is a separate engineering layer that has to be built on purpose. Skipping it doesn’t make an agent simpler. It moves the failures from design review into production.

What Is an Agent Harness?

An agent harness is the software layer that wraps a language model and turns it into an agent that can work over many steps, many tool calls and many sessions, rather than a single request and response. It executes the tools the model asks for, saves state between sessions, decides what stays in the model’s context as a task grows, and checks the model’s output against something real, such as a test suite or a second reviewer, instead of trusting it by default. You have probably used one already. Claude Code is a harness around Claude models: it supplies the file and shell tools, the agent loop, permission prompts and context compaction, while the model makes the decisions. The Claude Agent SDK packages the same tools, agent loop and context management as a Python and TypeScript library. OpenAI’s Codex CLI plays the same role for OpenAI models. People who ask about the difference between agent and harness are usually asking where the model ends. The agent is the whole system, and the harness is every part of it that isn’t the model. Because a model is stateless, starting each context window with nothing beyond what is fed into it, the harness is what lets it sustain a task far longer than one window and resume after a crash or a handoff. When a run goes wrong, start by separating what is agent harness behavior from what is model behavior. A lost progress note is a harness bug; a poor plan built from good inputs is a model limit.

What the Harness Is Actually Responsible For

Broken down by function, much of what looks like “the AI’s judgment” from the outside turns out to be infrastructure the harness built around the model.
Function What It Does Why the Model Alone Can’t Do This
Tool execution Runs the actual function calls, API requests, or code the model decides to invoke The model can only propose an action in text; something has to execute it and return a real result
Memory and state persistence Stores progress and decisions outside the model so work can resume where it left off The model’s context window resets; without external storage, every new session starts blind
Context management Decides what stays active in the context window and what gets summarized or trimmed as a task grows Left unmanaged, a long task eventually overflows the context window and degrades output quality
Verification and self-review Checks the model’s output against tests, external data, or a separate review pass before treating it as complete Models evaluating their own freshly generated work show a consistent bias toward approving it
Error recovery Detects failed tool calls, timeouts, or dead ends, and decides whether to retry, adjust, or escalate Without this, an agent either stalls silently or repeats the same failed action indefinitely
Guardrails and permissioning Enforces what actions the agent may take on its own and what requires human confirmation Autonomy without enforced boundaries is a security and operational risk as well as a reliability one

Effective Harnesses for Long-Running Agents: The Hard Problems

Single-session tasks can get by with a light harness. Agents that work for hours or days across many context windows cannot. The most detailed public account is Anthropic’s November 2025 engineering post Effective harnesses for long-running agents. An agent built on the Claude Agent SDK was asked to build a clone of claude.ai over many sessions. Even with built-in compaction, it tried to build everything at once and ran out of context mid-feature, and later sessions saw partial progress and declared the job done. The fix had two parts. An initializer agent runs once and creates an init.sh script, a claude-progress.txt log, an initial git commit and a JSON list of more than 200 features, all marked as failing. Every later session runs a coding agent that reads the log and git history, picks one failing feature, tests it end to end through browser automation (the Puppeteer MCP server), commits, and leaves notes for the next session. A March 2026 follow-up, Harness design for long-running application development, split the work between a planner, a generator that builds in sprints, and a separate evaluator that tests the running app through Playwright MCP. The evaluator exists because agents “reliably skew positive when grading their own work.” Together, those experiments point to five problems any effective harness for long-running agents has to solve:
  • Context compaction. When the history outgrows the context window, truncating old messages throws away goals and decisions, so a good harness summarizes them into a compact record instead. Compaction has limits: Anthropic found it insufficient on its own, and some models wrap up early as they near their context limit. The alternative is a context reset, a fresh session that starts from a structured handoff file.
  • Checkpointing and resumability. Long tasks have to survive a crash or a handoff. That takes a durable record outside the model: a progress file, a task list with a pass or fail status per item, and version control. Anthropic kept its feature list in JSON because the model was less likely to overwrite it than a Markdown file, and git commits gave every session a known-good state to roll back to.
  • Self-verification bias. A model grading output it just produced rates it higher than an outside reviewer would, even when the result is visibly incomplete. Effective harnesses verify independently: they run real tests, check output against external criteria, or hand it to a separate evaluator with its own context. The reasoning that produced the work should not be what approves it.
  • Initializer and sub-agent patterns. Separate setup from execution, as in Anthropic’s initializer agent, so each session starts from a progress log instead of rebuilding context, like a shift handoff. Sub-agents with their own context windows can take bounded side tasks, such as searching a large codebase, and return a short summary.
  • Efficient use of the context budget. Every token spent on verbose tool output is a token unavailable for the work. Well-designed harnesses trim tool results and keep large data in files or a queryable store that the agent reads on demand.

Model-Agnostic by Design: Switching Models by Task and Budget

A practical advantage of a real harness, compared with application logic tied to one model’s API, is that the model becomes a pluggable component. Tools, memory, guardrails and verification live in the harness and stay put when the model underneath changes. That pays off in four ways:
  • Matching model capability to task complexity. Route classification or extraction steps to a smaller, cheaper model, and keep a frontier model for planning, ambiguous instructions and cases the smaller model gets wrong.
  • Managing cost at scale. Workloads that run thousands or millions of steps make the price gap between model tiers material. Per-step model selection puts frontier-model budget only where it changes the outcome, not on every trivial tool call.
  • Adapting to model releases without rework. New models ship every few months with different trade-offs. A clean model interface lets a team swap one in without touching tool integrations or guardrails. Run the same evaluation set against the candidate first, because a new model can change behavior inside an unchanged harness.
  • Reducing vendor lock-in risk. Logic coupled to one provider’s API conventions makes switching expensive later. A harness interface keeps that option open by design.
This is what separates harness engineering from prompt engineering. Prompt engineering optimizes what goes into one model. Harness engineering builds a system that keeps working, at an acceptable cost, whichever model is plugged in this quarter. The logic also works in reverse. Anthropic’s March post argues that each piece of a harness reflects an assumption about something the model can’t yet do alone. When a stronger model arrived, the team dropped the sprints from its harness and kept the planner and the evaluator. Part of harness engineering is deleting scaffolding a better model no longer needs, which is easier when each component is separate and testable.

Where Harnesses Break Down

The most common failure is over-permissioned tools: broad, unscoped access to systems well beyond what a task needs, which turns an ordinary reasoning error into an operational incident. Scope each tool to the task, require human approval for irreversible actions such as payments or outbound email, and treat text a tool returns (a web page, a document) as untrusted input that may carry a prompt injection. Under-built verification is the second: a harness that runs tools competently but still lets the model judge its own success. The third is a category error. Durable execution platforms such as Temporal sometimes get mistaken for harnesses. Checkpointing and replay are necessary for a long-running agent, but on their own they make execution resumable, not trustworthy.

Building a Harness Instead of Renting One

Off-the-shelf frameworks get a team to a prototype quickly. Production reliability on long-running, business-critical tasks usually takes harness engineering fitted to the workflow: the tools it needs, the verification it can trust and the cost it has to hit at scale. Our engineers build this layer as part of custom AI agent development: state for tasks that outlive a single session, tool integrations with scoped permissions, verification that doesn’t rely on the model grading itself, and model routing that uses a frontier model only where it earns its cost. We have worked on AI systems since 2019, and a senior engineer reviews every AI output. If your agents show the failure patterns above, reach out and we’ll walk through your specific workload.

Agent Harness FAQ

  • What is agent harness design? Deciding what the harness around a model does: which tools the agent gets and with what permissions, where state lives between sessions, how context is compacted or reset, and how output is verified. Good agent harness design starts from the failure modes of the task, not from a framework’s feature list.
  • Is an agent harness the same as an agent framework? No. A framework such as LangGraph or the OpenAI Agents SDK supplies building blocks; a harness is the assembled system around a specific model and task. Our guide to multi-agent frameworks for software development compares the main options.
  • What makes an effective harness for long running agents? Durable progress outside the context window, one unit of work per session followed by a commit, verification the generating model doesn’t control, and a handoff that lets the next session start without guessing.
  • How much of a harness does a strong agent need? Less with each model generation, but never zero. Stronger models need less scaffolding for planning, as Anthropic found when it removed its sprints. Tool execution, persistence, permissions and independent verification stay, because no model can run its own tools or judge its own results impartially.
AI Agents & Workflow Automation

Have a project in mind?

Autonomous agents that run multi-step tasks in your CRM, ERP and other tools, within your rules.