Build Your First AI Agent from Scratch · 45 min · Python · Anthropic Python SDK
The Planning Loop
The loop is: ask, execute what it asks for, tell it what happened, repeat until it stops asking.
Hiring signal: This loop — with better tools and more error handling — is the actual architecture behind Claude Code, AutoGPT-style agents, and most 'agentic' products on the market. Once you've built it yourself, no agent framework's internals will feel mysterious again.
What you will learn
- Implement the ReAct-style loop: reason, act, observe, repeat
- Route a tool_use block to the correct Python function and feed the result back correctly
- Add a max-iterations guard and explain why every agent loop needs one
Introduction
You have 4 working tools. Today you stop calling them by hand and let the model decide which ones to call, in what order, based on a task — the part that actually makes this an "agent" instead of a tool-calling chatbot.
Architecture first
Before any code: here's the whole loop you're building.
task ──▶ [ messages ] ──▶ model.create(tools=TOOLS)
│
┌────────────┴────────────┐
│ │
stop_reason == stop_reason ==
"tool_use" "end_turn"
│ │
run_tool(name, input) return final text
│
append tool_result to messages
│
└──────▶ back to model.create (loop)
Every box in that diagram is code you already wrote in Lessons 1-2, except the loop itself and the max-iterations guard — that's genuinely all that's new today.
Why this is called "ReAct"
The pattern (reason about what to do, act by calling a tool, observe the result, repeat) comes from a 2022 paper called ReAct — "Reasoning and Acting." It predates most of the current agent-framework hype by two years. Frameworks like LangGraph didn't invent this loop, they just wrapped it in more abstraction. You're implementing the actual idea, not a framework's opinion about it.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers The part everyone forgets: max iterations, Routing the tool call, What You're Building — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.
Browse all courses · View pricing · DeVenture Academy