The agent loop
For engineers
The reason-act-observe cycle, stopping conditions, step and token budgets, and context management across turns
110 questions across four stages: Understand, Apply, Solve and Judge.
Try 5 questions
Practice items, not counted towards your mastery. No account needed.
Check yourself · 1 of 5
In an agent loop built on a tool-calling API, who actually runs the tool the model asks for?
Check yourself · 2 of 5
Why should an agent loop have a hard turn limit even when the model is told to stop when done?
Check yourself · 3 of 5
Why can an agent's cost grow faster than its number of turns?
Check yourself · 4 of 5
In an agent run, edit_file and run_tests alternate for six turns, undoing and redoing the same change. What is this pattern called?
Check yourself · 5 of 5
In a long agent run, which part of the history is usually the safest to clear after several turns?
Topics
- Reason, act, observe: the ReAct cycle4 min read · The interleaved reasoning and tool-call cycle, and how current models run it natively with tool use and extended thinking
- Stopping conditions that end runs cleanly4 min read · Done criteria, final-answer tools, turn limits, and stops on repeated errors or a user interrupt
- Step, token, time and cost budgets4 min read · Setting turn caps, token and spend limits, wall-clock timeouts, and what the agent does when a budget runs out
- Runaway and stuck loop mechanics4 min read · Repeating the same call, ping-ponging between two states and retrying an error forever, and the loop code that prevents each
- Managing context across loop turns4 min read · Tool-result clearing, compaction and summarised history so long loops stay inside the context window without losing facts
Start here
- ReAct: Synergizing Reasoning and Acting in Language Models (opens in a new tab)PaperFree
The paper that named the pattern of interleaving reasoning steps with actions and observations.
- Building effective agents (Anthropic) (opens in a new tab)ArticleFree
Describes agents as models using tools in a loop, and why to add stopping conditions and checkpoints.
- LLM Powered Autonomous Agents (Lilian Weng) (opens in a new tab)ArticleFree
A long survey of planning, memory and tool use, including ReAct-style loops and their failure modes.
Scenarios
Helps to know first
110 questions · last verified 2026-12