Mahir Shahriar Tamim

AI Researcher · Explainable & Responsible AI · Vision, Language & Agentic Systems

← All posts

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.

Model alone “Which tests fail?” LLM “Probably the login tests?” a guess: it has never seen your code Model + harness harness LLM run tests read file edit file “2 tests fail; fixed”
Same kind of model, two setups. On its own it can only guess. In a harness it can look, act and check.

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)
you context prompt · history · tools LLM tool request? permission? rules · sandbox run tool shell · files · web yes tool_result added final answer no repeat until the model stops asking
The agent loop. The model only writes the request. The harness checks it, runs it and feeds the result back.
Modelonly writes text
Harnessruns things, keeps the loop

    A scripted run of a coding agent fixing a failing test. Notice that every action happens on the harness side.

    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

    the harness system prompt + tool schemas context manager trim · compact permissions + sandbox sub-agents fresh context the loop edit tools LLM predicts tokens CLAUDE.md · AGENTS.md hooks you computer shell · files MCP servers DBs · APIs
    What sits around the model in a tool like Claude Code or Codex.

    In real use the 30-line loop breaks in predictable ways, and each fix is another part of the harness.

    ProblemHarness part
    The model must know how to behaveSystem 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 longContext management: trim tool output, clear old results, and near the limit compact (summarise the history and continue from the summary).
    Edits must be reliableEdit tools that replace an exact string (only if it appears once) instead of rewriting whole files.
    The model could do harmPermissions and sandboxing: allow, ask or deny before each tool call; OS sandboxes limit files and network hosts.
    A big task needs lots of readingSub-agents work in a fresh context and return only a short summary.
    Every session starts from zeroMemory files such as CLAUDE.md or AGENTS.md, loaded at the start.
    Know-how should load only when neededSkills: folders with a SKILL.md that the agent reads only when a task calls for it.
    Some rules must always holdHooks: your scripts run before or after a tool call and can block it. A hook is not a suggestion.
    Connecting to other systemsMCP (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”.
    you / your app a task, a repo, a product harness loop + tools + context permissions, assembled framework / runtime parts to build a loop model API text in, text out “fix the failing test” · an internal support bot Claude Code · Codex · Cursor ready to use Claude Agent SDK · Deep Agents harness as a library LangChain + LangGraph · OpenAI Agents SDK · Google ADK · Pydantic AI Claude · GPT · Gemini · open models build your own
    Where things sit. A framework gives you the parts, and a harness is a finished assembly of them. LangChain’s own Deep Agents sits in the harness layer.

    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.

    OptionExamplesGood forCost
    Ready-made harnessClaude Code, Codex, CursorCoding and dev work todayLittle control over the loop; built around one product
    Harness SDKClaude Agent SDK, Codex SDK, Deep Agents, Microsoft’s Harness AgentA proven loop and context handling inside your own appOpinionated; you still build the server, auth and multi-tenancy
    Framework or runtimeLangChain + LangGraph, OpenAI Agents SDK, Google ADK, Pydantic AICustom workflows, any model, durable stateYou design the prompts, compaction and permissions yourself
    Raw API + your own loopThe 30 lines aboveLearning; very small agentsYou 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.md that 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

    ProjectWhy look at it
    mini-swe-agentAbout 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 AgentsLangChain’s harness: planning, file system, sub-agents and skills on top of create_agent.
    smolagentsAgents that act by writing Python code instead of JSON tool calls.
    AiderA mature terminal pair programmer with a repo map and git commits for every change.
    OpenAI Codex CLIA production coding agent in Rust with sandbox modes and approval policies.
    OpenHands, goose, opencodeLarger 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