Slides · Harness engineering
Evaluating and operating a harness
1 / 29
Evaluating and operating a harness
How to tell whether a harness change really helped, what a resolved task costs, how to keep the harness healthy as models change, and how to run an agent safely.
By the end you can design the experiment, compute cost per resolved task, run the improvement loop, re-baseline after a model change and operate with limits.
Concept
Two questions that make the method
A new routing rule closes tickets faster than ever. Two questions test the claim.
- “Faster than what?” asks for a baseline: the same tickets, run the same way, without the rule.
- “How many came back?” asks for the outcome that matters: tickets resolved correctly, not tickets closed quickly.
- A good experiment holds everything else fixed, changes one thing, counts the right outcome over enough runs, then reads the failures.
Concept
Why one run tells you little
- Anthropic notes that the same agent can give different outputs on different runs, which is why its evaluations repeat each task over several trials.
- The run you look at after a change is the one you remember, so it feels like proof.
- Three good runs in a row can come from a lucky draw on easy tasks.
- Several trials per task, on the same tasks, with and without the change, is the minimum.
Process
Designing the experiment
- Start small. Anthropic began its multi-agent evaluation with about 20 queries from real usage, and describes 20 to 50 simple tasks taken from real failures as a good starting set.
- Change one thing (an ablation), with the model fixed. To compare models, fix the harness instead.
- Use the same tasks, split into a development set you tune on and a held-out set you report on. Anthropic’s tool-writing post says it used held-out test sets to avoid overfitting.
- Run several trials per task and report an interval. The interval is this course’s advice.
- Grade the end state, such as tests passing, not how the transcript reads.
- Seal the environment so the agent cannot find answers it would not have in production.
Sources[1] Demystifying evals for AI agents[2] Writing effective tools for agents — with agents[3] How we built our multi-agent research system
Diagram
One experiment, two harness versions
Compare
Choose graders on purpose
| Aspect | Code-based | Model-based | Human |
|---|---|---|---|
| Strength | Quick, inexpensive, objective, repeatable | Adaptable, scales, can weigh nuance | Best quality, mirrors what experts would decide |
| Weakness | Breaks on valid variations; weak on subjective tasks | Varies between runs, costs more than code, needs calibrating | Costly, slow, needs expert access |
| Role | First choice where a check exists | Where code cannot judge | Calibrates model graders |
The source’s summary of each grader type is condensed here. Prefer a deterministic check where one exists and use a model judge for what code cannot see.
Concept
Traps: broken graders and leaked answers
- Anthropic’s advice: to learn whether a grader works, read many trials’ transcripts alongside the grades they received.
- It reports that Opus 4.5 first scored 42 percent on CORE-Bench; after grading bugs and ambiguous specs were fixed and the scaffold loosened, the score rose to 95 percent.
- It also saw Claude examine git history from earlier trials in some internal evals, which gave an unfair advantage.
- Isolate each trial from a clean environment, or leftover state correlates failures and inflates scores.
Concept
Treat harness-only gains as claims to replicate
- Public leaderboards are useful for orientation.
- Gains reported from changing only the harness often come from vendor or practitioner posts without full methodology; this is the course’s observation, not a measured rate.
- A higher benchmark score does not by itself mean a better production agent for your tasks.
- Replicate on your own tasks before you believe a number.
Math
Reliability: pass@k and pass^k
pass@k=1−(1−p)kpassk=pk| Symbol | Meaning |
|---|---|
| p | Chance one trial of a task succeeds (assumed the same and independent each time) |
| k | Number of trials |
| pass@k | Chance of at least one success in k trials |
| passk | Chance that all k trials succeed |
Anthropic defines the two this way, and the tau-bench paper proposed passk as a reliability metric across trials. Worked, with p=0.7 and k=3: pass@3=1−0.33=1−0.027=0.973; pass3=0.73=0.343. An agent that usually works is nearly always right once in three and reliable all three times only about a third of the time.
Sources[1] Demystifying evals for AI agents[4] τ-bench: A Benchmark for Tool-Agent-User Interaction in Real-World Domains
Math
Cost per resolved task
cost per resolved task=success ratecost per attempt| Symbol | Meaning |
|---|---|
| cost per attempt | Average spend for one try, including failed tries |
| success rate | Share of attempts that end in a correct, accepted result |
Illustrative prices. Design P costs 0.45 dollars per attempt and succeeds 35 percent of the time: 0.350.45≈1.29 dollars per resolved task. Design Q costs 0.70 dollars and succeeds 70 percent: 0.700.70=1.00 dollar. Q’s attempt is about 56 percent more expensive (0.450.70=1.56) yet each result is cheaper, because it fails far less. A cheap attempt that fails often can be the expensive design.
Worked example
Worked example: aggregate, don’t average the ratios
Four held-out tasks, 5 trials each, 0.50 dollars per trial (illustrative). Successes per task: 5, 3, 1, 0.
| Aspect | Value | Arithmetic |
|---|---|---|
| Total cost | 10.00 dollars | 4×5×0.50 (tasks, trials, dollars per trial) |
| Total successes | 9 | 5+3+1+0 |
| Cost per resolved task | about 1.11 dollars | 910.00 |
| Mean success rate | 0.45 | 209 |
| pass@5 | 0.75 | 3 of 4 tasks had at least one success |
| pass5 | 0.25 | 1 of 4 tasks succeeded all 5 times |
| Never solved | 1 task | the task with 0 successes |
Averaging per-task ratios is the wrong method. The ratios are 0.50, 0.83 and 2.50 dollars for three tasks and undefined for the fourth (zero successes). Dropping the undefined one gives a mean of about 1.28 dollars, which no longer equals total spend over total successes (1.11) and ignores the money the unsolved task consumed. Report total cost over total successes and count never-solved tasks separately.
Code
Put an interval around the difference
Python
import random
A = [5,4,4,3,3,2,2,1,1,0,0,0] # successes out of k=5, baseline (illustrative)
B = [5,5,4,4,3,3,2,2,1,1,0,0] # same 12 tasks, one component changed
k = 5
diffs = [(b - a) / k for a, b in zip(A, B)]
random.seed(7)
boots = sorted(
sum(random.choice(diffs) for _ in diffs) / len(diffs)
for _ in range(10000)
)
print(sum(diffs)/len(diffs), boots[249], boots[9749])Output when run: mean difference 0.083, with a 95 percent interval of about 0.033 to 0.133. The code resamples tasks, not trials, because tasks are the unit you want to generalise over. With only 12 tasks the data and the interval are illustrative, and the interval says nothing about tasks unlike these.
Check yourself
Check: work backwards from the cost
A team reports that cost per resolved task fell from 2.10 dollars to 1.40 dollars after a harness change, with the attempt cost unchanged at 0.70 dollars. What happened to the success rate, and what would you check before believing it?
Answer
Success rate = cost per resolved taskattempt cost. Before: 2.100.70≈33 percent. After: 1.400.70=50 percent. Before believing it, check that both numbers came from the same held-out tasks with several trials, whether the interval separates the two, whether passk (reliability) moved too, and whether a successful result still counts only when it is correct and accepted.
Check yourself
Check: better on the dev set
A new compaction policy lifts success from 50 to 70 percent on the tasks the team tuned it on. On a fresh held-out set, success is 52 percent against 50. What do you conclude?
Answer
The change was probably fitted to the development tasks. The held-out result is the one to report, and a two-point gain on a small set may be noise. Run more trials on the held-out set and look at the failures. This is why tuning and reporting use different tasks: Anthropic’s tool-writing post used held-out test sets to avoid overfitting to its training evaluations.
Diagram
The improvement loop
Source[5] Harness Engineering: How to Build Reliable AI Agents by Engineering the System, Not the Model
Concept
Doing the loop well
- deepset says tracing makes the loop possible: without structured logs of tool calls, decisions and state changes, classifying failures is guesswork.
- Böckeler’s rule of thumb: a problem that keeps recurring is a signal to strengthen the controls that steer the agent beforehand and those that check it afterwards.
- Prefer a structural fix (a tool, a sensor, a hook) to more prompt text, and add a regression check for each fix. Both are this course’s guidance.
- Trace the versioned prompt, model, tool calls and results, permission decisions, durations, tokens, cost and stop reason. Redact secrets and personal data.
- Microsoft’s harness documentation (page updated 28 September 2026) says OpenTelemetry observability is enabled by default in its harness.
Sources[5] Harness Engineering: How to Build Reliable AI Agents by Engineering the System, Not the Model[6] Harness engineering for coding agent users[7] Agent Harness
Worked example
Worked example: sample, classify, pick the layer
deepset names these four failure types (context, constraint, verification, planning), each mapped to a kind of fix. Illustrative sample of 40 failed runs:
| Layer | Count | Share | Example symptom |
|---|---|---|---|
| Context | 21 | 52.5% | Forgot a naming rule after compaction |
| Constraint | 4 | 10.0% | Edited a file outside its scope |
| Verification | 9 | 22.5% | Reported success; the test runner never ran |
| Planning | 6 | 15.0% | Retried the same failing command in a loop |
| Total | 40 | 100% |
Fix context first (4021=52.5 percent). deepset’s mapping for context failures is to change how the agent retrieves information, manages memory and structures what it sees. A structural version: reload the rules file and the progress file at the start of every session and after each compaction, instead of hoping the model remembers. Add a regression task that reproduces the forgotten rule, re-run the held-out set, and keep the change only if the total improves and no previously passing task fails.
Source[5] Harness Engineering: How to Build Reliable AI Agents by Engineering the System, Not the Model
Check yourself
Check: read the tally
A sample of 30 failed runs shows: context 6, constraint 3, verification 5, planning 16. Which layer do you fix first, and what kind of fix fits it?
Answer
Planning: 16 of 30 is about 53 percent. deepset’s mapping for planning failures is in orchestration: split the task into smaller steps, delegate, or add loop detection that makes the agent rethink after repeated failures. Make that structural, for example repeated-call detection with a step limit and an escalate rule, then add a regression task that reproduces the loop and re-run the held-out tasks to keep or revert.
Source[5] Harness Engineering: How to Build Reliable AI Agents by Engineering the System, Not the Model
Diagram
When the model changes, test the harness
Concept
Keeping it healthy
- Re-baseline on every model upgrade, before changing anything.
- Tie every rule to the failure it prevents, so you can remove it when that failure stops occurring. Delete what you cannot justify, then re-test.
- Prune contradictions between guides and sensors.
- Version the harness as code: prompts, tool schemas, hooks and policies, reviewed in diffs and rolled out gradually.
- A sensor that never fires may mean quality or blindness. Böckeler leaves this as an open question and suggests coverage ideas like those from mutation testing. Seeding a known fault and seeing whether anything catches it is one practical test.
Worked example
Worked example: ablating after an upgrade
Illustrative held-out results (30 tasks, 5 trials each, 150 trials per variant; percentages rounded) after moving to a new model, harness unchanged. The baseline row is the harness as it stands.
| Variant | Success (rounded) | Steps per task | Cost per resolved task |
|---|---|---|---|
| Baseline, new model | 61% | 34 | 1.80 dollars |
| Without the extra planning step | 61% | 29 | 1.52 dollars |
| Without the automatic retry wrapper | 60% | 31 | 1.70 dollars |
| Without pruning of old tool results | 49% | 36 | 2.35 dollars |
Reading it: the planning step buys no success on this model and adds steps, so it is a candidate to remove and re-test. The retry wrapper’s one-point difference is within what 150 trials per variant can blur, so run more before acting. Pruning clearly earns its place: success falls by 12 points without it. Cost per resolved task is attempt cost over success rate, as before; the attempt costs themselves are not shown.
Check yourself
Check: a clean-up spree
On the day a new model arrives, a team deletes half its hooks and rules because “the new model is smarter”. A week later unrelated regressions appear. Which parts of the method did they skip?
Answer
They did not re-baseline first, so they had no number to compare against. They removed many components at once, so they cannot tell which removal caused which regression. Nor did they test on held-out tasks. The method is to re-baseline, ablate one component at a time, keep what still helps tied to its failure, and roll out gradually. Components can be removed, but only on evidence.
Compare
Operating an agent: the controls
| Aspect | Control | Why |
|---|---|---|
| Failure | Checkpoint and resume; idempotent tools with keys for side effects | A retry must not repeat a side effect |
| Spend | Budgets and timeouts per tool and per run; circuit breakers | A loop must not run up a bill unattended |
| Stopping | Kill switch | Someone can end a run now |
| Undo | Rollback fitted to the change: version control, snapshots or transactions, feature flags | Reversal differs by what was changed |
| Dependencies | Graceful degradation: stop and escalate when the verifier or a tool is down | Never carry on unverified |
| Response | A runbook: disable, revoke credentials, replay, audit | Incidents need steps written in advance |
Anthropic’s research system resumes from where an error occurred and uses rainbow deployments, which shift traffic gradually so running agents are not disrupted. Stripe’s API accepts an idempotency key so a retried request does not perform the same operation twice.
Sources[3] How we built our multi-agent research system[9] Idempotent requests
Concept
Retries and side effects
- An agent that retries a tool call after a timeout may repeat the action if the first call actually succeeded.
- A client-generated idempotency key lets the server recognise the retry. Stripe’s API v1 saves the first result for a key and returns it on retry.
- Stripe compares the retry’s parameters to the original and errors if they differ; its v1 keys can be pruned after at least 24 hours.
- Lesson for tool design: give state-changing tools an idempotency key, and have the harness reuse the same key when it retries.
- Every incident should end in a new guide, sensor or hook: the ratchet from the first lesson.
Source[9] Idempotent requests
Code
Limits as code: a run guard
Python
class RunGuard:
"""Costs are integer cents, so ten 10-cent steps are exactly 100."""
def __init__(self, max_steps, max_cents, kill_switch=lambda: False):
self.max_steps, self.max_cents, self.kill_switch = max_steps, max_cents, kill_switch
self.steps, self.cents = 0, 0
def before_step(self, verifier_up, est_next_cents):
if self.kill_switch(): return ("stop", "kill switch")
if self.steps >= self.max_steps: return ("stop", "step budget used")
if self.cents + est_next_cents > self.max_cents: return ("stop", "next step would exceed budget")
if not verifier_up: return ("escalate", "verifier unavailable")
return None # safe to take the next step
def record(self, cents):
self.steps += 1
self.cents += centsTest runs, with a loop that calls before_step and then record:
| Case | Result |
|---|---|
| 20-step cap, 5 cents per step | stopped after 20 steps, 100 cents |
| Cap 100 cents, 10 cents per step | stopped after 10 steps at exactly 100 cents |
| Cap 100 cents, 30 cents per step | stopped after 3 steps at 90 cents, before an overrun |
| Estimate 10 cents but a step really costs 500 | one step ran, 500 cents spent against a 100 cap |
| Kill switch turned on before the 8th step | stopped after 7 steps |
| Verifier down at its 4th check (up for the first 3) | escalated after 3 steps, did not continue |
| No caps (test limit of 50 iterations) | ran all 50; only the test’s own limit ended it |
Checking the estimate of the next step keeps the cap honest only if the estimate is. The overshoot is bounded by the cost of the largest single step: a 500-cent step overshoots a 100-cent cap by 400. So put a cap on single-step cost too (timeouts, output limits), and keep the money in integers, because floating-point sums such as repeated 0.10 can land on the wrong side of a cap.
Check yourself
Check: a duplicate email
An agent’s “send invoice” tool times out. The agent retries, and the customer receives two emails. Name two controls that would have prevented the duplicate, and one that helps afterwards.
Answer
Prevent: an idempotency key on the send call, reused on the retry so the server recognises it as the same request, and a checkpoint or status record that shows the send already happened before retrying. Afterwards: the runbook and audit log, which let you see what was sent and replay the session, and a new hook or guard so the incident ends in a permanent control.
Summary
Recap
- One run proves little: fix the model, change one thing, use the same held-out tasks, run several trials, grade the end state.
- passk measures reliability; cost per resolved task is attempt cost divided by success rate, aggregated over tasks.
- The loop: run, trace, classify by layer, make a structural fix, add a regression check, re-run, keep or revert.
- Re-baseline after a model upgrade, tie rules to failures, prune what you cannot justify, and version the harness.
- Operate with checkpoints, idempotent tools, budgets, a kill switch, rollback, safe degradation and a runbook.
References
References & Sources (1 of 2)
Demystifying evals for AI agents (opens in a new tab)
Mikaela Grace, Jeremy Hadfield, Rodrigo Olivares, Jiri De Jonghe2026Article
https://www.anthropic.com/engineering/demystifying-evals-for-ai-agents
Used for Multiple trials, grading outcomes over paths, grader types, reading transcripts, the CORE-Bench and git-history examples, pass@k and pass^k definitions, 20 to 50 tasks (9 January 2026).
Writing effective tools for agents — with agents (opens in a new tab)
Ken Aizawa2025Article
https://www.anthropic.com/engineering/writing-tools-for-agents
Used for Used held-out test sets to avoid overfitting to training evaluations (11 September 2025).
How we built our multi-agent research system (opens in a new tab)
Jeremy Hadfield, Barry Zhang, Kenneth Lien, Florian Scholz, et al.2025Article
https://www.anthropic.com/engineering/multi-agent-research-system
Used for Started with about 20 real queries, checkpoint-based resume, and rainbow deployments (13 June 2025).
τ-bench: A Benchmark for Tool-Agent-User Interaction in Real-World Domains (opens in a new tab)
Shunyu Yao, Noah Shinn, Pedram Razavi, Karthik Narasimhan2024Preprint
arXiv 2406.12045 (opens in a new tab)https://arxiv.org/abs/2406.12045
Used for Proposes the pass^k metric to evaluate reliability over multiple trials.
deepset2026Article
https://www.deepset.ai/blog/harness-engineering
Used for Describes the run, observe, classify, update, repeat loop and says tracing makes failure classification possible (21 May 2026).
References
References & Sources (2 of 2)
Harness engineering for coding agent users (opens in a new tab)
Birgitta Böckeler2026Article
https://martinfowler.com/articles/harness-engineering.html
Used for Improve controls when an issue recurs, and the open question of whether a sensor that never fires signals quality or blindness (2 April 2026).
Agent Harness (opens in a new tab)
Microsoft Learn (Agent Framework)2026Documentation
https://learn.microsoft.com/en-us/agent-framework/concepts/harness
Used for States that its harness enables OpenTelemetry observability by default (page updated 28 September 2026).
Agent Harness Engineering (opens in a new tab)
Addy Osmani2026Article
https://www.oreilly.com/radar/agent-harness-engineering/
Used for Quotes Anthropic that every harness component encodes an assumption about what the model cannot do alone (15 May 2026).
Idempotent requests (opens in a new tab)
Stripe2026Documentation
https://docs.stripe.com/api/idempotent_requests
Used for Idempotency keys let a retried request avoid performing the same operation twice.
Keys: ← → move, Home End first and last, F full screen.