L100 Claude Agentic Loops:
- Communication Stack 4 layers from your code to Claude's servers — what each one does
- messages.create() 5 parameters of the core API call — required vs optional
- Tools = Descriptions The most tested distinction — what Claude sees vs what runs
- The 4-Step Agentic Loop
- Model-Driven Agency: Claude decides what to call — vs scripted automation where you do
1. Communication Stack 4 layers from your code to Claude's servers
The 4 layers flow:
Code -> Anthropic SDK -> Claude API -> Claude Servers
*2. messages.create() with 5 params *
One function to call in every agentic loop
Required:
- model : Specify which Claude Model to use
- max_tokens : Hard cap on response length
Optional:
- system: Persistent instructions that shape every response
- tools: Declare what actions Claude is allowed to request
- messages: Full conversation history
3. Tools, descriptions, not code
Tools vs code:
Tools: Description puls a separate function (dont put execution logic inside the tool definition)
Code: actual function, eg API call, DB query
*4. The response Object & Agentic Loop: *
Two Critical fields:
- STOP_REASON : Why Claude Stopped (end_turn: exit loop, tool_use: Claude needs code to act, max_tokens: Response cut off)
- CONTENT[] : Array of blocks
Tool use block fields:
id: unique ID. Must match when sending result back.
name: which tool claude to call
input: arguments Claude chose based on context
Agentic Loop:
Send (call messages.create(), including tool definitions, converesation history → check stop reason end_turn, tool_use (step 3) → execute tools find every tool_use block in content array → append & repeat, add Claude response as assistant message, tool results as user message, back to step 1
5. Model-Driven Agency
Scripted Automation vs Model-Driven Agency
Calling Claude in a rigid, predetermined sequence is automation. True agency is when Claude reads context, chooses tools dynamically, and controls when the loop ends — while your code just executes what it decides. Claude reads tool descriptions and conversation context to decide which API to call.
5.1 Deep dive on stop_reason :
stop_reason field — the signal that tells your agentic loop what to do after each API response


Top comments (0)