F8.2 F8

The Agentic Loop: Reason → Act → Observe → Repeat

The agentic loop is the engine that makes agents work. It’s a repeating cycle: the model reasons about what to do, takes an action (tool call), observes the result, and decides whether to continue or stop. Without this loop, you have a chatbot.

The cycle

  1. Model receives the conversation history (including any prior tool results)
  2. Model reasons about the task and decides the next action
  3. If tool needed → model returns a tool call (stop_reason: tool_use). The client executes the tool, appends the result, and sends everything back. Loop continues.
  4. If task complete → model returns a final response (stop_reason: end_turn). Loop terminates.

Each iteration involves an API call. The model sees the full accumulated conversation — all prior messages, tool calls, and tool results — and decides what to do next.

stop_reason drives the loop

The stop_reason field is the control signal:

  • tool_use → the model needs a tool executed. Continue the loop.
  • end_turn → the model is done. Return the final response.

This makes the loop model-driven. The model decides when to continue (by requesting a tool) and when to stop (by returning a final response). Not a fixed iteration count, not a timer, not human approval at each step.

No completion guarantee

The agentic loop does NOT guarantee task completion. Tools may fail. Information may be unavailable. The task may be impossible. The model may hit max_tokens. The loop can terminate without successfully completing the task.

This is why max_turns exists as a safety limit — it prevents runaway loops where the model keeps trying but never converges. But it doesn’t make the loop succeed; it just prevents infinite spinning.

Counting iterations

A task like “find all TODO comments and create a summary” takes at minimum 3 iterations:

  1. Model calls Grep → result returned (tool_use)
  2. Model calls Read → file content returned (tool_use)
  3. Model generates summary → done (end_turn)

“At least” because the model might need multiple Read calls for multiple files. Each tool call is a separate iteration. The model can’t batch Read and summary generation — it needs the Read result before it can summarize.

Loop vs single call

A single API call generates text and stops. The agentic loop adds iterative tool execution with observation: call a tool, see the result, reason about it, decide the next action. This observe → reason → act cycle is what enables complex multi-step tasks. Same model, same API — the loop adds iteration capability, not model power.


One-liner: The agentic loop cycles through reason → tool call → observe result → repeat, driven by stop_reason (tool_use = continue, end_turn = stop) — it enables multi-step tasks but doesn’t guarantee completion.