The Agentic Loop Overview
request, inspect stop_reason, run tools, repeat.
What Is the Agentic Loop?
An agent is just a loop around the Claude Messages API. You send a request, Claude either finishes or asks to run a tool, you run it, and you send the results back. Repeat until Claude is done.
The whole pattern is four steps:
- Request — call the API with your message history.
- Inspect the
stop_reasonin the response. - Run tools if Claude asked for them, then add the results to the history.
- Repeat until
stop_reasonisend_turn.
Master this one loop and you understand the core of every agent.
The Request: Full History Every Turn
The Claude API is stateless. The model keeps no memory between calls, so you must send the full message history every single turn.
A request carries these fields:
model— which Claude model to use.max_tokens— the output cap.system— the system prompt.messages— the entire conversation so far.tools— the tools Claude may call.
If you forget to append a turn, Claude simply won't know it happened.
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-4-8",
max_tokens=1024,
system="You are a helpful weather assistant.",
tools=tools,
messages=messages, # the FULL history, every turn
)All lessons in this course
- What Makes a System Agentic
- Model-Driven vs Hard-Coded Decisions
- When to Use an Agent
- The Agentic Loop Overview