# Agent loop

Canonical page: https://www.theglitch.ai/ai-glossary/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.](https://www.theglitch.ai/images/cards/glossary/agent-loop.png?v=15be262bf10bf930)

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

- [Agent harness](https://www.theglitch.ai/ai-glossary/agent-harness): The agent loop is the core model-tool cycle; the agent harness is the complete surrounding system — state persistence, permissions, compaction, sandboxing and verification.

- [Workflow](https://www.theglitch.ai/ai-glossary/workflow): A workflow follows fixed code-defined branches between steps; an agent loop lets the model decide which tool to call next until its goal or stop cap is met.

## Related terms

[Agent](https://www.theglitch.ai/ai-glossary/agent) · [Agent harness](https://www.theglitch.ai/ai-glossary/agent-harness) · [Tool calling](https://www.theglitch.ai/ai-glossary/tool-calling) · [ReAct](https://www.theglitch.ai/ai-glossary/react-pattern)

## Try it here

[AI agents, minus the hype](https://www.theglitch.ai/learn/ai-agents) · [Build your first agent](https://www.theglitch.ai/learn/first-agent)

## Sources

- [Anthropic · Building effective AI agents](https://www.anthropic.com/engineering/building-effective-agents)

- [Anthropic · Tool use with Claude](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview)

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](https://www.theglitch.ai/ai-glossary/agent-loop.md).

Definition updated 2026-11-28.

[The Ultimate AI Glossary (2027): every term](https://www.theglitch.ai/ai-glossary)

---

Site: [The Glitch](https://www.theglitch.ai) · [About Rabin](https://www.theglitch.ai/about) · [Agent guide](https://www.theglitch.ai/agent.md)
