The host sends conversation state and tool schemas to the model, then inspects the reply.
Each turn is one model request. The host includes prior messages, the current user text, and the tools this session may call. After the reply, the host either paints text or starts the tool path.
- Control signal
- next turn
- 01user text
- 02model request
- 03stop_reason
- 04branch
Turn controller
Reading the animation: A ticket enters; the controller waits; the reply is sorted into text or a tool path.
Sends one model request and waits for a stop reason.
One user question opens a model turn
messages: [{role:"user", content:"Is the Bunny zone zackproser reachable?"}] + tools:[head_storage_zone]- User text
- Is the Bunny zone zackproser reachable?
- Tools in request
- head_storage_zone
- Model
- claude-opus-5
- Waiting on
- stop_reason
The controller assembles messages and tools, calls the model API, and branches on stop_reason. end_turn means show text. tool_use means run tools, then maybe request another completion.
In engineering terms: The turn controller is that dispatcher. It owns the request/response cycle with the model API.
FOLLOW THIS EXAMPLE
- 01
Collect messages, tools, and tool_choice for this turn.
- 02
Send one completion request to the model API.
- 03
Read stop_reason and the content blocks.
- 04
Show text, or hand tool_use blocks to the rest of the stack.
Picture a dispatcher who takes one ticket, sends it to a specialist, and waits for either a written answer or a work order.
Where it stops matching: A specialist can stall, refuse, or return several work orders at once. The controller must handle empty content, max_tokens, and mixed blocks.Measurements, controls, and tradeoff
- Useful evidence
- stop_reason values, empty content, max_tokens cuts, and time to first block.
- Controls
- max_tokens, tool_choice, and whether the SDK auto-continues after tools.
- Tradeoff
- A longer max_tokens budget lets a call finish; it also spends more when the model writes a large input object.
- Decision
- stop_reason
Definitions and sources
TERMS IN THIS VIEW
- Agent loop
- A program that repeatedly sends conversation state to a model, executes any tool calls in the reply, and continues until the model returns ordinary text or a stop rule fires.
- stop_reason
- The model API’s explanation for why a response ended. tool_use means the host should run tools before requesting another completion.
- Host
- The application that talks to the model API, decides which tools exist, executes or forwards calls, and writes tool_result blocks.
- Token
- A small unit of text the model reads or writes. Tool schemas, tool_use blocks, and tool_result blocks all consume tokens.
SOURCES + CONTINUE READING
Why it matters: Without this loop, a tool_use block is only a suggestion. The host is what turns it into work.
Definitions for this layer
TERMS IN THIS VIEW
- Agent loop
- A program that repeatedly sends conversation state to a model, executes any tool calls in the reply, and continues until the model returns ordinary text or a stop rule fires.
- Host
- The application that talks to the model API, decides which tools exist, executes or forwards calls, and writes tool_result blocks.
- tool_choice
- A request option that steers whether the model may call tools, must call one, or must answer in text.
- Token
- A small unit of text the model reads or writes. Tool schemas, tool_use blocks, and tool_result blocks all consume tokens.
