Agent loop

The core while-loop behind an AI agent: send context and tool definitions to the model, execute any tool call it requests, feed the result back and repeat until a stop condition fires.

Agent loop, common card #258 in The Glitch AI glossary: The core while-loop behind an AI agent: send context and tool definitions to the model, execute any tool call it requests, feed the result back and repeat until a stop condition fires.
GLS 258 · common

Also called: Agentic loop, Tool-use loop.

For: Beginner · Builders · Must know

Why it matters

Understanding the loop demystifies agents: there is no magic autonomy, just repeated model calls bounded by tools, budgets and exit checks.

In practice

A bug-fix agent runs a loop capped at 12 turns and $1.50 in token spend. Turn 1 reads the failing test, turns 2–3 edit the handler, turn 4 runs npm test and sees a green exit code 0, and turn 5 emits the final summary with no tool calls, exiting the loop cleanly.

Watch for

Without a hard step limit, spend cap and duplicate-call detector, a stuck model will retry the same failing command until it burns your budget or hits rate limits.

How it compares

Related terms

Agent · Agent harness · Tool calling · ReAct

Try it here

AI agents, minus the hype · Build your first agent

Sources

Use in an AI agent: connect MCP at https://www.theglitch.ai/mcp and call get_glossary_term with agent-loop, or read the Markdown edition.

Definition updated 2026-11-28.

The Ultimate AI Glossary (2027): every term