What is an agent harness?
- Advanced
- 35 min
- Lesson 1 of 7 in Harness engineering
- Last verified
Select text in the lesson first to keep it with your note. With the keyboard, move focus here and press the button: the note goes with the section you are reading.
In this module
On this page
Before you start
- Completed:Agentic patterns: ReAct, planning and memoryTools and agents
- Completed:Context engineering and memoryContext, memory and multi-agent systems
You will be able to
- Define an agent harness, say what Agent = Model + Harness means, and place it relative to prompt engineering and context engineering.
- Name the six harness component families and the failure each one prevents.
- Classify an agent failure as context, constraint, verification or planning, and name the layer you would change.
- Use the p-to-the-n arithmetic to explain why long agent tasks need higher per-step reliability or recovery.
- Explain the ratchet and why each harness component encodes an assumption that must be re-tested.
Vihaan is the same agent as last month, but the setup around him has changed. There is a checklist for each job, a log of what is finished, and a permission list that gives him only the tools a job needs. Wrong refunds have stopped.
Nobody changed a word of his instructions.
So what changed: Vihaan, or the setup around him?
Concept
A language model is a function from tokens to tokens. By itself it cannot read a file, run a test, remember yesterday or stop itself safely. Everything that turns it into something that does work is the harnessAgent harnessEverything around the model that turns it into an agent: the loop, tools, state, sandbox, permissions, verification, orchestration and observability. Agent = model + harness.Open the glossary entry. The short form people use is Agent = Model + Harness: if a part is not the model, it is the harness.
Harness engineeringHarness engineeringDesigning the environment, constraints and feedback loops around a model so an agent stays reliable, and improving them from observed failures. The unit of improvement is the environment, not the prompt.Open the glossary entry is the discipline of designing that environment, with its constraints and feedback loops, so the agent stays reliable, and improving it from observed failures. Its unit of improvement is the environment, not the prompt. When an agent makes a mistake, you do not hope it does better next time. You change the environment so that specific mistake is structurally harder to repeat.
Why It Matters
Many agent failures in production are not “the model was not smart enough”. They are an agent that lacked the right file, acted outside its scope, declared victory without checking, or looped on a failing plan. Each of those is fixable in the environment, often more cheaply than by switching models. The agent loop you already know is one component of a harness. This module is about the rest.
Interviewers for agent-platform and AI-infrastructure roles use the term to find out whether you can reason about an agent as a system: what to build around the model, how to diagnose a failure, and which layer to change.
Mental Model
Think of the support setup in the story. Vihaan, the model, did not change. The setup added a checklist per job (instructions), a permission list (permissions) and a progress log (state that outlives a session). A fuller setup would also add a way to check a job before it counts (verification). Vihaan stays literal and willing. The setup makes the right action easy and the wrong action hard.
What a harness is
Several sources say the same thing at different zoom levels.
- Wikipedia describes the agent harness as the software infrastructure around a language model that lets it operate as an agent: tool use, memory, state, execution environments and feedback loops.
- Microsoft’s Agent Framework documentation calls it the runtime scaffolding that turns a model into an agent. It drives model and tool calls, manages state and context, applies approval policies and can keep the agent working through a multi-step task.
- deepset puts it most bluntly: everything in an agent system except the model, covering tools, memory, guardrails, verification and orchestration.
Two cautions when you use the term. It is new: it spread in early 2026, and accounts of who coined it differ. Some credit Mitchell Hashimoto, who wrote about engineering a permanent fix into an agent’s environment after each mistake. Others credit Vivek Trivedy of LangChain for the post “Anatomy of an Agent Harness”. Say “popularised by”, not “invented by”. And “harness” is overloaded, which the interview section returns to.
Three nested disciplines
Prompt engineering is the wording of one interaction. Context engineering (see context engineering and memory) decides what is in the window at this step. Harness engineering contains both and adds what the window cannot hold: persistence between sessions, enforcement of what is allowed, orchestration across agents, and the loop that improves all of it.
A line that holds up in an interview: context engineering is a function of the harness; the harness also decides when to stop, what is allowed, what gets verified and what survives the session.
The six component families
A harness is easier to reason about when you sort its parts. The grouping below is adapted from the components Addy Osmani lists in his overview for O’Reilly: instructions, tools, bundled infrastructure, orchestration, hooks and middleware, and observability. Here the hooks and middleware are called enforcement and grouped with permissions, validation and tests, and git is added under infrastructure. Treat the sorting as a thinking aid, not a standard.
| Family | Typical contents | The failure it prevents |
|---|---|---|
| Instructions | system prompt, AGENTS.md or CLAUDE.md, skill files, subagent prompts | the agent does not know your conventions and repeats mistakes |
| Tools | file read and edit, shell, search, MCP servers, and their descriptions | the agent cannot act, or picks the wrong tool |
| Infrastructure | filesystem, git, sandbox, browser | state is lost between sessions; unsafe execution; no rollback |
| Orchestration | subagents, handoffs, routing to a cheaper or stronger model | context bloat; the wrong model for the step |
| Enforcement | hooks, approval policies, schema validation, linters, tests | out-of-scope actions; unverified output |
| Observability | logs, traces, token and cost metering | you cannot diagnose or improve anything |
A design method. Start from the behaviour you want, or want to fix, and derive the component that produces it. Osmani’s version: if you cannot name the behaviour a component exists to deliver, it probably does not belong.
Inner and outer harness
Birgitta Böckeler of Thoughtworks, writing on martinfowler.com in April 2026, draws three rings around a coding agent: the model, the harness built into the agent (the builder’s harness), and the harness the user adds (the user’s, or outer, harness). This lesson calls them the inner and outer harness for short; the “inner” label is a shorthand, not her term. You do not control the inner one; the tool or model builder ships it. The outer harness is yours: instruction files, MCP servers, custom skills, hooks, linters and tests. That is where most application engineers have leverage, and its job is to build enough trust that the agent needs less supervision.
Why long tasks fail: compounding errors
If each step succeeds with probability , and steps fail independently, a task of steps succeeds with about .
| Per-step success | 10 steps | 20 steps | 30 steps |
|---|---|---|---|
| 0.99 | 0.904 | 0.818 | 0.740 |
| 0.98 | 0.817 | 0.668 | 0.545 |
| 0.95 | 0.599 | 0.358 | 0.215 |
Two things follow. A per-step success rate that sounds excellent still gives a coin flip over 30 steps at 0.98. And the failure cannot be fixed in the prompt alone: you need either higher per-step reliability (better tools, better context, verification after the step) or recovery (detect an error mid-task and repair it). Both are harness properties.
Independence is an idealisation. Real errors are correlated, which can make the result better or worse, so say “roughly” when you quote the number. A worked case: 25 steps at 0.98 gives about 0.60. If you measure 55 percent, the arithmetic is the right order of magnitude; the small gap could be noise or correlated errors, so look at where the failures cluster before changing anything.
Classifying failures by layer
deepset sorts agent failures by the layer that broke, and the sorting tells you where to fix. The table below is adapted from its four layers; the fixes are examples, and some go beyond what deepset lists.
| Failure | What you see | Layer to change |
|---|---|---|
| Context | the agent lacked the right information (wrong file, stale document, truncated tool output) | retrieval, context assembly, documentation kept in the repo, tool output design |
| Constraint | the agent acted outside its scope (edited the tests, ran a destructive command) | permissions, sandbox, hooks, linters |
| Verification | wrong output went unchecked (declared victory, passed unit tests, broken end to end) | tests, validators, a separate evaluator, browser end-to-end checks |
| Planning | wrong approach, loops, one-shotting a huge task | decomposition, plan files, loop detection, subagents |
Anthropic’s engineering post on long-running agents shows two of these at once. Agents working across many context windows tried to do too much at once and left half-finished work (planning), and often marked a feature complete without testing it end to end (verification). Their fix lived in the harness, not the model: a feature list the agent could only mark as passing, a progress file, git history, and an instruction to test like a user would.
Diagnosing without logs is guessing. This is why observability is a family of its own, and why a later lesson in this module is about instrumenting first.
The ratchet and assumptions that decay
Two ideas keep a harness from rotting.
The ratchetRatchet (harness)Turning every real agent mistake into a permanent check, rule or hook, and removing it later when a stronger model makes it redundant.Open the glossary entry: each real mistake becomes a permanent rule, check or hook. Osmani’s test is that every line in a good AGENTS.md should trace back to a specific thing that went wrong. The ratchet also turns the other way. When a more capable model makes a constraint redundant, you remove it, so the harness does not fill up with rules nobody can explain.
Assumptions decay. Every component encodes an assumption about what the model cannot do: it forgets, it loops, it skips verification. A planning scaffold built for one model may do nothing for the next. Re-test components when the model changes. Better models retire some scaffolding but also open harder tasks that need new scaffolding, so harnesses move more than they shrink.
A few more principles that hold up:
- Externalise what models handle poorly (state, long-term memory, workflows) into files, git and tools.
- For high-risk actions, constrain first and loosen with evidence. This is course judgment: removing a guardrail is easier than retrofitting one after an incident. It sits beside the ratchet, where Osmani adds constraints after a real failure; apply it to actions where one failure is already too costly.
- Prefer computational checks where you can. A linter is cheaper, faster and more predictable than an LLM reviewer. Böckeler separates these as computational and inferential controls.
- If the agent cannot see it, it does not exist. Knowledge that lives in a chat thread or in someone’s head has to be written where the agent can read it.
A minimal harness
This sketch is illustrative, not a library. Every line maps to a family above.
def run_agent(task, model, tools, max_steps=30, budget_usd=2.0, est_cost=0.5):
messages = [system_prompt(), user(task)] # instructions
spent = 0.0
for step in range(max_steps): # stop condition: steps
if spent + est_cost > budget_usd: # stop condition: budget, checked before the call
return stop("budget_exceeded", messages)
reply = model.call(messages, tools=tool_schemas(tools))
spent += reply.cost
messages.append(reply.message)
log(step, reply, spent) # observability: every turn, including failed verifications
if not reply.tool_calls: # the model says it is done...
ok, report = verify(task) # ...the harness checks, not trusts
if ok:
return success(messages)
messages.append(user(f"Verification failed: {report}. Fix and continue."))
continue
for call in reply.tool_calls:
if not permitted(call): # enforcement
messages.append(tool_result(call, "DENIED: needs approval"))
continue
try:
out = truncate(tools[call.name](**call.args)) # context hygiene
except Exception as e:
out = f"ERROR: {e}. Check the arguments and retry." # errors are observations
messages.append(tool_result(call, out))
messages = compact_if_needed(messages) # context management
return stop("max_steps", messages)What a production version adds: checkpointing so a crash resumes, idempotent tools so a retry does not repeat a side effect, loop detection, and careful handling of secrets. The next lesson takes the loop and the tools apart.
Real-World Application
When you inherit an agent, do not start by rewriting its prompt. Collect a handful of real failures, sort each by layer, and change the cheapest layer that would have prevented it. A refund agent that issued a refund twice is a constraint and idempotency problem. A support agent that quoted last year’s policy is a context problem. A coding agent that reported “done” on a broken build is a verification problem. Each fix is a small, permanent addition to the environment, and the ratchet keeps the record of why it is there.
Interview Perspective
Expect: “What is an agent harness?”, “How is it different from context engineering?”, “An agent keeps declaring a task done when it is not. What do you change?”, “Your 25-step agent succeeds about half the time; what do the numbers tell you?”
Say in the first fifteen seconds which meaning of “harness” you are using. It is overloaded: a test harness, an evaluation harness that runs a benchmark, a reinforcement-learning environment wrapper, and the agent harness here. If it is unclear, ask: “Agent runtime scaffolding, or an evaluation harness?” In an agent-engineering interview the first meaning is the likelier one, and the second appears inside it as the sensor that grades the agent.
Common mistakes: calling the harness “just the prompt”; stating as fact that one person invented harness engineering; quoting benchmark gains from vendor or practitioner blog posts as established; believing a good harness makes the model irrelevant, or the reverse. A defensible line is that harness choices can change results noticeably, that reported gains often come from practitioner posts without full methodology, and that better models also change which scaffolding you need.
Provenance: Common industry pattern. These are the questions this topic tends to draw in agent-engineering interviews; none is verified for a named company. The term is recent and wording varies, so expect “agent infrastructure” or “agent scaffolding” as well.
Practice Questions
- Basic: What is an agent harness, and what is it made of?
- Intermediate: An agent edits its own failing tests until they pass. Classify the failure and name three harness changes.
- Advanced: Your 40-step agent succeeds 50 percent of the time and per-step reliability is about 0.99. What do the numbers say, and which two levers do you pull first?
- Product-Company: You inherit an agent with a 900-line system prompt that nobody dares edit. Plan its refactor into a harness.
Activity
Take an agent you have used or built. List its components under the six families and mark any family that is empty. Then write down three real failures and sort each as context, constraint, verification or planning. For each, name the one change to the environment that would make it harder to repeat.
Homework
Write a one-page explainer for a teammate on Agent = Model + Harness. Include a diagram of your own, the six families with an example from a real agent, and the three failure classifications from the activity, each with its fix and the incident that justifies it, as a ratchet entry.
Quick Revision
- Agent = model + harness. The harness is everything except the model.
- Prompt sits inside context, which sits inside the harness.
- Six families: instructions, tools, infrastructure, orchestration, enforcement, observability.
- Failure layers: context, constraint, verification, planning. Fix the layer that broke.
- steps at success succeed with about : over 25 steps.
- Ratchet: mistake becomes a permanent check, removed when a stronger model makes it redundant. Assumptions decay.
Check yourself
- Walk-through: State what harness engineering is, and how it differs from prompt and context engineering. Give one failure of each type and the layer you fix.
- Variation: Repeat it for a customer-support agent that issues refunds.
- Common misconception: “Harness engineering is context engineering with a new name.” Context is what the model sees now; the harness also holds persistence, enforcement, orchestration and the improvement loop.
Related
Resources & Further Reading
Checked sources to go deeper. The essential ones come first in each group.
Further reading
Building effective agents (opens in a new tab)Essential
Shows the agent loop and the agent-computer interface from the model builder's side, which is the loop component this lesson places inside a harness.
Effective context engineering for AI agents (opens in a new tab)
Explains the context layer in depth, so you can see which part of the harness the nested-scopes slide calls context.
LLM Powered Autonomous Agents (opens in a new tab)
Gives the planning, memory and tool-use background behind the components the harness packages up.
Research papers
ReAct: Synergizing Reasoning and Acting in Language Models (opens in a new tab)
The reason-then-act loop that most harness loops descend from; read it to see what a harness adds around that loop.
Hands-on
Building Effective Agents Cookbook (claude-cookbooks, patterns/agents) (opens in a new tab)
Runnable agent-pattern notebooks let you see a loop, tools and a stop condition in code before you add enforcement and verification.
AI Agents Course (opens in a new tab)
A guided course that builds agents step by step, useful practice for placing each piece in one of the six families.
More for this module: Harness engineering resources
Practice
Test what you just read. Quizzes and cards are grouped by module: Harness engineering.
Check yourself10 questions on what this lesson set out to teach
Checking answers needs JavaScript. You can still read every question and option below.
Keyboard: arrow keys move between options. Space or Enter selects the focused option.