An agent harness is the software around an AI model that runs the conversation loop, executes tools, manages context, and enforces permissions and limits. When you ask a coding agent to fix a bug, the harness supplies the files and test results the model needs, then executes the actions it requests.
The tools and context a harness gives the model affect what the agent can do and how much a session costs. A harness that sends dozens of tool definitions on every call can use more input tokens than one that loads tools only when needed, even when both use the same model.
Tl;dr
- The harness checks the actions the model requests, executes permitted ones, and returns their results so the model can decide what to do next.
- Two harnesses using the same model can give it different parts of the conversation history and stop it at different points in the task.
- In our small test, adding 40 unused tools increased Haiku’s median session cost from $0.00082 to $0.00277 without caching. With caching enabled, the 44-tool configuration had a median cost of $0.00071.
- Use Ori Harness to connect an existing agent to OpenRouter, or our Agent SDK and cookbooks to build your own.
What is an agent harness?
An AI agent harness connects a model API to an execution environment, such as your repository, shell, and external services. Claude Code, Codex, and Hermes Agent are examples.
In a text-and-tool workflow, the model receives messages and descriptions of the tools available to it. To request an action, it returns the tool’s name and arguments in a structured response. For example, a request to run tests names the test tool and supplies any inputs that tool requires.
This excerpt from our October bug-fixing run shows Claude Haiku 5.5 requesting two tools through Chat Completions:
In this response, the model asks to run the tests and list the project’s files. The harness checks that both tool calls are valid and allowed, then executes them and sends their results back to the model. The model can use those results to decide which file to inspect or what to fix next.
The parts of an agent harness
1. The agent loop
The loop builds a model request, processes the reply, executes permitted tools, and continues until a stopping condition applies. Claude Code describes its loop as gathering context, taking action, and verifying results. The harness determines how that process continues after an error or an incomplete attempt.
2. Tools
Tool definitions describe available actions and their arguments. Loading every definition increases the input sent to the model. Claude Code defers MCP tool definitions and discovers them through tool search, loading fuller definitions when needed. A harness can send the full tool catalog on each call, select a smaller set for the task, or let the model discover additional tools when needed.
3. Context
The harness chooses which instructions, messages, and tool results reach the next model call. Sending every earlier message and tool result lets the model refer to those details, but leaves less room for new information. Trimming old results or summarizing earlier messages frees space, though the model may then lose a detail it needs for the next step. Claude Code compacts long conversations; persistent project rules belong in CLAUDE.md rather than depending on early messages surviving a summary.
4. Permissions
Permission checks decide whether an action may proceed. A sandbox limits what the executing process can access. Codex separates these controls, so you can configure approval policy and filesystem or network boundaries independently. Telling the model in a prompt to avoid sensitive files relies on it following that instruction. A sandbox configured to deny access to those files prevents the tools running inside it from reading them.
5. Limits and stopping
A harness can stop on completion, a turn or spending limit, elapsed time, or repeated unproductive actions. The timing of a limit check affects what it can prevent. If the harness checks spending only after a model call finishes, that call may have already put the total over budget.
6. Sessions
A harness can save a session’s messages, tool results, and relevant approval state. When work resumes, it reloads the saved record and includes relevant history in subsequent model requests. Which approvals remain valid depends on the harness’s policy. For example, a resumed session’s saved history may show that a tool changed a database record. That history does not reverse the change, so restoring the record requires a separate action.
How one turn of the loop works
When the model requests a file edit, the harness checks the request against its permissions, runs the edit if allowed, and records the result. Its stopping rules then determine whether the model can continue working.
- Build the request. Assemble instructions, available tools, and retained conversation history.
- Call the model. Inspect its response and completion status. A normal answer can finish the task; an error or truncated response needs separate handling.
- Validate and authorize tool calls. Check the tool name, arguments, and permissions. A denied call does not run.
- Execute permitted actions. Return results or actionable errors to the conversation. Run dependent actions in order; parallel execution suits independent calls.
- Check progress and limits. Stop when required, or prepare the next request with the updated context.
As the loop continues, each tool result adds information for the model to consider. To keep later requests within the model’s context limit, the harness may shorten long outputs or summarize older messages, trying to retain the details needed for the unfinished task.
We used a minimal harness we built against the OpenRouter API to test whether the agent could fix two bugs in a shopping-cart calculation. The subtotal ignored each item’s quantity, and the discount applied only above 100 when it should also apply at exactly 100.
Across four model calls, Haiku requested test results and file information, read the affected file, requested edits and another test run, then returned its final answer. The harness executed those tool requests and passed the results back to Haiku after each call.
Developers can build this loop themselves or use a framework or SDK to handle model calls, tool execution, and conversation history. They then configure the tools, permissions, and limits that make up their harness.
Harness vs framework vs SDK
Our Agent SDK provides callModel to call the model, execute tools, and track the conversation. You build a harness around those functions by choosing its tools, permissions, and limits.
Does the harness change what a model costs?
The harness controls how much input it sends, how often it calls the model, and how it configures caching. Session records show what users spent with each harness across different tasks. A controlled test keeps the task fixed while changing a setting, such as the number of tool definitions, to examine how that setting affects cost.
Session costs across harnesses
Our October session-cost snapshot reports these median session charges in USD for the 30 days ending October 18, 2026. Different harnesses serve different users and tasks, so these are not controlled comparisons.
For Opus, the 2–9-turn median was 2.7 times higher in Codex than Hermes. That difference does not isolate harness overhead. Sessions in the same turn band can still contain different tasks and input lengths. To examine a specific mechanism, we changed the tools sent for the same task.
Controlled test of tools and caching
We ran the two-bug task five times for each of six configurations, resetting the project between runs. All 30 runs fixed both bugs. Four configurations used Haiku with 4 or 44 tools and caching on or off; two used GPT-6 Luna with automatic caching. The extra 40 tools were unused synthetic definitions.
The per-turn measurements used three runs for each tool count, while the configuration table below reports results from five runs per setup. The chart shows 636 versus 5,396 input tokens on turn one, a difference of 4,760. Later differences stay close to that amount as tool results add history.
Without caching, Haiku’s 44-tool session cost about 3.4 times the four-tool version. Enabling caching reduced its median to $0.00071. Luna’s reported costs were close despite the larger tool catalog, with substantial cache reuse in the 44-tool configuration.
In a separate budget-stop test, a $0.001 limit stopped the 44-tool run after turn two at $0.00119, while tests still failed. The post-call check detected the overshoot rather than preventing it.
When comparing session costs, check whether each configuration completed the task. To understand the charges, look at how many input tokens the harness sent and how many tokens the provider read from or wrote to the cache. Prompt caching depends on the model, provider, prefix, and cache lifetime. A larger prompt can cost less with reuse, but this experiment does not establish that unused tools improve efficiency.
Which CLI agent harnesses account for the most tokens on OpenRouter?
Our September 22–October 21, 2026 snapshot placed Hermes Agent, Claude Code, and Kilo Code first by CLI-agent token volume, at 53.1T, 39.2T, and 26.0T tokens, respectively. Cline, pi, and Codex also appeared in the top ten.
Token volume describes usage through OpenRouter, not task quality or total market share. See the CLI-agent rankings for the current view. With Ori Harness, a supported coding agent can manage your files and tools while sending model requests through OpenRouter.
Where OpenRouter fits in a harness
The harness manages its local loop, tools, permissions, and sessions. We route the harness’s model requests to providers through one API.
Ori Harness configures supported agent CLIs to use OpenRouter with OAuth sign-in and model selection. You keep using the same agent, but the selected model must support the features that the agent needs, such as tool calling, for the workflow to function.
On the request side, we provide:
- Model fallbacks and Auto Exacto for model availability and tool-calling provider selection.
- Prompt caching with sticky routing to improve reuse. Provider changes, including Auto Exacto reordering, can still cause misses.
- Server tools, including search, subagent delegation, and advisor calls, subject to API support and configuration.
- Guardrails for assigned spending and access policies, plus Broadcast for exporting configured request traces.
Our October Chat Completions Tool Search request returned HTTP 400. Current Tool Search documentation distinguishes the Responses/Messages server-tool format from the Chat Completions deferred-tools protocol. Before enabling Tool Search, identify whether your harness sends requests through Chat Completions, Responses, or Messages, then use the request format documented for that API.
When building a custom agent, you still need to decide which tools it can run, when it must ask for approval, and what information it carries between calls. Our Agent SDK provides the loop and tool-handling functions you can configure around those decisions.
Building your own harness
Start with the tools needed for one task, then check that the agent completes it correctly while respecting its approval rules and spending limits.
Frequently asked questions
What is a harness in machine learning?
A harness is surrounding software used to run or evaluate a system. An agent harness specifically manages model calls, tools, context, and execution controls. The term can also refer to a testing setup; Harness is separately the name of a CI/CD company.
What is harness engineering?
Harness engineering means improving an agent through its instructions, tools, context handling, execution controls, and feedback loop. These changes affect how a model performs tasks without changing its trained weights.
Is Claude Code a harness?
Yes. Claude Code supplies tools, manages the context sent to the model, and runs the process of gathering information, taking action, and checking results.
Do I need a harness to use tools?
You need software to execute tool requests and return their results. An SDK or hosted service can supply that execution layer. You do not need to build a complete custom harness for a single tool interaction.
Next steps
Install Ori Harness to connect a supported agent to OpenRouter. For a custom workflow, start with the headless-agent recipe, then add context management, approval rules, and limits around the tasks you need it to complete.










