Skip to content

The Agent Loop Explained

The core cycle every agent runs: think, call a tool, observe the result, repeat — and how the loop knows when to stop.

Editorial team 1 min read

At the centre of every agent harness is a loop.

The Cycle

  1. Send the model the task, instructions, available tools and history.
  2. The model responds with either a final answer or one or more tool calls.
  3. The harness executes the tool calls.
  4. Results are appended to the history.
  5. Go back to step 1.

Stopping Conditions

  • The model returns a final answer with no tool calls.
  • A maximum number of steps or tokens is reached.
  • A time or cost budget runs out.
  • The user interrupts.
  • An unrecoverable error occurs.

Always set limits; a confused agent can otherwise loop indefinitely.

Parallel Tool Calls

Models may request several independent tool calls at once. Running them concurrently speeds things up.

Errors Are Observations

When a tool fails, return the error message to the model rather than crashing. Models can often recover — fixing a path, retrying with different arguments, or trying another approach.

Keep It Simple

A basic loop with good tools and clear instructions handles a surprising range of tasks. Add planners, sub-agents and complex state only when evaluation shows they help.

More in Agent harnesses

All Agent harnesses guides →
Agent harnesses Guide · 2 min

What Is an Agent Harness?

The software around a language model that turns it into an agent: the loop, tools, context, permissions and memory.

Agent harnesses 2 min read 11 Sep 2025

Agent harnesses Guide · 1 min

Designing Tools for AI Agents

How to write tools agents use well: clear names, precise descriptions, sensible inputs and informative outputs.

Agent harnesses 1 min read 9 Sep 2025

Agent harnesses Guide · 1 min

Context Management in Agent Harnesses

How agents stay effective over long tasks: what to keep in context, what to summarise, and what to store outside.

Agent harnesses 1 min read 8 Sep 2025

Agent harnesses Guide · 1 min

Permissions and Approval in Agent Harnesses

Controlling what agents can do on their own: allow lists, approval prompts, forbidden actions and escalation.

Agent harnesses 1 min read 7 Sep 2025