Module 1 could only talk. This module gives Claude the ability to act — by calling functions in your own code and using the results to form its answer. This is the moment an LLM call becomes an “agent.”
stop_reason field: end_turn (Claude is done) vs tool_use (Claude wants to call a tool)1. Send messages + tool definitions to Claude
2. If stop_reason == "end_turn" → return Claude's text, done
3. If stop_reason == "tool_use" → run the requested tool(s),
append the result(s) as a "tool_result",
go back to step 1
4. Repeat until done, or max_turns is hit (a safety net against infinite loops)
Claude never executes code itself. It only ever requests a tool call by name with arguments — your code decides whether and how to actually run it. That boundary is what makes tool use safe to reason about.
agent.py gives Claude a calculator and a (fake) weather lookup, then asks a question that needs both:
pip install -r requirements.txt
export ANTHROPIC_API_KEY=your_key_here
python agent.py
Watch the printed →/← lines — that’s the loop calling tools and feeding results back in real time.
Module 3 — Persistent Memory makes an agent remember things across separate runs, not just within one conversation.