← govind p lal
AI and ML Bootcamp · Lecture 18 · lecture notes

Harness Engineering, Context Engineering and Evals

In short — The same model can score very differently depending on what is built around it. This lecture covers the harness (what wraps the model), how to manage the context it sees, and evals (how we learn where the harness fails). Together they form a loop that keeps improving an agent.

Why the harness matters

builds on Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026, Lecture 17: Week 16 - AI&ML | Offline: RL Environments for LLMs | 08/05/2026

On Terminal-Bench, the same underlying model (Opus 4.6) gives very different scores. Claude Code as a harness: 58%. ForgeCode: 79.8%. Another competitor: about 75%. What changed? Only the harness.

Agent = Model + Harness. Raw model alone is not an agent. Harness alone is not an agent.

Why Claude Code scores lower: it serves many domains (design, docs, coding), so it is not tuned only for bash tasks. Third parties can optimise hard for one benchmark.

Harness engineering

builds on Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026

Things we can control, since we cannot touch weights: system prompt, tools / MCPs, memory, sandbox / code execution, hooks, markdown files. Engineering these -> Harness engineering.

Run a task. If the agent succeeds or fails, we know which of these knobs to adjust.

Model deficiencies and harness fixes

builds on Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026, Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026
Model deficiencyHarness fix
Stateless, starts fresh each timeFile system (store and read state)
Cannot run codeBash / code execution
Runs unsafe code on your machineSandbox
Context gets bloatedCompaction, sub-agents
Gets stuck, lacks infoMiddleware: hooks, tools, MCPs

Middleware sits between the agent and its final output.

Model-harness fit

builds on Lecture 8: Week 7 - AI&ML | Training Your First Model | 28/02/2026

Different companies post-train their models on different tool vocabularies. The model expects to call tools in the way it was trained.

TaskCodex (GPT-5.5)Claude Code
Edit fileapply_patch (diff)Edit tool: string replacement
Save memorymemory citation tagsystem-reminder tag
Run commandsingle exec command toolbash tool plus a monitor tool for long runs

You can force GPT to use string replacement, but you pay: more tokens, more reasoning, more tool-call errors, less efficiency.

!

The harness is part of the model's effective parameters. A harness tuned for Claude does not transfer unchanged to Codex.

Costs of switching models mid-chat

Options: design for multiple models, or pick one model and adapt tightly. Tools like Cursor use a proxy to handle caching and transcript differences across models.

Dead-weight scaffolding is found by trial and error. Look at the raw model's behaviour first, then amplify it. New models can make old scaffolding useless, so re-check it -> that is why evals matter.

Demo: harness improvements

builds on Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026, Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026

Each change is about 30-40 lines.

  1. Truncate tool output
  1. Stuck-loop middleware
  1. Sub-agents
one paper eachshort summaryMain agentSub-agent: paper 1Sub-agent: paper 2Sub-agent: paper NFinal answer
Sub-agents do the heavy reading; the parent only sees summaries.

Context window is not equal to usable context

adds to earlier · Attention budget explanation and the smallest-high-signal-token rule with removal test · builds on Lecture 11: Week 10 - AI&ML | RAG Continuation - Part 2 | 23/03/2026, Lecture 5: Week 4 - AI&ML | Transformers: Part 2 | 07/02/2026

Attention compares every token with every other token -> about n squared computations. More tokens, less efficiency. Anthropic calls this the attention budget: it depletes with each added token.

!

Mantra: the smallest set of high-signal tokens.

How to find high-signal tokens: remove part of the system prompt. If performance stays the same, drop it. If output degrades, it was high signal. Repeat until removing anything hurts.

How to prompt: the Goldilocks zone

Should the system prompt list every case or stay vague? Both fail.

The Solution: hybrid. State the goal (resolve the user's query respectfully and helpfully) plus a few examples of how to handle typical cases. Few-shot examples, not an exhaustive rulebook.

Preloading vs just-in-time context

builds on Lecture 10: Week 9 - AI&ML | RAG from the Ground Up - Part 1 | 13/03/2026
PreloadedJust-in-time (JIT)
IdeaLoad all info at startAgent fetches when needed
SpeedFastSlower (extra tool calls)
ContextBloated as data growsSmall
Best forSmall dataLarge data, many operations

Coding agents use a hybrid. Always preload instruction and memory files (e.g. CLAUDE.md, memory.md, agents.md). Also preload only file metadata (name, folder, location). Fetch full files on demand. This mimics a human exploring a codebase.

Demo: preloaded used about 10,000 tokens at 1.7s. JIT used about 1,300 tokens at 2.9s. Latency can be cut with faster or parallel tool calls.

Long-horizon strategies

builds on Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026

Compaction prompt rule: maximise recall first (cover everything done), then improve precision (exact function, exact line).

Demo: compaction at 700 tokens fired on turns 11 and 13, keeping context from growing every turn.

!

LLMs are not exact. Asked to reproduce exactly 25, 100, 500, 1500, 3000 words, none matched; one overshot by 58%, others undershot by about 50%. Always inspect traces.

Evals are a learning signal

builds on Lecture 11: Week 10 - AI&ML | RAG Continuation - Part 2 | 23/03/2026, Lecture 17: Week 16 - AI&ML | Offline: RL Environments for LLMs | 08/05/2026

Misconception: evals are the last step. Reality: evals are a learning signal showing what the harness is good and bad at. Harness + context + evals together improve the agent over each release.

Vocabulary

!

General model benchmarks do not tell you how the model does in your product. A model with a worse general score can be better for your use case.

BinaryLikert
FormatPass or fail with a reasonScores out of 5 on helpfulness, respect, conciseness
SignalConcrete, actionable failureA 2 vs 3 tells you nothing to act on
VerdictPreferredAvoid

Building good evals

builds on Lecture 11: Week 10 - AI&ML | RAG Continuation - Part 2 | 23/03/2026

Split data into a small set for few-shot examples, a dev set to tune the judge prompt, and a test set to measure it.

Demo: with bad data injected, zero-shot judge got TPR 1.0, TNR 0.75, accuracy 80%. Adding few-shot examples improved all three.

MetricMeaningQuestion it answers
pass@kSucceeds at least once in k triesIs it solvable at all?
pass^kSucceeds on all k triesIs it reliable?

Flywheel - production traces expose new errors -> become new evals -> update harness -> better agent -> new error types -> repeat.

new errorslearning signalnew failuresProduction tracesNew evalsUpdate harnessBetter agent
The eval flywheel.

Glossary

Harness
Everything built around a model (prompt, tools, memory, sandbox, hooks) that turns it into an agent.
Middleware
Hooks and tools between the agent and its final output.
Compaction
Summarising the context and restarting from the summary when the window nears full.
Trial
One attempt at an eval task.
Flywheel
Loop where production traces create evals that improve the harness.
Attention budget
Idea that attention capacity shrinks as more tokens fill the context.