---
title: "Agent Loop"
slug: "agent-loop"
category: "glossary"
tags: ["glossary", "ai-agents", "llm", "tool-use", "autonomy"]
status: "stable"
last_updated: 2026-05-14
summary: "Agent loop is the repeating observe-think-act cycle driving an autonomous LLM: receive input, choose a tool or action, execute it, process the result."
related:
  [
    "[[ai-agents/multi-agent]]",
    "[[glossary/planner-executor]]",
    "[[glossary/tool-call]]",
    "[[glossary/tool-result]]",
    "[[glossary/system-message]]",
    "[[glossary/hallucination]]",
  ]
---

## Overview

This page is the atomic definition. Multi-agent coordination patterns live at [[ai-agents/multi-agent]].

## Definition

The agent loop is the execution cycle of an autonomous LLM agent. In each iteration: the agent receives the current state (task description, memory, prior observations); the model reasons about what to do next; the model emits either a final answer or a [[glossary/tool-call]] (tool use); if a tool call was emitted, the runtime executes the tool and injects the [[glossary/tool-result]] back into the context; the loop repeats until the model signals completion or a step limit is reached. The loop is the mechanism that transforms a stateless LLM into a stateful agent capable of multi-step problem solving. Loop failures include: infinite loops (model never concludes), [[glossary/hallucination]] of tool results, context overflow when long loops fill the window, and reward hacking when the termination condition can be gamed. Safety mechanisms include: max iteration limits, per-step human approval for dangerous tool calls, and summarization at context boundaries. The [[glossary/planner-executor]] pattern splits the loop into a separate planning phase and an execution phase to reduce reasoning errors in each step.

## When it applies

The agent loop applies to any agent that needs more than one model call to complete a task: code execution agents, research agents, database query agents, and orchestrators managing sub-agents. Single-turn completions (one question, one answer) do not use a loop.

## Example

A code agent receives: "Fix the failing test." Loop iteration 1: read file (tool call). Iteration 2: run tests (tool call), observe failure. Iteration 3: edit file (tool call). Iteration 4: run tests (tool call), observe pass. Iteration 5: emit final answer. Five loop iterations to complete the task.

## Related concepts

- [[glossary/planner-executor]] - a two-phase architecture that separates planning from loop execution.
- [[glossary/tool-call]] - the mechanism by which the model invokes external tools within the loop.
- [[glossary/tool-result]] - the observation injected back into context after a tool executes.
- [[glossary/system-message]] - defines the agent's role and loop termination criteria.
- [[ai-agents/multi-agent]] - nested agent loops where one agent orchestrates others.

## Citing this term

> See [[glossary/agent-loop|Agent Loop]] (llmbestpractices.com/glossary/agent-loop).

## Related

- [[ai-agents/multi-agent]]
- [[glossary/planner-executor]]
- [[glossary/tool-call]]
- [[glossary/tool-result]]
- [[glossary/system-message]]
- [[glossary/hallucination]]
