Steel Town AIFree resources

Guide · Updated October 2026

How to build an agent harness

An agent is a model plus the code around it: the loop, the tools, the memory, the permissions and the checks. That code is the harness. Most agent failures come from the harness, not the model.

First, use one before you build one

Building a harness from scratch is rarely the right first move. These already handle the loop, tools and sessions, so you can spend your time on the tools and tests that are specific to your business:

Build your own when you need full control of the loop, run fully on-prem, or have requirements none of these meet.

The seven parts of a working harness

1. The loop, with stop conditions

The model picks an action, the harness runs it, the result goes back to the model, and the cycle repeats. Every loop needs three exits: the task is done (checked by code, not just claimed by the model), the step limit is hit, or the budget runs out. A loop without exits is how a $5 task becomes a $50 one.

2. Tools: few, narrow and typed

Give the agent the smallest set of tools that does the job, each with a plain-English description, typed inputs and short outputs. MCP (Model Context Protocol) is the standard way to package tools so any agent can use them. A tool that returns a whole database table wastes context; return only the fields the next step needs.

3. Context: short instructions, retrieval for the rest

Standing instructions are paid for on every call. Keep them to what the agent must always know, and fetch reference material when it's needed. A shared, plain-file memory (an AGENTS.md or CLAUDE.md entry file pointing to project notes) gives every tool and every session the same starting point.

4. Permissions: read-only by default

Start every agent read-only. Writes, deletes, payments and outbound messages need an explicit approval step or a narrow allow-list. Run code in a sandbox. Credentials come from the environment, never from the model's output.

5. Budgets and model routing

Staff the agent like a crew: the strongest model plans and makes hard calls, a mid-tier model does most steps, and a small model handles high-volume sorting and checks. Escalate to a bigger model only when a check fails. Put a budget on each agent and each run.

6. Logs and traces

Record every model call and tool call with its input, output, cost and time. When something goes wrong, the trace is the only way to see why. Open-source tracing tools such as Langfuse do this without a vendor contract.

7. Evals: a test set that runs on every change

Collect 20 to 50 real tasks with known good outcomes, and run them whenever you change a prompt, a tool or a model. promptfoo and similar tools run these in CI. Without a test set, every change is a guess.

Build order

  1. Write the test set first: 20 to 50 real tasks with known good outcomes.
  2. Start read-only with one or two tools, and log everything from day one.
  3. Add stop conditions: a done check, a step limit and a budget.
  4. Run the tests on the cheapest model that might work, and escalate only where it fails.
  5. Add write tools one at a time, each behind an approval step.
  6. Re-run the tests on every change to a prompt, tool or model.

What usually breaks