---
title: "Agent loop"
url: https://eldan.ai/glossary/agent-loop
canonical: https://eldan.ai/glossary/agent-loop
locale: en
language: en
published: 2026-11-23
updated: 2026-11-23
author: "Eldan Abdrashim"
cite_as: "Eldan Abdrashim. \"Agent loop.\" Eldan.ai, 23 November 2026. https://eldan.ai/glossary/agent-loop."
---

# Agent loop

> The agent loop is the cycle at the heart of every agent: send the conversation to the model, and if it asks for tools, run them, append the results and send again. It ends when the model answers in plain text or a limit is hit. The message list is the whole state of the run.

Because the state is just a list, you can log it, trim it, save it and replay it. Frameworks add features around the loop, but the loop itself fits in about thirty lines.

**Common mistake.** Running the loop without a step limit. A confused model will keep calling tools and keep billing you.

**In practice.** Cap steps, tokens and wall-clock time in code, detect repeated identical calls, and test the loop with a scripted model that replays recorded replies.

## Related terms

- [Agent](https://eldan.ai/glossary/agent)
- [Tool calling](https://eldan.ai/glossary/tool-calling)
- [Observability](https://eldan.ai/glossary/observability)

## Used in

- [Tool Calling From Scratch](https://eldan.ai/tutorials/tool-calling-from-scratch)
