License YOLO
Back to Ultralytics Glossary

Agent Harness

An agent harness is the code around a model that makes it an AI agent: the loop, tools, context, memory, permissions, and checks that run its actions.

An agent harness is all the software around a model that turns it into an AI agent: the loop that calls the model, the tools it may use and the code that executes them, the context it sees on each turn, its memory, its permissions, and the rules for when to stop. A large language model (LLM) on its own only maps text to text. The harness reads that text, decides whether a requested action may run, runs it, and feeds the result back. LangChain sums the split up as "Agent = Model + Harness", meaning every prompt, tool, hook, and line of orchestration code that is not the model belongs to the harness. Coding agents such as Claude Code, Codex CLI, and Cursor's agent mode are harnesses, and several of them run the same underlying models.

What a Harness Does#

  • Agent loop: Calls the model, parses its reply into a final answer or a tool call, executes the call, and repeats until the task is done or a step, time, or token budget runs out.
  • Context engineering: Assembles the system prompt, task, tool descriptions, prior results, and loaded agent skills into each request, and compacts old turns before the context window fills.
  • Tools: Describes each tool to the model with a name, a purpose, and a JSON schema, then runs the calls the model emits, including tools served over the Model Context Protocol (MCP).
  • Memory: Keeps plans, progress notes, and files outside the context window so long tasks can continue across sessions.
  • Permissions: Allows routine actions, asks a person before irreversible ones, and runs commands inside an agent sandbox.
  • Hooks and verification: Runs deterministic checks, such as linters, tests, or structured output validation, before results are accepted or the agent is allowed to finish.
  • Observability: Records a trace of every model call, tool call, and decision for debugging and agent evaluation.

Each pass through the loop combines these duties:

flowchart TD
    A["Task from the user"] --> B["Harness assembles context"]
    B --> C["Model replies"]
    C --> D{"Tool call or final answer?"}
    D -->|"Final answer"| E{"Checks pass?"}
    E -->|"Yes"| F["Return the result"]
    E -->|"No"| B
    D -->|"Tool call"| G{"Allowed without approval?"}
    G -->|"No"| H{"Person approves?"}
    H -->|"Yes"| I["Run the tool"]
    H -->|"No"| B
    G -->|"Yes"| I
    I --> B

Why the Harness Matters#

The harness often moves results as much as the model does. LangChain raised its deepagents-cli coding agent from 52.8% to 66.5% on the Terminal-Bench 2.0 benchmark by changing only the harness, its system prompt, tools, and middleware, while the model stayed fixed at GPT-5.2-Codex. Its most common failure was an agent that wrote a solution, re-read its own code, judged it correct, and stopped without testing it, so the new harness adds a middleware check that sends the agent back to verify its work against the task before it may finish. For the same reason, agent leaderboards report a score for each model and harness pair, and Anthropic's guide to building effective agents recommends simple, composable harness logic over elaborate frameworks, with complexity added only when it measurably helps.

  • Model: The foundation model and its weights. Swapping the model keeps the harness, and a strong model in a weak harness still fails long tasks.
  • Agent frameworks and SDKs: Libraries such as LangChain and the OpenAI Agents SDK supply loops, tool wrappers, and tracing as building blocks. A harness is the configured runtime one application builds from them.
  • AI agent orchestration: Coordinates several agents, each running in its own harness, and merges their results.
  • Evaluation harness: An older use of the word, as in test harness, for the infrastructure that runs benchmark tasks, records each attempt, and grades it.

A Tool Call Through the Harness#

The model's side of a tool call is only text. The harness parses it, checks it against policy, executes it, and appends the result to the conversation. Here the harness exposes Ultralytics YOLO26 object detection as a tool that returns Results.summary(), a list of each detected object's class name, confidence, and box coordinates:

import json

from ultralytics import YOLO

detector = YOLO("yolo26n.pt")
tools = {"detect_objects": lambda image_url: detector(image_url)[0].summary()}
auto_approved = {"detect_objects"}  # Any other tool waits for a person

# The model's turn ends with text naming a tool and its arguments
reply = '{"tool": "detect_objects", "arguments": {"image_url": "https://ultralytics.com/images/bus.jpg"}}'
call = json.loads(reply)

# The harness, not the model, checks permission and runs the tool
if call["tool"] in auto_approved:
    observation = tools[call["tool"]](**call["arguments"])
else:
    observation = {"error": f"{call['tool']} needs human approval"}

# The result goes back into the context for the model's next turn
messages = [{"role": "tool", "content": json.dumps(observation)}]
print(messages[0]["content"][:150])

The printed JSON is the observation the model reads on its next turn, the predict mode results serialized as text, beginning with the first detection's class name, class index, confidence, and box.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning