Harness Engineering for AI Agents
Build an agent harness from an empty while-loop, then add tools, skills, guardrails and verification. Measure it with evals and traces, compare models side by side, and cut whatever stops paying off.
Levels 1 and 2 are free to read, no account needed. Levels 3 and 4 are free with a free account, and so are 20 answers from the AI tutor.

Expert · 40 levels · 4 free · Created Nov 2026 · Professionally curated by levelupwith.com
What's inside
- Level 1: Same Model, Different Scores: Why Harnesses MatterFree
Read benchmark results where the model stays fixed and only the harness changes, and see why the code around the model can move results by as much as switching models.- Explain what a harness is, and why Terminal-Bench 2.0 results for one model differ across harnesses such as Terminus 2 and vendor agents
- Read a leaderboard entry critically by checking which harness ran it and what it spent in tokens and turns
- List three questions to ask before believing that one model beats another
- Level 2: Anatomy of a HarnessFree
Break an agent harness into its parts (model client, loop, tools, context, guardrails, verification) and find each part in a coding agent you already use.- Draw the parts of a coding agent's harness and say what each part is responsible for
- Sort behaviours you have seen in a coding agent into model behaviour and harness behaviour
- Set up the course repo with matching Python and TypeScript starter projects
- Level 3: One Thin Client for Many ModelsFree account
Write a small, vendor-neutral chat interface that calls Claude, OpenAI, Gemini and an open-weight model through the same function signature.- Put roles, messages, system prompts and token usage from each provider's API into one shared message type
- Switch providers through configuration without changing the code that calls the client
- Record latency, token counts and cost for every call
- Level 4: The Empty While-LoopFree account
Build the smallest possible agent loop: call the model, add its reply to the conversation, and repeat, with the conversation state kept explicit and easy to inspect.- Write a working agent loop in under 40 lines of Python and of TypeScript
- Explain why the loop keeps the full message history, and what resending it costs on every turn
- Print the conversation state at each turn so you can watch the loop run
- Level 5: Tool Calling: Declare, Parse, Execute
Add tool use to the loop by declaring a tool, spotting tool-call blocks in the model's reply, running them, and handling how each provider formats them differently.- Declare a read_file tool and run it whenever the model asks for it
- Handle several tool calls in one turn and match each result to the call that requested it by ID
- Turn Claude, OpenAI and Gemini tool-call formats into one internal representation
- Level 6: Feeding Results Back Into Context
Return tool results to the model in a form that is useful and affordable, keeping long outputs, binary data and growing context under control.- Shorten and summarise long tool outputs, with a clear note showing where text was cut
- Track context size per turn and warn as it approaches a set budget
- Explain how a badly shaped tool result can get the agent stuck repeating the same step
- Level 7: Stop Conditions
Decide when the loop should end, using the model's own end-of-turn signal, turn and token budgets, timeouts and detection of repeated actions.- Add stop reasons for the model finishing, maximum turns, token or cost budget, and wall-clock timeout
- Spot a stuck agent that keeps making the same tool call and stop it
- Return a clear final result that says why the loop stopped
- Level 8: A Minimal Coding Agent, Traced
Put the loop together into a small coding agent that can read, write and run code, with retries for API failures and a trace of every step.- Build a coding agent with read, write and shell tools in both Python and TypeScript
- Handle rate limits, temporary API errors and malformed tool calls without crashing
- Write each turn to a JSONL trace and replay a run to see why it succeeded or failed
- Level 9: Tool Names and Descriptions
Write tool names and descriptions that tell the model what a tool does, when to use it and when not to, and see how wording changes which tool it picks.- Rewrite vague tool names and descriptions so they are clear and don't overlap
- Add usage notes and short examples to a description without bloating the context
- Run a small before-and-after test of how often the model picks the right tool
- Level 10: Tight Tool Schemas
Design parameter schemas that make wrong calls hard to express, using enums, required fields, clear types, and the strict or structured modes that providers offer.- Replace free-text parameters with enums and constrained types where they fit
- Turn on and compare each provider's strict schema mode and note its limits
- Validate tool arguments in code before running anything
- Level 11: Errors Written for the Model
Return tool errors that tell the model what went wrong and what to try next, so it can recover on its own rather than give up or guess.- Turn raw exceptions and stack traces into short error messages that suggest a fix
- Tell apart errors the model can fix from errors it should report to the user
- Show in a trace that better error messages reduce wasted turns
- Level 12: Tool Granularity and Output Shape
Choose between a few general tools (such as a shell) and many specialised ones, and shape tool outputs with pagination, filtering and concise formats.- Weigh the trade-offs of a single bash tool against dedicated file and search tools
- Add pagination and filtering to a search tool so it doesn't flood the context
- Merge or split tools based on how the model actually uses them in traces
- Level 13: When Tools Multiply: Routing and Tool Search
Measure how tool-selection accuracy drops as the tool count grows, and keep it up with routing, grouping and loading tool definitions only when needed, including tools from MCP servers.- Run a simple experiment showing selection accuracy against the number of tools for one model
- Add a router or tool-search step that shows the model only the relevant tools
- Decide when connecting an MCP server helps and when it just adds clutter
- Level 14: Context Files: AGENTS.md and CLAUDE.md
Write project context files that give an agent the conventions, commands and constraints it needs, and learn how agents find and layer these files.- Write a short AGENTS.md covering build, test and style rules for a real repo
- Explain how nested and global context files are loaded and which takes priority, and where tools differ
- Cut a bloated context file down to the instructions that measurably change behaviour
- Level 15: Skills and Progressive Disclosure
Package know-how as SKILL.md skills: the agent sees only a skill's name and description, loads the full instructions when a task matches, and reads bundled files only when needed.- Write a skill folder with SKILL.md frontmatter, instructions and a supporting script
- Add simple skill discovery and loading to your own harness
- Decide what goes in the always-on context, in a skill, or in a reference file
- Level 16: User-Invoked vs Model-Invoked Skills
Decide when a skill should run only when the user explicitly calls it and when the model should trigger it on its own, and write descriptions that trigger reliably.- Add both an explicit slash-command path and a model-triggered path to your harness
- Test whether skill descriptions trigger on the right prompts and not on the wrong ones
- Choose the right way to invoke risky or costly skills
- Level 17: Managing Context on Long Runs
Keep long agent runs coherent with compaction, notes kept in files, and sub-agents that work in their own context and return only a summary.- Add a compaction step that summarises old turns while keeping key facts
- Hand a search-heavy subtask to a sub-agent and return only its summary
- Compare a long run with and without compaction using traces and token counts
- Level 18: Guardrails as Code: Deterministic Hooks
Understand why instructions in a prompt get ignored, and add hooks that run your own code before and after each tool call so certain rules always hold.- Add pre-tool and post-tool hook points to your agent loop
- Write a hook that blocks edits to protected files whatever the model decides
- Explain which rules belong in a hook and which belong in an instruction
- Level 19: Permission Checks and Sandboxing
Control what the agent may do with allow, deny and ask policies for commands and paths, and run risky actions in a sandbox.- Write an allow/deny/ask permission layer for shell commands and file paths
- Run the agent's shell tool inside a container or restricted working directory
- Explain why pattern-matching shell commands is fragile and what to do about it
- Level 20: Validators That Feed Back
Check tool inputs and the agent's final outputs against schemas and rules in code, and send failures back to the model as specific, fixable feedback.- Validate structured outputs and tool arguments with Pydantic in Python and Zod in TypeScript
- Send validation failures back to the model with a retry limit
- Decide when a failed check should stop the run and when it should let the model try again
- Level 21: Turn Repeated Corrections into Checks
Learn to spot corrections you keep giving an agent in prompts and context files, and turn each one into a deterministic check that blocks or repairs the behaviour, so you stop adding more instructions.- Mine your traces and review comments for corrections that keep coming back, and rank them by how often they occur and how much they cost
- Turn a natural-language rule such as 'never edit generated files' into a hook or validator in Python and TypeScript that returns an error message the model can act on
- Delete the instruction the check replaces, then confirm on a few tasks that the behaviour holds without it
- Level 22: Tests as the Agent's Feedback Signal
Wire test runs into the agent loop so failing output comes back to the model in a form it can act on, and learn why running tests the agent cannot game beats asking the model whether its code works.- Add a run_tests step that captures failures, trims noisy output and feeds a short, readable summary back into context
- Stop the agent from deleting or weakening tests to pass, using file protections and a check on the diff
- Choose between running the full test suite and only the relevant tests at each step, weighing feedback quality against time and token cost
- Level 23: Linters and Type Checks in the Loop
Use linters, formatters and type checkers (such as ruff, mypy or pyright, eslint and tsc) as fast, cheap verifiers, and decide which should auto-fix quietly and which should report back to the model.- Run a formatter automatically after every edit and send only the remaining lint and type errors back to the model
- Order checks by speed and cost so cheap failures show up before slow test runs
- Measure whether adding a type-check step really cuts failed tasks on your own examples, rather than assuming it does
- Level 24: Self-Review and Model Reviewers: When They Help
Build self-review and separate reviewer-model passes, and learn from your own measurements when a second look finds real bugs and when it only adds cost or makes harmless changes.- Build a reviewer step that sees the task, the diff and the check results, and returns findings in a structured format
- Compare self-review, a fresh-context reviewer and a different-model reviewer on the same failing examples
- Explain why model review works best alongside deterministic checks rather than in place of them, and treat the size of the gain as an open question to settle with your own data
- Level 25: Verification Budgets and Retry Limits
Put the checks together into one verification loop with retry limits, escalation and give-up rules, so the agent fixes what it can fix and stops cleanly when it can't.- Set limits on verification retries, tokens and wall-clock time, and record why each run stopped
- Detect when the agent is stuck repeating the same failure and escalate to a person, or roll back, instead of looping
- Read a run's log of attempts and decide whether the verification loop helped, hurt or made no difference
- Level 26: Build a Small Eval Set That Matters
Build a 20–50 task eval set from real work and real failures, with fixed starting states, so you can judge a harness change with evidence instead of gut feel.- Pick tasks from real bugs, traces and user requests that cover the main types of work and the known ways the harness fails
- Package each task so it can be re-run: repository snapshot, prompt, environment and expected outcome
- Keep a held-out split so harness changes are not tuned to the same tasks you report results on
- Level 27: Graders: Deterministic Checks vs Model Judges
Score eval runs with code-based graders where you can and model-based judges where you must, and check that the judges agree with human judgement before trusting them.- Write code-based graders (tests pass, file changed, no forbidden calls) in Python and TypeScript
- Write a model-judge rubric with narrow pass/fail criteria, and measure how often it agrees with your own hand labels
- Recognise common judge failures, such as preferring longer answers, favouring its own output, or being swayed by text placed in the output, and design against them
- Level 28: Traces and Failure Analysis
Record structured traces of every model call, tool call and check, then read and label them to find which part of the harness causes most failures.- Record traces with spans for model turns, tool calls, tokens, latency and stop reasons, using OpenTelemetry-style structure or a tracing tool of your choice
- Label failed runs into a small set of causes (wrong tool, bad context, gave up, check gamed) and count them
- Turn the most common failure cause into one concrete harness change with a prediction you can test
- Level 29: Ablations, Variance and Fair Comparisons
Run controlled experiments that change one harness component at a time and repeat each run, so random variation in agent output doesn't fool you into keeping a change that did nothing.- Run each setup several times and report pass rates with a simple spread or confidence interval, not one lucky run
- Remove one component at a time (a tool, a skill, a check) to measure what each contributes
- Track cost and latency next to accuracy, so you compare harness versions on all three
- Level 30: Same Harness, Different Models
Run your eval set across Claude, OpenAI, Gemini and an open-weight model behind one provider-neutral interface, and learn which harness choices carry over between models and which need per-model tuning.- Build a thin adapter that maps tool calling and message formats across the providers' APIs and a locally served open-weight model
- Compare pass rate, cost and failure causes per model on the same tasks and harness
- Separate harness settings that hold across models from the ones that need tuning per model, such as tool descriptions, how much reasoning the model is told to do, and context layout
- Level 31: Automatic Prompt Optimisation with DSPy
Use DSPy to describe a harness step as an input/output signature with a metric, then let an optimiser search for better instructions and examples instead of you editing prompts by hand.- Express one harness step, such as tool routing or review, as a DSPy module with a metric taken from your eval set
- Run a DSPy optimiser and compare the optimised step against your hand-written prompt on held-out tasks
- Judge when automatic optimisation is worth its setup and compute cost compared with simply fixing the harness
- Level 32: GEPA and Optimising the Harness Itself
Try GEPA's reflective, trace-driven evolution of prompts and other text in your harness, and learn to spot overfitting and the places where harness optimisation is still unsettled.- Run GEPA (for example through DSPy) on a harness component, feeding it the failure feedback from your traces
- Check optimised results on a held-out split and against a second model to catch overfitting
- State plainly what is still experimental in harness optimisation and decide whether to adopt it for your project
- Level 33: Deleting Harness as Models Improve
Re-measure each piece of harness scaffolding whenever a stronger model arrives, and delete the workarounds the new model no longer needs, without losing the guardrails that protect safety and correctness.- Tag each harness component as a capability workaround, a safety guardrail or a product requirement
- Run removal experiments on a new model and delete components that no longer improve results
- Write a short deprecation note recording what you removed, the evidence behind it, and how to roll it back
- Level 34: Vendor SDKs: Claude Agent SDK and OpenAI Agents SDK
Rebuild a slice of your harness on the Claude Agent SDK and the OpenAI Agents SDK, and compare how each handles the loop, tools, hooks, guardrails, handoffs and tracing, checking every detail against current documentation.- Map your own loop, tools, hooks and checks onto each SDK's building blocks, using the current documentation
- Run the same eval tasks through both and compare results, how much code each needed, and how easy each was to observe
- Identify where each SDK ties you to one vendor and how hard it would be to swap models
- Level 35: Framework Harnesses: LangGraph, Mastra and Strands
Compare LangGraph's graph-based orchestration, Mastra's TypeScript agent and workflow tooling, and Strands Agents' model-driven loop by rebuilding the same agent slice in each.- Implement the same tool-using task in LangGraph and Strands (Python) and Mastra (TypeScript)
- Compare control over the loop, persisted state, human-in-the-loop support and tracing across the three
- Explain which shapes of problem fit a graph, a workflow or a model-driven loop
- Level 36: Adopt a Framework or Write Your Own
Use a decision framework based on control, observability, team skills, vendor lock-in and maintenance cost to choose between an existing harness and your own, and plan how to migrate either way.- Score your project against explicit criteria and defend a build-or-adopt decision with evidence from your evals
- Design a thin internal interface so tools, checks and evals survive a later move to a different framework
- List the hidden costs on each side, such as upgrade churn, debugging through someone else's abstractions, and owning your own loop
- Level 37: Final Project I: Build the Coding Harness
Build a complete coding agent harness from your own components: the loop, a small and well-designed tool set, context files and skills, hooks, permission checks and a verification loop.- Put together a working coding harness in Python or TypeScript that can fix real bugs in a sandboxed repository
- Apply the course's design rules: errors written for the model, a minimal tool set, progressive disclosure, and checks instead of instructions
- Record every component in a manifest that says why it exists and what evidence would justify removing it
- Level 38: Final Project II: Measure the Coding Harness
Measure your coding harness with a held-out eval set, repeated runs, traces and at least two models, to establish an honest baseline for accuracy, cost and latency.- Run the full eval across at least two providers (including one open-weight model if you can), with repeated trials
- Produce a baseline report with pass rates, spread, cost per task and the main failure causes from traces
- Pick the three components most likely to be dead weight, with a hypothesis for each
- Level 39: Final Project III: Cut the Coding Harness
Remove harness components one at a time under measurement, keep only what earns its place, and ship a smaller harness that performs at least as well.- Run removal experiments on your candidate components and keep or delete each one based on the evidence
- Show that the final harness has fewer components and equal or better accuracy, cost or latency on the held-out set
- Document what you cut, what you kept and why, including the guardrails you kept on purpose regardless of their score
- Level 40: Final Challenge: Harness Engineering End to End Exam
Bring the whole course together by designing, defending and critiquing a harness for a new task, covering the loop, tools, context, guardrails, verification, measurement, optimisation, simplification and framework choice.- Design a harness for a new agent task and justify each component with the course's principles and planned evals
- Diagnose a supplied set of failing traces and propose fixes: a tool change, a check or a deletion
- Present a build, measure and cut plan that includes a framework decision and honest notes on where practice is still unsettled
Access
Levels 1 and 2 are free to read, no account needed. Levels 3 and 4 are free with a free account, and so are 20 answers from the AI tutor. Every level, the podcast edition and the AI tutor come with All Access at £4.99/month or any Creator plan — see pricing.
More like this
- Post-Training LLMs: Reward Models, RL and Scale
Train reward models, run PPO, GRPO and multi-turn agent RL on several GPUs, distil and merge models, and keep a tuned model safe.
Course · AI Engineering · AI Engineering · Expert · 60 levels · 4 free · Professionally curated by levelupwith.com
- Agentic Commerce: Safe AI Checkout and Payments
Build checkouts that let AI agents find, buy and pay safely.
Under the Radar · AI Engineering · Expert · 40 levels · 4 free · Professionally curated by levelupwith.com
- Forward Deployed AI Engineer: Pilot to Production
Take an AI system from customer discovery to production inside an organisation: find the workflow worth automating, scope a pilot and build an eval set from…
Course · AI Engineering · AI Engineering · Expert · 40 levels · 4 free · Professionally curated by levelupwith.com
- Autoresearch Loops: Agents That Experiment and Improve
Build agent loops that form a hypothesis, edit code or prompts, run evals, and keep or revert each change.
Under the Radar · AI Engineering · Expert · 39 levels · 4 free · Professionally curated by levelupwith.com
- Agent Interfaces: MCP Apps, Generative UI, WebMCP & A2A
Build agent interfaces people can actually use: ship MCP Apps with sandboxed interactive widgets, stream agent state with AG-UI, expose site tools through…
Under the Radar · AI Engineering · Expert · 40 levels · 4 free · Professionally curated by levelupwith.com
- Voice and Realtime AI Agents: From Mic to Phone Line
Build voice agents you can ship.
Course · AI Engineering · AI Engineering · Expert · 48 levels · 4 free · Professionally curated by levelupwith.com