Harness Engineering, Context Engineering and Evals
Why the harness matters
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.
- Model - borrowed from Anthropic, OpenAI, Alibaba etc. We have almost no control over weights.
- Anyone can use the same model, so the model is not your moat.
- Harness - everything we build around the model. This is where we differentiate.
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
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
| Model deficiency | Harness fix |
|---|---|
| Stateless, starts fresh each time | File system (store and read state) |
| Cannot run code | Bash / code execution |
| Runs unsafe code on your machine | Sandbox |
| Context gets bloated | Compaction, sub-agents |
| Gets stuck, lacks info | Middleware: hooks, tools, MCPs |
Middleware sits between the agent and its final output.
Model-harness fit
Different companies post-train their models on different tool vocabularies. The model expects to call tools in the way it was trained.
| Task | Codex (GPT-5.5) | Claude Code |
|---|---|---|
| Edit file | apply_patch (diff) | Edit tool: string replacement |
| Save memory | memory citation tag | system-reminder tag |
| Run command | single exec command tool | bash 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
- History uses the old model's vocabulary, so the new model hallucinates or wastes reasoning tokens.
- Prompt cache lives on the provider's servers. Switching provider means no cache hit and you pay again.
- Tool mismatch and out-of-distribution transcripts.
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
Each change is about 30-40 lines.
- Truncate tool output
- Keep only the first and last lines of each tool result in context.
- Save the full output to a file the agent can read if needed.
- Result: about 11,000 tokens -> about 1,000 tokens (90% reduction).
- Stuck-loop middleware
- Test: write add(a, b) with tests 2+2=4 and an impossible 2+2=5, and do not edit the tests.
- The agent cheated with a counter: first call returns 4, second returns 5, ignoring the inputs. It took 6 tool calls.
- Fix: a hook detects the same action for about 3 turns and asks, 'Is your approach wrong? Are you bypassing the tests?'
- Sub-agents
- Problem: passing 5 papers directly costs about 5000 tokens in the main context.
- Solution: main agent dispatches one sub-agent per paper. Each returns a short summary.
- Main context ended at about 205 tokens (about 25x less). Typical saving is 5-10%.
- Sub-agents can use a cheaper model since tasks are simple.
Context window is not equal to usable context
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.
- Listing every case - brittle. Unlisted cases give unpredictable behaviour.
- Vague ('be respectful, thank the user') - customer asks 'when is my flight?', bot just thanks them and asks for feedback. Polite, useless.
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
| Preloaded | Just-in-time (JIT) | |
|---|---|---|
| Idea | Load all info at start | Agent fetches when needed |
| Speed | Fast | Slower (extra tool calls) |
| Context | Bloated as data grows | Small |
| Best for | Small data | Large 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
- Compaction - summarise the whole context and start a fresh session from the summary. Trigger at a threshold (e.g. 70-80% of a 256K window).
- Note-taking - agent writes steps and state to a file like scratchpad.md and reads it in a new session. Good for long iterative tasks (Claude playing Pokemon tracked levels, items, region).
- Sub-agents - offload context-heavy work and return only a summary.
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
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
- Task - one test with defined input and success criteria.
- Trial - a single attempt at a task. Run several to measure non-determinism.
- Grader - judges what failed or passed and why.
- Transcript - full trace: reasoning, tool calls, steps.
- Final state - the outcome at the end.
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.
| Binary | Likert | |
|---|---|---|
| Format | Pass or fail with a reason | Scores out of 5 on helpfulness, respect, conciseness |
| Signal | Concrete, actionable failure | A 2 vs 3 tells you nothing to act on |
| Verdict | Preferred | Avoid |
Building good evals
- Domain expert - gives few-shot examples and reviews traces.
- Diverse use cases - new customer, old customer, frustrated user, payment query and so on.
- Detailed critique - give a concrete reason for each failure.
- Fix obvious agent issues found while building evals right away.
- Build an LLM-as-judge.
- Error analysis - categorise failures at scale. Add new failures, drop fixed ones, keep a regression set.
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.
- True positive rate (TPR) - judge catches what it should catch.
- True negative rate (TNR) - judge correctly passes good outputs.
- False positives are also tracked.
Demo: with bad data injected, zero-shot judge got TPR 1.0, TNR 0.75, accuracy 80%. Adding few-shot examples improved all three.
| Metric | Meaning | Question it answers |
|---|---|---|
| pass@k | Succeeds at least once in k tries | Is it solvable at all? |
| pass^k | Succeeds on all k tries | Is it reliable? |
Flywheel - production traces expose new errors -> become new evals -> update harness -> better agent -> new error types -> repeat.
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.