Overview
This page is the atomic definition. Multi-agent coordination patterns live at 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 tool-call (tool use); if a tool call was emitted, the runtime executes the tool and injects the 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), 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 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
- planner-executor - a two-phase architecture that separates planning from loop execution.
- tool-call - the mechanism by which the model invokes external tools within the loop.
- tool-result - the observation injected back into context after a tool executes.
- system-message - defines the agent’s role and loop termination criteria.
- multi-agent - nested agent loops where one agent orchestrates others.
Citing this term
See Agent Loop (llmbestpractices.com/glossary/agent-loop).