← Agents courseAGENTS · CHAPTER 2 OF 12 · 4 min READ · FREE

The loop: look, think, act, repeat

The story

Every agent you have ever heard of, from a coding assistant to a shopping bot, is built on the same small loop. The loop is so simple that people are surprised. Look at the situation. Decide what to do. Do it. Look at what happened. Go around again until done.

The one plain idea

An agent is a model plus a loop. The model reads everything so far, picks either 'call a tool' or 'give a final answer', and a plain program around it carries out the tool call and feeds the result back. That program is often called the harness.

The kitchen-table picture

Think of cooking without a recipe. You taste the sauce (look), decide it needs salt (think), add salt (act), taste again (look). You stop when it tastes right. The 'stop when it tastes right' part is the hardest bit for an agent too.

Worked example

Here is the loop written as plain steps, no code. 1. The harness sends the model: the goal plus a list of tools it may use. 2. The model replies: 'use the search tool with the words cheap flights Chicago Friday'. 3. The harness runs the search and pastes the results back into the conversation. 4. The model reads them and replies: 'use the sort tool'. 5. Repeat. 6. At some step the model replies with plain words instead of a tool request. The harness treats that as the final answer and stops. A typical run can be 5 to 50 trips around the loop. Each trip costs tokens, so loops cost money (see our Tokens course, chapter 7).

No-code exercise

Run the loop by hand with a friend. You are the model, they are the harness. Goal: 'find out if it will rain at their house tomorrow.' You may only say one tool request at a time ('look at weather app', 'read me the hourly view'). They do exactly that and read back what they see. Count the trips. Notice that you never knew trip 2 until you heard trip 1's result.

Self-check

  1. What is the harness? Answer: The ordinary program around the model that runs tool requests, feeds results back, and decides when to stop.
  2. How does the loop know to end? Answer: The model answers in plain words instead of asking for a tool, or the harness hits a limit it was given, such as a step cap.
  3. Why do longer loops cost more? Answer: Every trip adds text the model must read again, and models are billed by tokens.

Sources

  • Anthropic describes the building block as an 'augmented LLM' (a model with tools and memory) and agents as that model operating in a loop with feedback from its environment. https://www.anthropic.com/engineering/building-effective-agents General knowledge / our framing: The harness name and the step-by-step loop description are common industry vocabulary, taught here in our own words. Step counts like 5 to 50 are illustrative, not measured.
CURIOUS? TEST THE CLUES

Curiosity check

Pick an answer and see why. No scores, no pressure. All shop examples are invented practice scenarios.

01 What is the harness?
02 Why do longer loops cost more?