AI PM 10X / TECHNICAL FOUNDATIONS

Loops & Harnesses

The engineering scaffold that runs an AI model. The loop is how an agent acts and re-plans, the harness is the runtime around it, and most of an agent's reliability and safety live there rather than in the model.

Overview

A language model on its own can only read text and write text. To make it act, you wrap it in a loop. The model proposes an action, the surrounding code runs that action, the result comes back as an observation, and the model decides the next step. That cycle repeats until a stop condition is met. The code that runs this cycle is the harness, and the cycle itself is the agent loop. The AI Agents page covers what an agent is. This page is about the scaffold that makes one run.

For product managers, the harness is where the real product lives. It manages the context window, decides what the model sees each turn, dispatches tool calls, enforces permissions, handles retries, and sets the conditions that end the loop. The model is one component. Choosing or designing the harness is the decision that determines an agent's reliability, cost, and safety, and those are product decisions as much as engineering ones.

Why It Matters for PMs

Reliability lives in the harness

The model is one component. Most of what makes an agent dependable in production comes from the scaffold around it. Tool design, context limits, retries, and stop conditions are all harness decisions, and they are product decisions.

The loop is where cost accrues

Every turn of the loop sends the growing context back to the model and pays for it again. A loop that runs ten steps when three would do is slow and expensive. That is a harness problem, and it is yours to fix.

Control is always by design

A loop with no stop condition runs forever or until it breaks something. Where the loop ends, what needs human approval, and what the agent is allowed to touch are all things a PM specifies up front.

Key Concepts

Three ideas that make an agent run. The loop, the runtime around it, and the rules that end it safely

1

The agent loop

Propose · Act · Observe

An agent runs in a cycle. The model proposes an action, often a tool calltool callA structured request from the model to run a function the harness provides, such as searching a database or reading a file. The harness executes it and returns the result. Tool use is what lets a model act on the world rather than only generate text.Anthropic on tool use. The harness runs it and feeds the result back as an observationobservationThe result of an action returned to the model: the search hits, the file contents, the error message. The model reads the observation and decides what to do next. Reason, act, observe, repeat is the ReAct pattern.Prompting Guide: ReAct. The model then decides the next step. The cycle repeats until a stop condition is met.

2

The harness

Runtime · Scaffold

The harness is the runtime that runs the loop. It manages the context windowcontext windowThe fixed amount of text a model can read in one turn, measured in tokens. Everything the model knows about the task lives here: the instructions, the conversation so far, and every tool result. When it fills up, the harness has to decide what to keep.Anthropic on context windows, dispatches tool calls, enforces permissions, handles retries and errors, and decides what the model sees each turn. Claude Code and the Claude Agent SDKClaude Code and the Claude Agent SDKAnthropic's framework and tooling for building agents on Claude. It handles the loop, context management, tool dispatch, and permissions so you build on top rather than from scratch. Claude Code is built on it.Claude Agent SDK docs are harnesses. So are open frameworks. The harness is where you make most of your real reliability and safety decisions.

3

Stop conditions & control

Safe termination

A loop needs a way to end. That comes from a stop conditionstop conditionThe rule that ends the loop: a maximum number of steps, a success check that the goal is met, a budget cap, or an error threshold. Without one, the loop runs until it exhausts resources or causes harm. Setting it is a product decision.Anthropic: building effective agents such as a step limit, a success check, or a budget cap. For consequential actions you add a human approval stephuman approval stepA checkpoint where the agent pauses and a person approves or rejects before it proceeds, for example before sending an email or deleting data. It trades autonomy for safety on the actions that matter most.Human-in-the-loop. Together these decide how the loop ends and what it is allowed to do on the way.

Core building blocks to know

Hover over any term for a plain-English explanation and a link to go deeper.

The loop

How an agent runs its cycle

ReActReActThe reason-act-observe pattern. The model thinks, takes an action such as a tool call, reads the result, then thinks again. It is the backbone of most agent loops.Yao et al., 2022 (arXiv)Tool callTool callA structured request from the model to run a function the harness exposes, such as search, read a file, or query an API. The harness executes it and returns the result to the model.Anthropic on tool useObservationObservationThe result of an action fed back into the loop: data, file contents, or an error. The model reads it and decides the next step. The quality of observations shapes how well the loop converges.Prompting Guide: ReAct
Context management

What the model sees each turn

Context windowContext windowThe fixed budget of tokens the model can read in one turn. Instructions, history, and every tool result compete for the same space. Managing it is the harness's central job.Anthropic on context windowsCompactionCompactionSummarising or trimming earlier turns so the loop can keep running without overflowing the context window. The Claude Agent SDK does this so long-running agents do not lose the thread.Anthropic on the Agent SDKStateStateWhat the agent carries between steps: the goal, what it has tried, intermediate results. Twelve-factor agents argue you should own this state explicitly rather than leave it implicit in the model's context.12-factor agents
Control

How the loop ends safely

Stop conditionsStop conditionsThe rules that end the loop: a step limit, a success check, a budget cap, or an error threshold. Without one, an agent can loop indefinitely or burn through resources.Anthropic: building effective agentsHuman-in-the-loopHuman-in-the-loopA checkpoint where a person approves a consequential action before the agent proceeds. It trades some autonomy for safety on irreversible steps such as payments or deletions.Human-in-the-loopPermissionsPermissionsThe scope of what tools and resources the agent may touch. Tight permissions limit the blast radius if the model goes off-plan. Claude Code asks before running anything outside its allowed set.Claude Code docs
Harnesses

Runtimes that run the loop

Claude Agent SDKClaude Agent SDKAnthropic's toolkit for building agents on Claude. It handles the loop, context management, tool dispatch, and permissions so you build on top of a maintained runtime rather than wiring one yourself.Claude Agent SDK docsAgent frameworksAgent frameworksOpen libraries that provide a harness, such as Hugging Face smolagents. They give you a loop, tool plumbing, and conventions so you do not start from a blank file.smolagents docsOrchestrationOrchestrationCoordinating multiple steps, tools, or agents into a reliable flow. The choice between a simple loop and a multi-agent orchestration is an architecture decision with real cost and complexity trade-offs.Anthropic: building effective agents

In Practice

Four ways loops and harnesses change how PMs scope and ship agentic features

1

Specify the harness alongside the model

When a team says it is building an agent, the model choice is the smallest part of the decision. The harness is where the work is. What tools the agent gets, how context is managed, where the loop stops, and what needs human sign-off all shape how the feature behaves. Treat those as product requirements you write down, rather than leaving them for whoever wires it up.

2

Budget the loop before it ships

Each turn of the loop re-sends a growing context and pays for it again. An agent that takes eight steps when three would do is slow and expensive, and your users feel both. Set a step limit and a token budget, then watch real traces to see how many steps tasks actually take. The loop length is a number you can manage, so manage it.

3

Decide where a human stands in the loop

Reading data is low-stakes. Sending money, deleting records, or emailing a customer is not. Map the agent's actions by how reversible they are, then put an approval step in front of the ones you cannot undo. This is a guardrail you design, and it is far cheaper to add before launch than after an incident.

4

Build vs buy the harness

Writing a working loop is a weekend project. Making one reliable across context limits, retries, errors, and permissions is not. A maintained harness like the Claude Agent SDK or an open framework handles those for you, while a hand-rolled loop gives you full control and full maintenance. Choose deliberately, because the harness is the part you live with.

Curated Resources

Videos

Key Takeaway

The model is one part of an agent. The harness around it runs the loop, manages context, and enforces the stop conditions and permissions that decide whether the thing is reliable and safe. Spec the harness with the same care you give the model, because that is where the product actually lives.