---
title: "Chapter 07: The Harness"
description: "Two hundred lines, one tool. Build the smallest possible agent loop and understand why behavior — not knowledge — is what you're training."
type: lesson
order: 7
chapter: "03-trajectories"
---

# Chapter 07: The Harness

## Objective

Build the smallest possible agent harness, instrument it to record everything, and fine-tune the 1B model until it emits **syntactically valid tool calls**. Not smart ones. Valid ones.

## The Insight This Part Exists For

You are not fine-tuning the model on your code. **You are fine-tuning it on the shape of agentic behavior.**

Codebase knowledge belongs in context, retrieved at runtime — bake it into weights and you retrain every time the code changes, and it hallucinates moved APIs anyway. What small models are actually bad at, and what *is* stably trainable, is the loop: take a task, emit a well-formed tool call, read the result, reason, call again, stop when done, report.

That behavior is learnable. That behavior is what we train.

## The Harness

Two hundred lines. One tool.

```
read_file(path) -> string
```

The loop:

1. System prompt describing the tool and the output protocol
2. User task
3. Model emits a tool call
4. Harness parses, executes, appends result
5. Repeat until the model emits a final answer or hits a step cap

Point it at the endpoint you stood up in [Chapter 06](/fine-tune-local-agent/02-the-pipeline/06-serve-and-automate/) — anything speaking the OpenAI chat-completions API works, which is exactly why we built it that way.

## Picking a Tool-Call Protocol

Use whatever protocol you like — a JSON block, an XML tag. Small models do better with simple, unambiguous delimiters than with elaborate schemas. You control the protocol; pick one you can parse with a regex and validate with a schema.

One rule that will save you later: **the system prompt must be identical between training and inference.** A mismatch here silently destroys everything downstream.

---

[← Part 3 Index](/fine-tune-local-agent/03-trajectories/) · [Next: Chapter 08 →](/fine-tune-local-agent/03-trajectories/08-the-logger/)
