0Pricing
Claude Architect · Lesson

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_reason in the response.
  • Run tools if Claude asked for them, then add the results to the history.
  • Repeat until stop_reason is end_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

  1. What Makes a System Agentic
  2. Model-Driven vs Hard-Coded Decisions
  3. When to Use an Agent
  4. The Agentic Loop Overview
← Back to Claude Architect