Category · Agents and orchestration
What is an agent loop?
In an agent loop, the model answers or requests a tool, the code runs it, and the result comes back, until the task is done or a limit is reached. ReAct (Reasoning and Acting) is its classic form, not to be confused with React.
By Laurent Poupet, Claude trainer and artificial intelligence architect · Updated
How it works
- At each turn, the whole history, with tool results, is sent back to the model; the cost of a task therefore grows faster than the number of turns.
- The loop stops when the model answers without requesting a tool, or when a limit is reached, and it is the code, not the model, that checks these conditions.
- Frameworks such as LangGraph or LangChain provide this loop ready-made, with the state saved between turns and breakpoints for a human.
The trap to avoid
The trap is the loop that goes round in circles, for example a tool that fails and that the model calls again endlessly with the same parameters.
Related terms
- LangChainAgents and orchestration
- LangGraphAgents and orchestration
- Agent skillsAgents and orchestration
Where this is taught
Track 2 · Claude Code: the augmented developer
Your First Session on a Projectlesson 2 · 1 hourTrack 3 · Skills, agents and connectors
The Agent SDK (software development kit) — Build and deploy agentslesson 9 · 1 hour
Lesson content (step-by-step instructions, exercises with solutions, quizzes) is for students only, with an access code received after the first lesson.