What is an agent harness?

  • Advanced
  • 35 min
  • Lesson 1 of 7 in Harness engineering
  • Last verified

Open slides(22 slides)

Before you start

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.

Diagram: On its own the model maps tokens to tokens.

Agent = Model + Harness

Instructions, memory, state

Model

Tools, sandbox, permissions

Verification, logs, stop rules

Model alone

Tokens in

Tokens out

Diagram summary: On its own the model maps tokens to tokens. The harness is everything around it that turns that into work: what it knows, what it can do, what is allowed, how results are checked, and when it stops. If a part is not the model, it belongs to the harness.

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.

Diagram: Three nested boxes.

Harness: the whole operating environment over time

Context: what the model sees at this step

Prompt: wording of one interaction

+ tools, loop control, memory, permissions, sandbox, verification, orchestration, observability, improvement loop

Diagram summary: Three nested boxes. The prompt sits inside the context, and the context sits inside the harness, which also holds the tools, controls and improvement loop that the window cannot.

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.

FamilyTypical contentsThe failure it prevents
Instructionssystem prompt, AGENTS.md or CLAUDE.md, skill files, subagent promptsthe agent does not know your conventions and repeats mistakes
Toolsfile read and edit, shell, search, MCP servers, and their descriptionsthe agent cannot act, or picks the wrong tool
Infrastructurefilesystem, git, sandbox, browserstate is lost between sessions; unsafe execution; no rollback
Orchestrationsubagents, handoffs, routing to a cheaper or stronger modelcontext bloat; the wrong model for the step
Enforcementhooks, approval policies, schema validation, linters, testsout-of-scope actions; unverified output
Observabilitylogs, traces, token and cost meteringyou cannot diagnose or improve anything
Diagram: The model talks to the agent loop, and the loop draws on six families: instructions, tools, infrastructure, orchestration, enforcement and...

Model (stateless)

Agent loop: plan, act, observe, stop

1 Instructions

2 Tools

3 Infrastructure

4 Orchestration

5 Enforcement

6 Observability

Diagram summary: The model talks to the agent loop, and the loop draws on six families: instructions, tools, infrastructure, orchestration, enforcement and observability.

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.

Diagram: Three rings around a coding agent.

Outer harness: yours

Inner harness: built into the agent tool

Model

Language model

Agent loop, built-in tools, system prompt

Instruction files, MCP servers, skills, hooks, linters, tests

Diagram summary: Three rings around a coding agent. The model sits at the centre, the builder’s own harness wraps it, and the outer ring is the one you add. You cannot change the inner rings, so the outer harness is where application engineers have leverage.

Why long tasks fail: compounding errors

If each step succeeds with probability pp, and steps fail independently, a task of nn steps succeeds with about pnp^n.

Per-step success pp10 steps20 steps30 steps
0.990.9040.8180.740
0.980.8170.6680.545
0.950.5990.3580.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.

FailureWhat you seeLayer to change
Contextthe agent lacked the right information (wrong file, stale document, truncated tool output)retrieval, context assembly, documentation kept in the repo, tool output design
Constraintthe agent acted outside its scope (edited the tests, ran a destructive command)permissions, sandbox, hooks, linters
Verificationwrong output went unchecked (declared victory, passed unit tests, broken end to end)tests, validators, a separate evaluator, browser end-to-end checks
Planningwrong approach, loops, one-shotting a huge taskdecomposition, 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.

Diagram: Ask the questions in order and the first yes names the layer to fix.

yes

no

yes

no

yes

no

The agent failed

Did it lack the right
information?

Context failure:
retrieval, context assembly, docs, tool output

Did it act outside its scope?

Constraint failure:
permissions, sandbox, hooks, linters

Did wrong output go unchecked?

Verification failure:
tests, validators, evaluator

Planning failure:
decomposition, plan files, loop detection

Diagram summary: Ask the questions in order and the first yes names the layer to fix. Missing information is a context failure, acting out of scope is a constraint failure, unchecked wrong output is a verification failure, and what remains is a planning failure.

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.

Diagram: The ratchet turns each real mistake into a permanent control, so the same mistake gets harder to repeat.

now redundant

still needed

A real mistake

Turn it into a permanent rule,
check or hook

Harness: that mistake is now
structurally harder

A more capable model arrives

Re-test each component

Remove it

Keep it

Diagram summary: The ratchet turns each real mistake into a permanent control, so the same mistake gets harder to repeat. It also turns back: when a better model makes a control unnecessary, re-testing shows it and 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.

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 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.
  • nn steps at success pp succeed with about pnp^n: 0.9825≈0.600.98^{25} \approx 0.60 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.

Resources & Further Reading

Checked sources to go deeper. The essential ones come first in each group.

Further reading

Research papers

Hands-on

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.

0 of 10 answered

Keyboard: arrow keys move between options. Space or Enter selects the focused option.

ObjectiveDefine an agent harness, say what Agent = Model + Harness means, and place it relative to prompt engineering and context engineering.

  1. Question 1 of 10A teammate says, "The harness is just our system prompt." What is the best correction?

    Choose one answer.

  2. Question 2 of 10Which description orders prompt engineering, context engineering and harness engineering correctly?

    Choose one answer.

ObjectiveName the six harness component families and the failure each one prevents.

  1. Question 3 of 10Which of these belong to the enforcement family of a harness? Select all that apply.

    Choose all that apply.

  2. Question 4 of 10An agent that works through 40 tasks over several days keeps forgetting which tasks it has finished each time it restarts. Which family do you change first?

    Choose one answer.

ObjectiveClassify an agent failure as context, constraint, verification or planning, and name the layer you would change.

  1. Question 5 of 10A coding agent edits its own failing tests until they pass, then reports success. Which failure is this, and what is the right fix?

    Choose one answer.

  2. Question 6 of 10A support agent quotes a refund policy that was replaced last quarter. The only copy of the policy it could read was out of date. Which layer produced the failure?

    Choose one answer.

ObjectiveUse the p-to-the-n arithmetic to explain why long agent tasks need higher per-step reliability or recovery.

  1. Question 7 of 10An agent completes each step correctly 98 percent of the time and a task needs 25 independent steps. About how often does the whole task succeed?

    Choose one answer.

  2. Question 8 of 10Which changes raise the success rate of a long, multi-step agent task? Select all that apply.

    Choose all that apply.

ObjectiveExplain the ratchet and why each harness component encodes an assumption that must be re-tested.

  1. Question 9 of 10An agent deletes a branch it should have left alone. Which response follows the ratchet?

    Choose one answer.

  2. Question 10 of 10A planning scaffold was added to help an older model. A newer model scores the same without it on your held-out tasks. What does "assumptions decay" suggest?

    Choose one answer.