agent loop
The cycle at the heart of an agent: the model reasons and requests tools, your code runs them, and the results go back until the model finishes or a limit stops it.
In more detail
Give the loop every exit it needs: a finished answer, unexpected stop reasons, and budgets for steps and money, and return the reason it stopped. Each turn resends the whole conversation, so long loops get expensive quickly.
Related terms
- AI agent — A system in which a model decides its own next steps, calling tools in a loop until a task is done, rather than following a path your code fixed.
- step budget — A hard limit on how many turns or how much money an agent loop may use before it stops and reports why.
- ReAct — A prompting pattern in which a model alternates reasoning steps with actions, such as tool calls, and reads each observation before continuing.
Taught in
- Streaming Responses — AI Engineering: LLM Apps, RAG & Agents
- Reasoning Techniques — AI Engineering: LLM Apps, RAG & Agents
- The Agent Loop — AI Engineering: LLM Apps, RAG & Agents
- Planning, Memory And Many Agents — AI Engineering: LLM Apps, RAG & Agents
- Agent SDKs And Human Approval — AI Engineering: LLM Apps, RAG & Agents
- Connect An Agent To MCP — AI Engineering: LLM Apps, RAG & Agents
- Threat-Model An LLM App — AI Engineering: LLM Apps, RAG & Agents
- Prompt Injection — AI Engineering: LLM Apps, RAG & Agents
- Excessive Agency — AI Engineering: LLM Apps, RAG & Agents
- Capstone: The Tasks Assistant — AI Engineering: LLM Apps, RAG & Agents
References
- OpenAI Agents SDK: Running agents (the agent loop, max_turns)
- Claude Agent SDK: How the agent loop works