How does an agentic loop work step by step?
Each pass through the loop, usually called a turn, has the same shape. The runtime sends the model its context: system prompt, tool definitions and history so far. The model replies with text, one or more tool calls, or both. The runtime executes each allowed call, appends the result to the history and calls the model again. Anthropic’s definition of agents is the short version: “LLMs using tools based on environmental feedback in a loop” (Building effective agents, 19 December 2024, read 16 November 2026).
A worked example from the Claude Agent SDK docs, for the prompt “Fix the failing tests in auth.ts”: turn 1 runs the tests and sees three failures, turn 2 reads the source and test files, turn 3 edits the code and reruns the tests, and a final text-only turn reports the fix (How the agent loop works, read 16 November 2026). The loop ends when the model stops asking for tools, not when a step counter says so. The final answer costs a turn as well: the same docs note that max_turns=2 would have stopped that run before the edit.
When does an agentic loop stop?
On a final answer, or on a limit the runtime enforces. The defaults differ widely:
| Runtime | Limit | Default | When the limit is hit |
|---|---|---|---|
| OpenAI Agents SDK (Python) | max_turns |
10 turns | raises MaxTurnsExceeded |
| Claude Agent SDK | max_turns, max_budget_usd |
no limit | result subtype error_max_turns or error_max_budget_usd |
| LangGraph 1.1.4 and later | recursion_limit |
10,007 super-steps | raises GraphRecursionError |
Sources, all read 16 November 2026: OpenAI’s run_config.py and running agents guide, Anthropic’s agent loop page, and LangGraph’s Graph API docs. A LangGraph super-step is a graph step, not a model call, so its limit is not comparable one to one. Never ship on the framework default: set a turn cap, a spend cap and a wall-clock agent timeout yourself. Anthropic’s guide recommends stopping conditions “such as a maximum number of iterations” for the same reason. Decide what a hit limit returns, too: a partial result, a resumable session, or a handoff to a person.
What does the reasoning step in an agentic loop do?
It chooses the next action from the latest observation, and nothing more. Executing, validating and limiting belong to the agent harness around the model. A ReAct agent makes that reasoning explicit by writing a thought before each action. The model proposes, the runtime decides: arguments get schema checks, risky calls wait for human approval, and in the Claude Agent SDK a PreToolUse hook can reject a call before it runs, in which case the model receives the rejection as its observation (agent loop page, read 16 November 2026). Reasoning quality decides how many turns a task takes; the runtime decides whether a bad turn does damage.
How is an agentic loop different from an agentic workflow?
In an agentic workflow, code fixes the path; in an agentic loop, the model picks it. A workflow model only fills in the steps, while a loop model chooses each next step one turn at a time. The loop is more flexible and harder to predict, and its context grows with every turn until something trims it, which is the job of context compaction. Use a loop when you cannot write the steps in advance, and a workflow when you can. Many production systems nest the two: a fixed workflow with one bounded loop inside the step that needs judgment. Hosted harnesses now run the loop for you, as we covered in Claude Managed Agents: the harness is now a service, but the limits stay your decision.