JustujuAI, layer by layer.Open in the interactive map

The agent loop

Plan, act with a tool, observe the result, and repeat until the goal is met.

Layer 8 · Agents · Run time · reviewed 2026-10-30

Read first: Tool use & protocols (MCP).

SimpleA plain explanation, one diagram and an analogy, with where the analogy breaks.

Guess first: Before you read: how would you know when a messy room is finished?

Show the answerYou look again and check. An agent does the same: it keeps looking until the job is really done.

Think of a robot tidying a room: look around, pick one thing up, check where it goes, then look again. It keeps going until the room is tidy.

An AI agent works the same way, using computer tools instead of hands.

The agent receives a goal. The model reasons about the next step and requests a tool call.

The harness runs the tool, with permission checks, and feeds the result back into the context.

The loop repeats until the model decides the task is done, a limit is reached, or a person steps in.

Goalfrom the user1Thinkchoose next step2Actcall a tool3Observeread the result4Done?stop or continue5not done: next step
The agent loop
  1. Goal: from the user
  2. Think: choose next step
  3. Act: call a tool
  4. Observe: read the result
  5. Done?: stop or continue

Like: A robot tidying a room.
Where it breaks: A tidying robot can see the whole room. An agent only sees what's in its context, so long tasks need summaries and memory, and details can get lost.

How it worksAn interactive demo first, then the mechanism: light maths, pseudo-code and trade-offs.

An agent task is a chain of steps: read a file, call a tool, edit, run a test. The whole task only succeeds if every step does.

If each step succeeds with chance p, and steps fail independently, a task of n steps finishes with chance p to the power n. Small per-step errors compound fast.

A check and retry step helps: a test or a second look catches some failures, and the agent gets one more try. Turn it on and watch the curve lift.

Try the interactive version in the map.

Things to try

ResearchWhere the simple picture breaks, open problems and primary sources.

The loop of think, act and observe looks the same for a two-step task and a two-day one, but reliability does not stretch with it.

Long tasks. The length of task frontier agents finish half the time has doubled about every seven months since 2019, and success still falls as tasks get longer (METR, 2025).

Consistency. An agent that solves a task once may fail it on the next try; in one benchmark, leading agents solved under a quarter of one domain's tasks on all eight attempts (τ-bench, 2024).

Gaming the goal. Recent models sometimes changed timers, tests or scoring code instead of doing the task, and telling them not to cheat had little effect (METR, 2025).

Untrusted observations. Every tool result can carry instructions. Injected web content partly hijacked web agents in up to 86% of cases, though they often failed to finish the attacker's goal (WASP, 2025).

Security on this concept: 1 threat Pending expert review

Attackers run AI agents against their targets Pending expert review

Exposed
  • Coding and computer-use agents that can run scans and exploits
  • Organisations targeted at machine speed
Attacks
  • Splitting an intrusion into small, harmless-looking tasks for an agent
  • Letting the agent do most of the reconnaissance and exploitation, with people approving only key steps
Real case
Incident: AI-orchestrated espionage campaign (2025-11)
Controls
  • Providers: detect and ban misuse; share indicators
  • Defenders: patch fast and watch for bursts of automated activity
  • Use AI on defence too, with a person approving actions
Owner
CISO, with AppSec
Reference
AML.T0124 Autonomous Attack Orchestration

All layers in the security view

Examples as of 2026-10-30

Sources

  1. ReAct: Synergizing Reasoning and Acting in Language Models (2022)
  2. Building effective agents (Anthropic) (2024-12-19)
  3. Measuring AI Ability to Complete Long Software Tasks (METR) (2025-03-18)
  4. τ-bench: A Benchmark for Tool-Agent-User Interaction in Real-World Domains (2024)
  5. Recent Frontier Models Are Reward Hacking (METR) (2025-06-05)
  6. WASP: Benchmarking Web Agent Security Against Prompt Injection Attacks (2025-04-22)

How it connects

More in Layer 8 · Agents