1/17
Part 1 of 7 · The loopLearn

Agent harness

Anthropic ML engineer candidates report a tooling scenario in which the model plans and then calls a tool (1 report). In an OpenAI round billed as system design, the questions turned to an agent harness and its evals (1 report). It starts like this:

An agent is a model that calls tools in a loop. The model only writes text. Your code runs the tools.

Write run_agent(model, tools, task, max_steps=10). The transcript starts with the user's task. Each step calls model(transcript), which returns {"answer": text} or {"tool": name, "args": {...}}. For a tool call, run tools[name](**args), and add the call and its result to the transcript. Stop on an answer, or after max_steps model calls. Return a dict with the answer, why it stopped ("answer" or "max_steps"), and the transcript.

For the task "Can I return order A17?":

  1. The model asks for look_up_order with the args {"order_id": "A17"}. The loop runs it, and adds the call and its result, "A17: 2-person tent, delivered Nov 10, $189.00, unused".
  2. The model returns {"answer": "A17 can be returned."}. The loop adds the answer and stops.

So run_agent returns the answer "A17 can be returned.", stopped set to "answer", and a transcript of 4 messages. With max_steps=1, the model never gets its second turn: the answer is None, stopped is "max_steps", and the transcript holds 3 messages.

Then the levels come. Errors go back to the model as results, not crashes: a tool that doesn't exist, a tool that raises, arguments that don't fit the tool's schema. Then a person approves risky calls, and a run that makes the same call three times in a row stops as a loop. The follow-ups ask about budgets, a refund that must never run twice, and how you grade an agent.

You don't write it yet. This lesson builds each piece first on one example, a shop's returns agent: the loop, tool definitions, errors and limits, a person for risky calls, and grading. At the end you solve the whole problem, level by level, in an interview simulation with a 45-minute timer.

This is the newest kind of coding round: a loop around a model. Hold on to one idea from the start. The loop is plain code that owns every decision, and the model only suggests the next call.