# Agent Harness

> The Agent Harness is the software around an AI model that turns it into an agent: the loop, tools, context management and permissions.

## What is an agent harness?

The software layer around a model that runs the agentic loop, provides tools like file editing and terminal, manages context and memory, asks for permissions and shows progress. The same model can perform very differently in different harnesses.

- Topic: Agentic Coding
- Type: concept

## Example

Wrong:

```js
while (true) {
  const reply = await model(messages);
  const result = await runTool(reply.toolCall);
  messages.push(reply, { role: 'user', content: result });
}
```

Right:

```js
for (let step = 0; step < MAX_STEPS; step++) {
  const reply = await model(messages);
  if (!reply.toolCall) return reply;
  const result = await runTool(reply.toolCall).catch((e) => ({ error: e.message }));
  messages.push(reply, { role: 'tool', id: reply.toolCall.id, content: result });
}
```

The loop stops on a final answer or a step limit, and errors go back to the model as tool results.

## Key points

- The loop has a stop condition, such as a maximum number of steps or a token budget.
- Tool results are returned to the model as tool result messages, including errors.
- Risky tools are gated by permission checks in the harness, not only by instructions in the prompt.

## Interview questions

### Agent harness vs agent framework: what is the difference?

A framework is a library for building agents. A harness is the complete runtime around a model, often built with a framework, that runs a specific agent.

### Why does the same model perform differently in different agents?

The harness decides the tools, prompts, context management and retries the model works with, which strongly affects results.

### What does an agent harness include?

The agent loop, tool definitions and execution, context and memory management, permission checks, and a way to show progress to the user.

## Related cards

- [AI Agent](https://wonderium.dev/ai/ai-agent.md)
- [Coding Agent](https://wonderium.dev/ai/coding-agent.md)
- [Tool Calling](https://wonderium.dev/ai/tool-calling.md)
- [Context Engineering](https://wonderium.dev/ai/context-engineering.md)
- [Agent Permissions](https://wonderium.dev/ai/agent-permissions.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/agent-harness
- Last updated: 2026-11-25
