02 Building the agentLesson 3 of 812 minIntermediateHelps to have seen:Tools and the loop
The harness: the code around the model
- + the agent from Tools and the loop
The diagram shows: Customer (waiting in the chat), Harness (the code that runs the loop), Model API (can go down or be slow) and tools (look up, refund).
Highlighted: Harness.
Customer sends to Harness carrying "where is 4821?".
Harness sends to Model API.
Model API sends to Harness.
Harness sends to tools.
tools sends to Harness carrying "6 days late".
Harness sends to Customer carrying "the answer".
Added: the agent from Tools and the loop.
Step 1 of 9: It worked on the laptop
- What the harness is and what it decides
- Which piece catches each failure
- When to retry a call, and when not to
- Why caps, timeouts and state live in the code
Conversations that end with an answer or a handoff, with no repeated action, with failures injected in the API and the tools
Coming soon: I will measure this on the example agent and publish the number with the report.
The whole lesson as textEvery step, to read at once, search or print.
It worked on the laptop
In the earlier lessons the agent worked: it asked for the tool, got the data, answered. That is the happy path.
In the real chat, the model API goes down, the tool is slow, the model asks for the same thing again, and there is a customer waiting on the other side. Who takes care of that?
An agent that works once is not ready for the customer yet.
The code around the model
The is all the code around the model. It builds the context, calls the API, runs the tools, counts the turns, keeps time, saves the state and decides what the customer sees.
The model decides the next step. The harness decides what happens when something goes wrong, and something always does.
The model chooses. The harness guarantees.
Break the agent on purpose
Each of these failures happens every day in an agent in production. None of them depends on whether the model is good or bad.
Notice who solves each one: it is never the model. It is a piece of code, with a simple rule, that exists before the failure happens.
For each failure, a piece of code that was already there.
Retry, carefully
An overload or network error usually goes away on its own: it is worth waiting and trying again, waiting longer each time, up to a limit. The Anthropic SDK already does this twice by default.
An error that does not go away, like "order 4999 does not exist", is not retried: it goes back to the model as a result, with what to do. And a tool that changes something is only retried with the unique key from the Tools and the loop lesson.
Retry what is passing. Give the model back what is not.
Turn cap and timeout
The cap counts the loop turns; the timeout counts the seconds of each call and of the whole conversation. Both live in the code, because the model does not know how many turns it took or how long the customer waited.
Hitting a limit is not an error: it is the moment to tell the customer and hand off the case, with what was already done.
A limit the model cannot see has to be in the code.
State, and what the customer sees
The state keeps the conversation, the calls made and what changed in the world, like the refund created. If something goes down halfway, the harness resumes from there, without repeating.
And the customer is never left in the dark: while the agent works, the harness shows what is going on. "Checking your order" is worth more than ten seconds of silence.
Save what changed in the world. Show what is going on.
It went down after the refund
The most expensive failure is not the one that stops everything. It is the one that happens halfway: the world has already changed and the conversation does not know.
Without state, the customer gets no answer or gets two. With state and a unique key, resuming is safe.
A failure halfway is the most expensive. State and a unique key make resuming safe.
Whoever builds agents builds the environment
In February 2026, OpenAI described how three engineers guided agents that wrote about a million lines and 1,500 PRs in five months, with no code written by hand. The title of the post is "Harness engineering".
Our reading: their work became building the environment around the agent, with rules in linters and tests and verification loops. It is the harness, at scale.
The more the agent does, the more the work becomes the harness.
What to take from this lesson
The model decides the next step. The harness takes care of everything that can go wrong around it.
Questions in this lesson
- The tool returns "order 4999 does not exist". Should the harness retry the call?
- No, give it back to the model so it asks for the right number. Retrying only helps with a passing error. A data error goes back as a result.
- Where does the loop's turn limit go?
- In the harness code. The model does not reliably count turns. The code counts and stops.
- The conversation goes down after the refund is created. What prevents a duplicate refund?
- Saved state and a unique key. The state says what was already done, and the unique key stops the tool from repeating.
- OpenAI, Harness engineering: leveraging Codex in an agent-first world (Feb 2026) ↗
- Anthropic, Effective harnesses for long-running agents (Nov 2025) ↗
- Anthropic, Building effective agents (Dec 2024) ↗
- Claude Docs, Errors ↗
- Claude Docs, Python SDK ↗
- Amazon Builders’ Library, Timeouts, retries and backoff with jitter ↗
- Temporal, AI agents ↗
- LangGraph, Persistence ↗