The harness: what turns a language model into an agent
TL;DR
- A model only writes text. The harness around it (loop, tools, permissions, context) is what lets Claude Code, Codex or Cursor actually do work.
- LangChain is a toolkit for building a harness, and LangChain’s own Deep Agents is one.
- The same model scores very differently on coding benchmarks depending on the harness it runs in.
When someone says “Claude fixed my bug”, two things are at work. The model reads and writes text. The harness is the program around it that lets it read files, run commands and check its own work, so the harness decides what the model can do.
A model only writes text
A language model just predicts the next token, so it can’t open a file, run a test or visit a website. Ask a bare model “which of my tests fail?” and it can only guess. Ask Claude Code, Codex or Cursor and it runs the tests, reads the failures, edits the code and runs them again. I like Simon Willison’s definition, an agent runs tools in a loop to achieve a goal.
How tool calling works
With every request the harness sends the list of tools, each with a name, a description and a small JSON schema for its input.
{
"name": "run_command",
"description": "Run a shell command in the project folder and return its output.",
"input_schema": { "type": "object",
"properties": { "command": { "type": "string" } },
"required": ["command"] }
}
The model can then reply with a request like “call run_command with {"command": "pytest"}”. In Anthropic’s API that’s a tool_use block and the response stops with stop_reason: "tool_use". Nothing has run yet. The harness runs it, sends the output back as a tool_result, and the model decides what’s next.
you: What's the weather in San Francisco? (tools: get_weather)
model: tool_use get_weather {"location": "San Francisco, CA"}
harness: (calls the weather API) → "15°C, partly cloudy"
harness: tool_result "15°C, partly cloudy"
model: It's 15°C and partly cloudy in San Francisco. (done)
A whole harness in 30 lines
The core is small. Thorsten Ball builds a working coding agent in a few hundred lines of Go and calls it “an LLM, a loop, and enough tokens”. Here’s the shape in Python-like pseudocode.
TOOLS = [run_command_schema] # what the model may ask for
def run_tool(name, args):
if name == "run_command":
# a real harness asks permission or uses a sandbox here
out = subprocess.run(args["command"], shell=True,
capture_output=True, text=True, timeout=60)
return (out.stdout + out.stderr)[-10_000:] # keep long output short
return "Error: unknown tool " + name
def agent(task, llm, max_steps=30):
messages = [{"role": "system", "content": "You are a coding agent. Use tools."},
{"role": "user", "content": task}]
for _ in range(max_steps): # the loop
reply = llm(messages, tools=TOOLS) # the model only returns text/JSON
messages.append(reply)
if not reply.tool_calls: # no tool requested: finished
return reply.text
for call in reply.tool_calls: # the harness does the acting
result = run_tool(call.name, call.args)
messages.append(tool_result(call.id, result))
return "Stopped: step limit reached."
Every line is a harness decision. TOOLS sets what the agent can touch, run_tool how safely it runs, [-10_000:] how much output the model sees, messages what it remembers and max_steps when it stops. Change any of them and the same model behaves differently.
What a real harness adds
In real use the 30-line loop breaks in predictable ways, and each fix is another part of the harness.
| Problem | Harness part |
|---|---|
| The model must know how to behave | System prompt and tool descriptions, written like onboarding notes. Anthropic says it spent more time on its tools than on the prompt. |
| The conversation gets too long | Context management: trim tool output, clear old results, and near the limit compact (summarise the history and continue from the summary). |
| Edits must be reliable | Edit tools that replace an exact string (only if it appears once) instead of rewriting whole files. |
| The model could do harm | Permissions and sandboxing: allow, ask or deny before each tool call; OS sandboxes limit files and network hosts. |
| A big task needs lots of reading | Sub-agents work in a fresh context and return only a short summary. |
| Every session starts from zero | Memory files such as CLAUDE.md or AGENTS.md, loaded at the start. |
| Know-how should load only when needed | Skills: folders with a SKILL.md that the agent reads only when a task calls for it. |
| Some rules must always hold | Hooks: your scripts run before or after a tool call and can block it. A hook is not a suggestion. |
| Connecting to other systems | MCP (Model Context Protocol): write a tool once (database, issue tracker, browser) and use it in any harness. |
Honestly, none of this is model research. The “AI” is one API call and the rest is systems work.
“Isn’t this what LangChain does?”
Partly. LangChain splits its own products into three layers.
- Framework: LangChain. Model wrappers, tools and, since version 1.0 (October 2025),
create_agent, which is “built around the core agent loop” and has middleware hooks to change it. - Runtime: LangGraph. Runs long agents as graphs with saved state, so they can pause for a human, survive a crash and resume.
- Harness: Deep Agents. LangChain calls harnesses “opinionated, batteries-included frameworks with built-in tools”. Deep Agents adds planning, a file system, sub-agents and a detailed prompt on top of
create_agent, and its authors say it was “primarily inspired by Claude Code”.
So I feel “LangChain or a harness?” is the wrong question. A LangChain agent already is a harness core (model, tools, loop), and the real choice is how much of the rest you build. Even Harrison Chase, LangChain’s CEO, says there’s no clear line between framework, runtime and harness.
| Option | Examples | Good for | Cost |
|---|---|---|---|
| Ready-made harness | Claude Code, Codex, Cursor | Coding and dev work today | Little control over the loop; built around one product |
| Harness SDK | Claude Agent SDK, Codex SDK, Deep Agents, Microsoft’s Harness Agent | A proven loop and context handling inside your own app | Opinionated; you still build the server, auth and multi-tenancy |
| Framework or runtime | LangChain + LangGraph, OpenAI Agents SDK, Google ADK, Pydantic AI | Custom workflows, any model, durable state | You design the prompts, compaction and permissions yourself |
| Raw API + your own loop | The 30 lines above | Learning; very small agents | You rebuild retries, context limits, sandboxing and tracing |
What changed in 2025–26
- Harnesses became products you can embed. In September 2025 the Claude Code SDK became the Claude Agent SDK, “the agent harness that powers Claude Code”. LangChain shipped Deep Agents and Microsoft’s Agent Framework added a Harness Agent.
- The plumbing got a neutral home. In December 2025 the Linux Foundation formed the Agentic AI Foundation, starting with MCP (Anthropic), AGENTS.md (OpenAI) and goose (Block).
- Skills became an open standard. A skill is a folder with a
SKILL.mdthat loads only when relevant, so an agent can carry many without bloating its context. - “Harness engineering” got a name. Birgitta Böckeler defines the harness as everything in an agent except the model, i.e. Agent = Model + Harness.
- Agents moved to the background. Claude Code on the web and Codex cloud run tasks in sandboxes and open pull requests while you do something else.
Why the harness matters as much as the model
This part surprised me. The SWE-agent paper (NeurIPS 2024) kept the model (GPT-4 Turbo) and the benchmark (real GitHub issues, SWE-bench Lite) fixed and only changed how the model used the computer.
- No edit tool: 18.0% dropped to 10.3%.
- Whole files instead of a 100-line window: 12.7%.
- Full history instead of the last five tool outputs: 15.0%. More context was actually worse.
Anthropic saw the same. Its upgraded Claude 3.5 Sonnet hit 49% on SWE-bench Verified with a deliberately simple harness (a prompt, a bash tool, an edit tool), above the previous best of 45%. Epoch AI found that just switching the scaffold moved SWE-bench Verified scores by up to 11 points for GPT-5 and 15 for Kimi K2 Thinking. So I think “model A vs model B” is often “model A in harness X vs model B in harness Y”.
Open-source harnesses to read
| Project | Why look at it |
|---|---|
| mini-swe-agent | About 100 lines: one bash tool and a plain message history. Start here. |
| “How to Build an Agent” (Thorsten Ball) | A step-by-step Go agent with three file tools. |
| Deep Agents | LangChain’s harness: planning, file system, sub-agents and skills on top of create_agent. |
| smolagents | Agents that act by writing Python code instead of JSON tool calls. |
| Aider | A mature terminal pair programmer with a repo map and git commits for every change. |
| OpenAI Codex CLI | A production coding agent in Rust with sandbox modes and approval policies. |
| OpenHands, goose, opencode | Larger general agents with Docker sandboxes or MCP extensions. |
I’d start with mini-swe-agent, then Thorsten Ball’s post, then Deep Agents. The big ones make more sense once you know the loop at their centre.
Brain and body
The way I see it, the model thinks and the harness acts. It gives the model tools, runs them safely, picks what it sees and keeps it going until the job is done. It’s all plain engineering, so any software engineer can learn to build one.
Further reading
- Building effective agents (Anthropic).
- Effective context engineering for AI agents (Anthropic).
- Agent frameworks, runtimes, and harnesses – oh my! (Harrison Chase, LangChain).
- LangChain vs LangGraph vs Deep Agents (LangChain docs).
- Harness engineering for coding agent users (Birgitta Böckeler).
- Building agents with the Claude Agent SDK (Anthropic).
- The Agentic AI Foundation (Linux Foundation).
- A definition of “agent” (Simon Willison).
- Why benchmarking is hard (Epoch AI).