You know when you don’t know the answer, so you just keep thinking about it and thinking about it? Agents can get stuck the same way. For good reason, limits were introduced so they don’t. Frankly, humans could benefit from something similar.
Let’s take a step back and establish some foundations for how this works.
The setup
An agent is just code wrapped around an LLM. It sends the LLM three things:
- A system prompt: “You’re a party planner.”
- Tools: functions the LLM can ask to use, each with a name, a description, and parameters. For example,
book_venue(date, guests). - Context: the actual request, usually an email or chat message, plus everything that’s happened so far.
The LLM sends back one of two things: a tool call (“run book_venue with date = Nov 2, guests = 30″) or a final answer, which ends the run.
How the agent knows which one it got
The response isn’t just text. It’s structured, with a label that literally says “I want a tool” or “I’m done.” The agent’s code checks that label. If it’s a tool call, the agent runs the tool, adds the result to the conversation, and calls the LLM again. If it’s a final answer, it stops.
The LLM never runs anything itself. It only asks. The agent does the doing.
What’s a turn?
One trip around that loop: call the LLM, get a response, run the tool, feed the result back. That’s one turn.
There’s a catch. The LLM has no memory, so every turn the agent resends the entire conversation. Turn 20 carries everything from turns 1 through 19, which makes each turn more expensive than the last.
Why limit turns
- Runaway loops: a confused agent can retry the same failing thing forever.
- Cost: it compounds as the context grows.
- Speed: someone is waiting on the answer.
- Safety: fewer turns means fewer chances to do something wrong.
- Knowing when to escalate: hitting the limit is the signal to stop and hand off to a human.
The human lesson
Give yourself a turn limit. If you’ve gone around the loop five times with no progress, stop spinning and escalate: ask someone, or try a different approach. Sometimes the smartest move is admitting you’ve hit max turns.