Skip to content
Eldan.ai
Glossary

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.

Where this is taught

  • Agent

    An agent is a program that lets a model decide its own next steps: it calls tools, reads the results and repeats until it judges the task done or a limit stops it. Autonomy is a spectrum, and the smallest design that works, often a fixed workflow with one model call, is usually the right starting point.

  • Tool calling

    Tool calling, also called function calling, lets a model request that your code run a named function with structured arguments. The model never executes anything itself. It returns a request, your code validates and runs it, and the result goes back into the conversation for the next step.

  • Observability

    For AI systems, observability means recording enough about every request to explain it later: the prompt version, the inputs, the retrieved passages, each tool call, the output, token counts, latency and cost. Traces turn a vague user complaint into something you can read, and failed traces become new test cases.

Cite this page

Eldan Abdrashim. "Agent loop." Eldan.ai, 23 November 2026. https://eldan.ai/glossary/agent-loop.

The date you read it is added when you copy.

BibTeX

@online{abdrashim2026agent,
  author = {Eldan Abdrashim},
  title = {Agent loop},
  organization = {Eldan.ai},
  date = {2026-11-23},
  year = {2026},
  month = nov,
  url = {https://eldan.ai/glossary/agent-loop},
  langid = {english}
}

All terms

Section: Agents and tools. Last updated 23 Nov 2026.