Slides · Harness engineering
What is an agent harness?
1 / 22
What is an agent harness?
Why the same model behaves differently in different setups, and how to find and fix the layer that broke.
By the end you can define a harness, sort its parts into six families, classify a failure by layer, do the compounding-error arithmetic, and explain the ratchet.
Concept
Same model, different outcome
- Picture an assistant who stops issuing wrong refunds after the team adds a checklist per job, a log of finished work and a short permission list.
- Nobody rewrote his instructions. The setup around him changed.
- A model maps tokens to tokens. It cannot read a file, run a test, remember yesterday or stop itself safely.
- Everything that turns that function into something that does work is the harness.
Concept
Agent = Model + Harness
- Short form, credited by Osmani to Viv Trivedy: Agent = Model + Harness. Anything that is not the model counts as harness.
- Wikipedia: the infrastructure wrapped around an LLM so that it can work as an agent (also called agent scaffolding).
- Microsoft Agent Framework: its harness is the runtime layer that makes a model behave as an agent, handling tool calls, session state, approvals and long multistep work.
- deepset: “everything in an AI agent system except the model itself”.
- Harness engineering designs that environment and improves it from observed failures. Its unit of change is the environment, not the prompt.
Sources[1] Agent Harness Engineering[2] Agent harness[3] Agent Harness[4] Harness Engineering: How to Build Reliable AI Agents by Engineering the System, Not the Model
Diagram
Prompt, context, harness: three nested scopes
Compare
The six component families
Grouping adapted from Osmani’s component list; treat it as a thinking aid, not a standard.
| Family | Typical contents | Failure it prevents |
|---|---|---|
| Instructions | system prompt, AGENTS.md or CLAUDE.md, skill files | the agent does not know your conventions |
| Tools | file edit, shell, search, MCP servers, descriptions | it cannot act, or picks the wrong tool |
| Infrastructure | filesystem, git, sandbox, browser | state lost between sessions; unsafe execution |
| Orchestration | subagents, handoffs, model routing | context bloat; wrong model for the step |
| Enforcement | hooks, approvals, validators, linters, tests | out-of-scope actions; unchecked output |
| Observability | logs, traces, cost metering | nothing can be diagnosed or improved |
Process
Design method: start from the behaviour
- Name the behaviour you want, or the failure you want to stop.
- Pick the family that produces it (for example, “never edits outside the workspace” points to enforcement).
- Add the smallest component that delivers it.
- Osmani’s test, in his words: “If you can’t name the behavior a component exists to deliver, it probably shouldn’t be there.”
Diagram
Whose harness is it?
Math
Why long tasks fail: compounding errors
P(task)≈pn| Symbol | Meaning |
|---|---|
| p | probability that one step succeeds |
| n | number of steps the task needs |
| P(task) | probability every step succeeds |
- Assumes steps fail independently. Real errors are correlated, so say “roughly”.
- A rate that sounds excellent decays fast: it is multiplied by itself n times.
Worked example
Worked example: 20 steps at 0.97
Numbers computed in a script, not read off a chart.
| Quantity | Calculation | Result |
|---|---|---|
| Whole-task success | 0.97 ** 20 | about 0.544 |
| Same task at 12 steps | 0.97 ** 12 | about 0.694 |
| Per-step rate needed for 0.70 over 30 steps | 0.70 ** (1/30) | about 0.9882 |
| Per-step rate needed for 0.70 over 20 steps | 0.70 ** (1/20) | about 0.9823 |
- Shortening the task (decomposition) and raising p both help.
- To get 70 percent over 30 steps you need roughly 98.8 percent per step, not 97.
Worked example
Two levers: higher p, or recovery
Illustrative: a step succeeds 0.90 of the time. A check detects a failed step, and the harness retries once. Assume the retry is independent and the check never misses.
| Setup | Per-step success | 20 steps |
|---|---|---|
| No recovery | 0.90 | 0.9020≈0.122 |
| Detect and retry once | 1−0.10×0.10=0.99 | 0.9920≈0.818 |
- Both levers are harness properties: better tools and context raise p; verification plus repair is recovery.
- The assumptions are generous. A weak check or a correlated failure erodes the gain.
Compare
Four failure layers
Layers follow deepset; the example fixes are partly ours.
| Failure | What you see | Layer to change |
|---|---|---|
| Context | lacked the right information (stale document, truncated tool output) | retrieval, context assembly, docs in the repo |
| Constraint | had the information but acted outside its scope | permissions, sandbox, hooks, linters |
| Verification | output looked plausible but was wrong and nothing caught it | tests, validators, a separate evaluator |
| Planning | wrong approach: one-shotting a huge task, repeating a failed plan | decomposition, plan files, loop detection |
Source[4] Harness Engineering: How to Build Reliable AI Agents by Engineering the System, Not the Model
Diagram
Ask in order; the first yes names the layer
Worked example
Two layers at once: a long-running coding agent
Anthropic (Young, 26 November 2025) reports agents working across many context windows.
| What went wrong | Layer | Harness change they describe |
|---|---|---|
| Tried to build too much at once, left half-finished work | Planning | one feature at a time; commit and update notes before ending |
| Marked features complete without end-to-end testing | Verification | prompt to test as a human user would, with browser automation |
| Later session saw progress and declared the job done | Verification | a feature list written up front, every entry starting as failing |
None of the fixes changed the model.
Check yourself
Check: which layer?
A log-analysis agent summarised a test run and reported no failures. Its tool returned only the first 200 lines of a 6,000-line output, and the failing test was on line 4,100. Which layer broke, and what do you change first?
Answer
Context. The agent lacked the information, because tool output was truncated. Change the tool output design: keep the head and tail, write the full output to a file, and return a hint such as a path and how to search it. A stronger prompt would not help, since the failing line never reached the model. Note that head and tail alone would still miss line 4,100; the file pointer is what lets the agent search for it.
Diagram
The ratchet
Concept
Assumptions decay
- Every component encodes a guess about what the model cannot do: it forgets, loops or skips checks.
- A scaffold built for one model may do nothing for the next. Re-test on a held-out task set when the model changes.
- Better models retire some scaffolding but open harder tasks that need new scaffolding, so harnesses move more than they shrink.
- Course judgment, beside the ratchet: for high-risk actions, constrain first and loosen with evidence. Osmani’s own rule is to add constraints only after a real failure and remove them when a capable model makes them redundant.
- Prefer computational checks (linters, tests) over inferential ones (a model as judge): Böckeler describes the first as cheap and deterministic, the second as slower and less predictable.
Sources[1] Agent Harness Engineering[5] Harness engineering for coding agent users
Code
A minimal harness, line by line
Illustrative sketch, run against stub tools and a fake model. Helper functions are assumed.
Python
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: steps
if spent + est_cost > budget_usd: # stop: 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
if not reply.tool_calls: # model says done...
ok, report = verify(task) # ...harness checks
if ok:
return success(messages)
log(step, "verify_failed", report)
messages.append(user(f"Verification failed: {report}"))
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: # errors are observations
out = f"ERROR: {e}. Check the arguments and retry."
messages.append(tool_result(call, out))
return stop("max_steps", messages)Tests with stubs: a tool that raises came back to the model as an ERROR: result and the run continued; a “done” claim with red tests was rejected, logged as verify_failed, and the run later succeeded. With est_cost=0.5 the budget check stops before a call that would probably pass the limit, but it uses an estimate: one unusually expensive call can still overshoot, and a fixed estimate that is too high stops the run early when calls are cheap (in a test with 0.1-cost calls it stopped near 1.6 of 2.0). Tune the estimate to the observed cost per call.
Comments name the family or loop control each line serves. Production versions add checkpointing, idempotent tools and loop detection.
Concept
Pitfalls with the word “harness”
- It is overloaded. Wikipedia lists related uses: a test harness, an evaluation harness for benchmarks, and the environment wrapper in reinforcement learning. Say which meaning you intend in your first sentence.
- It is a new term, and accounts of who coined it differ. Say “popularised by”, not “invented by”.
- “The harness is just the prompt” and “harness engineering is context engineering renamed” both miss persistence, enforcement and orchestration.
- Gain figures from practitioner or vendor posts often come without full methodology. Quote them as reports, not facts.
Check yourself
Check: numbers and families
(a) A 15-step agent succeeds 0.96 of the time per step. Roughly how often does the whole task finish? (b) Traces show nobody can tell which tool call used most of the budget. Which family is thin, and what do you add?
Answer
(a) 0.96 ** 15 is about 0.542, so a little over half. (b) Observability: add per-step logs and token and cost metering, so you can diagnose before you change anything.
Summary
Recap
- Agent = Model + Harness; prompt sits inside context, which sits inside the harness.
- Six families: instructions, tools, infrastructure, orchestration, enforcement, observability.
- Failures are context, constraint, verification or planning; fix the layer that broke.
- p to the power n shows why long tasks need higher per-step reliability or recovery.
- The ratchet turns each mistake into a control and removes controls a stronger model makes redundant.
References
References & Sources (1 of 2)
Agent Harness Engineering (opens in a new tab)
Addy Osmani2026Article
https://www.oreilly.com/radar/agent-harness-engineering/
Used for The Agent = Model + Harness formula, the component list behind the six families, the start-from-behaviour design test, and the ratchet idea that every AGENTS.md line traces to a past failure.
Agent harness (opens in a new tab)
Wikipedia2026Article
https://en.wikipedia.org/wiki/Agent_harness
Used for A neutral definition of the agent harness and the other senses of the word (test harness, evaluation harness, reinforcement-learning environment).
Agent Harness (opens in a new tab)
Microsoft Learn (Agent Framework)2026Documentation
https://learn.microsoft.com/en-us/agent-framework/concepts/harness
Used for A framework vendor's definition of the harness as runtime scaffolding for model calls, state, approvals and multistep work.
deepset2026Article
https://www.deepset.ai/blog/harness-engineering
Used for The definition of the harness as everything except the model, and the four failure layers: context, constraint, verification and planning.
Harness engineering for coding agent users (opens in a new tab)
Birgitta Böckeler2026Article
https://martinfowler.com/articles/harness-engineering.html
Used for The three rings around a coding agent (model, builder's harness, user's harness) and the computational versus inferential split.
References
References & Sources (2 of 2)
Effective harnesses for long-running agents (opens in a new tab)
Justin Young2025Article
https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents
Used for A real case where planning and verification failures across context windows were fixed in the harness, not the model.
Keys: ← → move, Home End first and last, F full screen.