Skip to main content

Agent Tool Loop

An agent tool loop is the canonical agentic execution pattern: the model receives a goal, optionally calls a tool, observes the result, and decides whether to call another tool or finish. The loop continues until the model emits a terminal response or hits a step or cost ceiling. The pattern is used (with variations) by virtually every modern agent framework — LangGraph nodes wrap loops, CrewAI tasks run loops, the OpenAI Agents SDK's Runner is a loop, Mastra agents loop. Understanding the loop shape is foundational because most agentic failure modes are loop-shape failures (infinite loops, premature termination, tool thrash).

Example

A research agent in a tool loop calls a search tool, reads the snippets, calls a fetch tool on the most promising URL, summarizes, and either calls more tools or returns the final answer — all within a single user turn. A step-ceiling cuts off runaway loops; a cost-ceiling cuts off ones that recurse profitably but expensively when token spend matters more than completion.

Put this into practice

Build polished, copy-ready prompts in under 60 seconds with SurePrompts.

Try SurePrompts