
The agent loop
An agent isn't magic — it's an LLM in a loop with access to tools.
User turn
→ LLM picks next step (tool call or final answer)
→ Tool router validates + calls endpoint
→ Tool returns JSON result
→ LLM receives result
→ (repeat until final answer or iteration cap)
→ Final answer sent to user
Cap iterations at 8. Uncapped agents can loop indefinitely on ambiguous tasks.
A worked example — support assistant answering "Why does my MBA-2024 battery drain overnight?":
- LLM calls
SearchTickets("battery drain MBA-2024", productSku: "MBA-2024", limit: 5) - Tool returns 5 tickets; LLM identifies 2 as relevant
- LLM calls
GetNeighbours(uid: "ticket-42", edge: "Resolution", limit: 1) - Tool returns: "firmware update v3.2 fixes overnight drain"
- LLM composes answer with citations
[1][2] - Total: 3 model calls, 2 tool calls, ~2 seconds
Keep the tool catalog small. Overlapping tools cause unreliable selection. Aim for fewer than 10 tools per chat surface, each with a distinct, non-overlapping purpose.