The loop with no exit
Step 1 · The pattern
Ask the model, run the tool, repeat
The agent asks the model; the model asks for a search; the runner runs it and asks the model again. After a couple of turns the model has what it needs and answers. Each turn spends tokens (amber). (All numbers are illustrative.)
- a task
- tokens spent
- answered
In short
The loop with no exit: how it works and how it breaks
An agent is a loop: the model reads the conversation and asks for a tool, the runner executes it and appends the result, and the model is asked again, until it answers without asking for a tool. Nothing in that loop has to end. Asked for something that does not exist, the agent keeps searching and rephrasing; each turn resends the growing history, so cost climbs faster than the turn count, and the user stares at 'working on it'. Anthropic describes early versions of its research system searching endlessly for nonexistent sources. The fix is deterministic: a hard turn limit (OpenAI's Agents SDK raises an error when max_turns is exceeded) and a token or cost budget per task, then a controlled ending: say what was found and what was not, or hand over to a person. Track turns and tokens per task.
What this simulation simplifies
- Turns take a fixed time; real turns vary with tool latency and output length.
- Unfindable tasks are a fixed half; real ones are rarer, which is why they are easy to miss.
How this comes up in interviews
"How do you keep an agent from running forever or running up the bill?"
Then they ask
- What ends the loop?
- What happens at the limit?
- What do you monitor?
A strong answer covers
- The loop ends only when the model stops calling tools.
- Hard turn limit and token/cost budget per run.
- A controlled ending: partial answer or human hand-off.
- Tell the model when tools fail; avoid repeated identical calls.
- Graph turns and tokens per run; alert on the tail.
Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.
On one page: the track cheat sheet.
Sources: OpenAI Agents SDK docs: Running agents (the agent loop, max_turns) ↗ · Anthropic engineering: How we built our multi-agent research system ↗ · Report a problem
Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.