Skip to content
NEWBudgetBench: memory strategy evaluation under a fixed token budget (arXiv:2609.13149) →
Aditya Karnam
Chapter 5 of 7 · Agents · 35 min

Agents and harnesses

An agent is a loop around a model. Learn the harness: tools, permissions, context, and what makes one auditable.

You will learn

By the end of this chapter

  • Draw the agent loop and name its parts
  • Explain approval gating, session persistence and tool design
  • See how a minimal harness (Quecto) is put together
5.1

A model is not an agent

A language model takes text in and gives text out. It cannot read your files, run a command or remember yesterday. If you ask it to fix a failing test, it can only write what it thinks the fix looks like.

An agent is a model placed inside a loop that lets it act. The loop sends the model some context, takes the tool call it asks for, runs that call, and feeds the result back. It repeats until the model answers without asking for another tool. Everything around the model that makes this work is called the harness.

Aditya's guide What Is an AI Agent Harness? defines it as the software layer that surrounds a model and manages its interaction with tools, memory, files, environments, users and evaluators. It makes a strong claim: two systems using the same model can behave very differently, because the harness controls what the model sees, what it can do, how failures are handled and when execution stops.

5.2

The loop, one step at a time

Below is one pass through the loop for a coding task. Press Step and watch two things: the highlighted part of the loop, and the context window at the bottom, which is the only thing the model ever sees. When the loop reaches the gate for a file edit, you decide whether it is allowed.

The agent loopMODELGATETOOLCONTEXTrepeat until no tool call
Context window (2 messages)
systeminstructions
usermake the failing test pass

The loop starts with a context: the instructions and your task. The model only ever sees this list.

Schematic, not to scale
Interactive: the agent loop with a permission gate. Try both Approve and Deny, then Reset.

Three things are worth noticing. First, the model never runs anything. It writes a request, and the harness executes it. Second, a denied call is not silent: the refusal goes into the context as a tool result, so the model can react. Third, the loop ends when the model replies with no tool call. Quecto, covered in 5.5, also enforces a max_steps limit so a confused model cannot loop forever.

A term you will see again: a tool is a function the harness exposes to the model, described by a name, a description and a schema for its arguments. The Quecto write-up lists its tool shape as Tool { name, description, schema, run }, with built-in tools and MCP tools sharing one dispatch surface.

What if the model is wrong? The guide describes a verification step that checks the result against success criteria, and a recovery step that retries or replans when the check fails. A failed check loops back into reasoning before the harness returns a final result. This is why a harness can be better than its model: it does not have to trust the first answer.

5.3

Anatomy of a harness

The same guide splits every harness into eight components. Click each one in the diagram below. The descriptions are the ones from the guide, and the notes connect them to Quecto where the sources do.

Tool layer

Schemas, permissions, execution and error responses. Models propose actions here; the harness decides which reach the machine.

Interactive: the eight components of an agent harness. Click a part to read what it does.

The guide's main point about this list is that swapping any one component gives you a different agent, even with the same model underneath. It also contrasts a minimal harness with a research-grade one. A minimal harness sends a prompt, exposes tools and stops when the model responds. A research-grade harness versions the whole execution contract, records every tool request and response, uses explicit completion criteria and classifies failure modes. Most demos live in the first column; most production systems need the second.

5.4

Context is a budget

Every turn of the loop adds to the context: the model's message, then the tool result. Files and command output can be long. A model has a limit on how much context fits in one call, so the context manager has to decide what stays. That decision is part of the harness, not the model.

Context window fillSYSWINDOW LIMIT
2 of 16 units used, 0 turns

Only the instructions are in the window. Add turns, as an agent would while it works.

Window
Policy
Schematic, not to scale
Interactive: add turns and watch the window fill. Units are abstract. Try the same turns with Drop oldest and Keep all.

Dropping the oldest turns is the simplest policy, and the diagram shows its cost: whatever was in those turns is gone. Better policies retrieve or summarize instead, which is what Chapter 4 covered and what Chapter 6 measures. The BudgetBench write-up makes the same point in a sentence: budget is part of the agent harness, the same way the tool set and the verification loop are. It also separates three numbers that are often blurred: the advertised context window, the total tokens spent across a task, and the active budget, which is how many input tokens one call is allowed to see.

5.5

Quecto: a minimal harness you can read

Aditya built Quecto to study agent behavior as a system. It has two layers. The core is a model transport: it sends a prompt to any OpenAI-compatible endpoint, local or cloud, and returns the answer. The agent adds the pieces that involve policy. Switch between the two below.

Quecto binary sizesCORE~1.3 MBAGENT~5.5 MB
What is inside
  • Send a prompt to an OpenAI-compatible endpoint
  • Return the response, buffered or streamed
  • Two direct dependencies: ureq and serde_json
  • No async runtime

Model transport only. If something goes wrong here, there is very little code to blame.

Interactive: the two Quecto layers and what each contains. Sizes are the size-optimized builds listed on the Quecto page.

The design rule, from Building Quecto, was to describe the full harness first and then ask which responsibilities must live in the smallest core. The answer was exactly one: model transport. Everything else was assigned a home in the agent crate.

Four of the agent's design choices are worth learning by name.

  • Approval gating. The policy layer returns allow, ask or deny. Edits and commands go through a configurable approval preset before anything touches disk, and dangerous commands are denied even under permissive approval.
  • Sandbox. A separate layer enforces the repository directory, a command denylist, a timeout, output caps and redaction.
  • Session persistence. Messages and file changes are stored in SQLite, so chat, resume, diff and undo are runtime features and not terminal scrollback.
  • Verification as a stop condition. A configured check, not the model's own confidence, decides whether an edit counts.

Two more details show how policy shows up in small places. File edits use exact search and replace blocks. An edit that matches more than one place is rejected, and the prior content is recorded, so every change can be replayed and undone instead of being a vague rewrite of a file. Project-local flavor files, which can declare commands and loosen approvals, use trust on first use: the project has to be trusted before its settings apply. In both cases the model can propose, but a rule outside the model decides.

The same post describes subagents, which are agents started by another agent. A background subagent returns an id, a read-only monitor reports status and recent activity, and cancellation is explicit. Its stated reason: concurrency is only useful if the supervisor can still tell what is happening.

There is also a book. Building a Coding Agent Harness, by Aditya Karnam and Arjun Jaggi, is a free 75-page guide that builds a compact Rust core: an OpenAI-compatible transport, a bounded tool-calling loop, typed tools, repository path checks and execution policy. The announcement, I Wrote the Practical Systems Guide I Wanted, is careful to say that the teaching crate is a library component, not a finished terminal product, and that later chapters on sessions and MCP are design studies mapped to Quecto's source.

5.6

Plugins and MCP: how tools get shared

Hand-writing every tool does not scale, so there are shared formats for adding tools to an agent. MCP, the Model Context Protocol, is a way for a client to call tools on a server. Aditya's site runs one: the post I Turned My Portfolio Into an MCP Server describes a public, read-only endpoint that exposes seven tools, such as get_profile, list_projects and search_work. It also records two real bugs from hardening it: rate-limit writes that silently did nothing, and a missing inputSchema field that the MCP spec requires.

Agent Plugins v1.0.0 is the packaging side. Its portable core is small: a plugin is a directory with a required plugin.json, an optional skills/ directory and an optional mcp.json. The post notes that v1 defines no trust model, permission declarations or sandboxing, and calls that a real gap.

5.7

Try it yourself

The portfolio server post gives one command to connect it to Claude Code. This gives you an agent calling a tool server, so you can watch the loop from 5.2 in practice:

claude mcp add --transport http aditya-portfolio https://adityakarnam.com/mcp

Then ask a normal question such as "tell me about quecto". The post shows Claude choosing to call get_project on its own. Notice where it asks for permission.

Conceptual exercise: pick a task you would give a coding agent. Write down which tools it needs, then label each tool call allow, ask or deny, and say why. Finally, decide what check would tell the harness the task is finished. If you cannot name that check, the harness has no completion criterion yet.

Check yourself

Can you answer these?

Q1In the agent loop, who actually runs a tool call, the model or the harness?
The harness. The model only writes the request. The gate decides whether the call is allowed and the tool then runs it.
Q2What happens to the loop when you deny a tool call?
The denial is added to the context as a tool result, so the model can see it and respond. The action does not run, but the loop continues until the model answers without a tool call.
Q3Why is the context a budget, and what does a simple drop-oldest policy cost?
A call can only hold so much context, so the harness has to choose what stays. Dropping the oldest turns keeps the window within its limit but removes whatever those turns contained.
Q4What did Quecto's design keep in the core, and why?
Only model transport. Policy-heavy pieces such as the tool loop, approval, sandbox and sessions live in the agent layer, so the core stays small and has fewer places to hide behavior.
Go deeper

The original work behind this chapter

← RetrievalNext: Evals →
© 2026 Aditya Karnam