Slides · Harness engineering

What is an agent harness?

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.

Sources1 Agent Harness Engineering2 Agent harness3 Agent Harness4 Harness Engineering: How to Build Reliable AI Agents by Engineering the System, Not the Model

Diagram

Prompt, context, harness: three nested scopes

Diagram: Reading down, the prompt sits inside the context, and the context sits inside the harness.

sits inside

sits inside

Prompt
wording of one call

Context
what the model sees now

Harness
whole environment over time

Adds: persistence, enforcement,
orchestration, improvement loop

Diagram summary: Reading down, the prompt sits inside the context, and the context sits inside the harness. The harness also holds what a window cannot: state between sessions, enforcement of what is allowed, orchestration and the loop that improves the rest. This nesting is the lesson’s framing, not a quoted standard.

Compare

The six component families

Grouping adapted from Osmani’s component list; treat it as a thinking aid, not a standard.

FamilyTypical contentsFailure it prevents
Instructionssystem prompt, AGENTS.md or CLAUDE.md, skill filesthe agent does not know your conventions
Toolsfile edit, shell, search, MCP servers, descriptionsit cannot act, or picks the wrong tool
Infrastructurefilesystem, git, sandbox, browserstate lost between sessions; unsafe execution
Orchestrationsubagents, handoffs, model routingcontext bloat; wrong model for the step
Enforcementhooks, approvals, validators, linters, testsout-of-scope actions; unchecked output
Observabilitylogs, traces, cost meteringnothing can be diagnosed or improved

Source1 Agent Harness Engineering

Process

Design method: start from the behaviour

  1. Name the behaviour you want, or the failure you want to stop.
  2. Pick the family that produces it (for example, “never edits outside the workspace” points to enforcement).
  3. Add the smallest component that delivers it.
  4. Osmani’s test, in his words: “If you can’t name the behavior a component exists to deliver, it probably shouldn’t be there.”

Source1 Agent Harness Engineering

Diagram

Whose harness is it?

Diagram: Böckeler (martinfowler.com, 2 April 2026) describes three rings: the model, the builder’s harness and the user’s (outer) harness; “inner”...

wrapped by

wrapped by

Model
core

Builder's harness
built into the tool

User's harness
yours

Diagram summary: Böckeler (martinfowler.com, 2 April 2026) describes three rings: the model, the builder’s harness and the user’s (outer) harness; “inner” for the builder’s ring is this course’s shorthand. You cannot change the builder’s ring, so your own instruction files, skills, hooks, linters and tests are where you have leverage.

Source5 Harness engineering for coding agent users

Math

Why long tasks fail: compounding errors

P(task)≈pnP(\text{task}) \approx p^n
SymbolMeaning
ppprobability that one step succeeds
nnnumber of steps the task needs
P(task)P(\text{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 nn times.

Worked example

Worked example: 20 steps at 0.97

Numbers computed in a script, not read off a chart.

QuantityCalculationResult
Whole-task success0.97 ** 20about 0.544
Same task at 12 steps0.97 ** 12about 0.694
Per-step rate needed for 0.70 over 30 steps0.70 ** (1/30)about 0.9882
Per-step rate needed for 0.70 over 20 steps0.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.

SetupPer-step success20 steps
No recovery0.900.9020≈0.1220.90^{20} \approx 0.122
Detect and retry once1−0.10×0.10=0.991 - 0.10 \times 0.10 = 0.990.9920≈0.8180.99^{20} \approx 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.

FailureWhat you seeLayer to change
Contextlacked the right information (stale document, truncated tool output)retrieval, context assembly, docs in the repo
Constrainthad the information but acted outside its scopepermissions, sandbox, hooks, linters
Verificationoutput looked plausible but was wrong and nothing caught ittests, validators, a separate evaluator
Planningwrong approach: one-shotting a huge task, repeating a failed plandecomposition, plan files, loop detection

Source4 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

Diagram: Reading down, ask whether the information was missing, whether the agent acted out of scope, and whether wrong output went unchecked.

yes

no

yes

no

yes

no

Agent failed

Lacked the
information?

Context

Acted out
of scope?

Constraint

Wrong output
unchecked?

Verification

Planning

Diagram summary: Reading down, ask whether the information was missing, whether the agent acted out of scope, and whether wrong output went unchecked. The first yes names the layer; if all three answers are no, it is a planning failure. Without logs you are guessing, which is why observability is its own family.

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 wrongLayerHarness change they describe
Tried to build too much at once, left half-finished workPlanningone feature at a time; commit and update notes before ending
Marked features complete without end-to-end testingVerificationprompt to test as a human user would, with browser automation
Later session saw progress and declared the job doneVerificationa feature list written up front, every entry starting as failing

None of the fixes changed the model.

Source6 Effective harnesses for long-running agents

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

Diagram: Reading down, each real mistake becomes a permanent control, so the same mistake gets structurally harder.

no

yes

A real mistake

Becomes a permanent
rule, check or hook

That mistake is now
harder to repeat

A more capable
model arrives

Re-test: still needed?

Remove it

Keep it

Diagram summary: Reading down, each real mistake becomes a permanent control, so the same mistake gets structurally harder. When a better model arrives you re-test each control, removing the ones that are now redundant and keeping the rest. Osmani’s test is that every line in a good AGENTS.md traces to something that went wrong.

Source1 Agent Harness Engineering

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.

Sources1 Agent Harness Engineering5 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.

Sources2 Agent harness1 Agent Harness Engineering

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)

  1. Agent Harness Engineering (opens in a new tab)

    Addy Osmani2026Article

    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.

  2. Agent harness (opens in a new tab)

    Wikipedia2026Article

    Used for A neutral definition of the agent harness and the other senses of the word (test harness, evaluation harness, reinforcement-learning environment).

  3. Agent Harness (opens in a new tab)

    Microsoft Learn (Agent Framework)2026Documentation

    Used for A framework vendor's definition of the harness as runtime scaffolding for model calls, state, approvals and multistep work.

  4. Harness Engineering: How to Build Reliable AI Agents by Engineering the System, Not the Model (opens in a new tab)

    deepset2026Article

    Used for The definition of the harness as everything except the model, and the four failure layers: context, constraint, verification and planning.

  5. Harness engineering for coding agent users (opens in a new tab)

    Birgitta Böckeler2026Article

    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)

  1. Effective harnesses for long-running agents (opens in a new tab)

    Justin Young2025Article

    Used for A real case where planning and verification failures across context windows were fixed in the harness, not the model.