Short answer
An agent harness is the ordinary software wrapped around a language model that turns it into an agent: it runs the loop of asking the model what to do next, carries out the tool calls the model requests, keeps notes between steps, and enforces what the agent is and isn't allowed to touch. The model supplies the judgment; the harness supplies the hands, the memory and the rules.
Follow-up question Do you need to build your own?
A language model on its own can only read text and write text. It can't open a file, run a test or check a web page. When people talk about an "agent" that fixes bugs or tidies a spreadsheet, most of what makes that possible is the program around the model. That program is called the harness, by analogy with the gear that lets a horse pull a cart: the horse provides the strength, the harness makes it useful and keeps it on the road.
Anthropic, for example, describes its Claude Agent SDK as a general-purpose agent harness, and its engineers report that the design of the harness has a large effect on how well long-running agents perform. Two products using the same model can behave very differently because their harnesses differ.
The four parts of a harness
| Part | What it does | Everyday comparison |
|---|---|---|
| Loop | Sends the task to the model, reads its reply, acts on it, and repeats until the model says it is finished or a limit is hit | A shift supervisor who keeps asking "what's next?" |
| Tools | Functions the model may request, such as reading a file, running a command or searching | The equipment in the workshop |
| Memory | What carries over between steps and sessions: the conversation so far, plus notes and files | The logbook left for the next shift |
| Permissions | Rules on which tools may run, where, and which need a person's approval | The keys a new employee is given, and the ones they aren't |
The loop is the heart of it. The README of OpenAI's Agents SDK describes the same cycle: call the model; if it produced a final answer, stop; if it asked for a tool, run the tool, add the result to the conversation and go around again; and stop anyway after a maximum number of turns.
A minimal harness, step by step
Here is a small harness in Python that shows all four parts. The call_model function stands in for whichever model API you use; it returns either a final answer or a request to use a tool. The rest is real, runnable logic.
import json, subprocess, pathlib
WORKDIR = pathlib.Path("project").resolve()
NOTES = WORKDIR / "PROGRESS.md" # memory that survives between sessions
MAX_TURNS = 30 # loop limit
ALLOWED_COMMANDS = {"pytest", "ls"} # permission: commands it may run
def read_file(path):
p = (WORKDIR / path).resolve()
if WORKDIR not in p.parents: # permission: stay inside the project
return "Refused: outside the project folder."
return p.read_text()[:20000]
def run(command):
if command.split()[0] not in ALLOWED_COMMANDS:
return f"Refused: '{command}' needs a person's approval."
out = subprocess.run(command.split(), cwd=WORKDIR,
capture_output=True, text=True, timeout=120)
return (out.stdout + out.stderr)[-5000:]
TOOLS = {"read_file": read_file, "run": run}
def agent(task):
notes = NOTES.read_text() if NOTES.exists() else "No notes yet."
messages = [{"role": "user",
"content": f"{task}\n\nNotes from earlier sessions:\n{notes}"}]
for turn in range(MAX_TURNS):
reply = call_model(messages, tools=list(TOOLS)) # the model decides
if reply["type"] == "final":
NOTES.write_text(notes + "\n" + reply["summary"]) # update memory
return reply["text"]
result = TOOLS[reply["tool"]](**reply["args"]) # the harness acts
print(f"turn {turn}: {reply['tool']} {json.dumps(reply['args'])}") # log
messages.append({"role": "tool", "content": result})
return "Stopped: turn limit reached."
Read it from the bottom up. The for loop is the loop, with a hard cap. TOOLS is the list of things the model may ask for. PROGRESS.md is the memory a new session reads first. The checks inside read_file and run are the permissions: the model can ask to run any command, but the harness decides whether it happens. The print line gives you a log of every action.
Try it: Draw your own agent idea as four boxes labeled loop, tools, memory and permissions. For each box, write one sentence answering "what happens if this part is missing?" The answers show you where your safeguards belong.
Where good harnesses earn their keep
The simple version above works for short jobs. Longer ones expose harder problems, and much of the recent engineering effort goes into them.
Memory across sessions. A model can hold only so much text at once, its context window. Anthropic found that agents working across many sessions either tried to do everything at once and ran out of room, or looked at partial work and declared the job finished. Their harness had the first session write a feature list with every item marked failing, a progress log and a first saved version of the project; later sessions read those first and worked on one feature at a time.
Checking the work. Agents asked to grade their own output tend to approve of it. A later Anthropic experiment split the job between a planner, a builder and a separate, deliberately skeptical evaluator, and found that easier to tune than asking one agent to criticize itself.
Context management. A harness can compact a long conversation, summarizing older parts in place, or reset it: start a fresh session with a written handoff. Each has trade-offs in cost and continuity, and choosing between them is a harness decision, not a model one.
Do you need to build your own?
Usually not. If you want an agent to work on code or files, existing harnesses such as Claude Code, Codex and the ChatGPT desktop app already provide the loop, tools, memory features and permission settings, tested across many users. Your effort is better spent on the instructions, the project notes and the permission choices you give them.
If you are building an agent into your own product, start from a framework instead of a blank file. The OpenAI Agents SDK and the Claude Agent SDK each run the loop and the tool calls for you, and leave you to define tools and rules.
Writing a small harness yourself is still worth doing once, the way it is worth changing a tire once even if you usually call for help. You learn exactly where the model's judgment ends and your code's responsibility begins, and that makes every ready-made agent easier to set up safely.
Sources
- Effective harnesses for long-running agents — Anthropic, November 26, 2025
- OpenAI Agents SDK (README) — OpenAI (GitHub), March 21, 2025
- Harness design for long-running application development — Anthropic, March 24, 2026
Sources for the articles linked in the text
Each linked article has its own page, with its sources and its date.
- What is Claude, Anthropic's new AI assistant?
- Introducing Claude — Anthropic, March 14, 2023
- Google-backed Anthropic launches Claude, an AI chatbot that's easier to talk to — The Verge, March 14, 2023
- Constitutional AI: Harmlessness from AI Feedback — arXiv (Anthropic), December 15, 2022
- What are OpenAI's Responses API and Agents SDK, and how do they help build AI agents?
- New tools for building agents — OpenAI, March 11, 2025
- OpenAI launches new tools to help businesses build AI agents — TechCrunch, March 11, 2025
- What are Claude 3.7 Sonnet and Claude Code, and what can they do?
- Claude 3.7 Sonnet and Claude Code — Anthropic, February 24, 2025
- Anthropic launches a new AI model that 'thinks' as long as you want — TechCrunch, February 24, 2025
- What is ChatGPT, and how is it different from a search engine?
- ChatGPT: Optimizing Language Models for Dialogue — OpenAI, November 30, 2022
- OpenAI’s new chatbot can explain code and write sitcom scripts but is still easily tricked — The Verge, December 1, 2022
From the Guide to Artificial Intelligence, by Robert Scales, published by Holistic Hybrid Inc. Share and adapt it under CC BY-NC-SA 4.0: credit the guide, link to https://guidetoartificialintelligence.com/en/learn/agent-harness/, no commercial use without permission, and keep the same licence.