Implementation Guide — Agents Examples

This directory originally contained Python example scripts that were removed from this archive.
An AI assistant can recreate them by following the instructions below.


react_agent.py

Purpose: Implement a ReAct (Reasoning + Acting) agent loop from scratch.

What to implement:

  1. Define 2–3 simple tools as Python functions (e.g. web_search(query) → fake results, calculator(expr) → eval result, get_weather(city) → hardcoded response).
  2. Implement the ReAct loop:
    • Thought: Claude reasons about what to do next.
    • Action: Claude picks a tool and arguments (via tool-use / structured output).
    • Observation: Run the tool and feed the result back.
    • Repeat until Claude outputs a final answer (no tool call).
  3. Cap the loop at 10 iterations to prevent runaway execution.
  4. Print each Thought/Action/Observation step to show the reasoning trace.

How to run: python react_agent.py
Dependencies: anthropic


tool_use_agent.py

Purpose: Demonstrate Claude’s native tool-use (function-calling) API.

What to implement:

  1. Define tool schemas using the tools parameter in the Anthropic messages API.
  2. Include at least: search_documents(query: str), create_note(title: str, body: str), list_notes().
  3. Implement mock backends for each tool.
  4. Run an agentic loop: call Claude → execute any requested tools → feed tool_result messages back → repeat until no more tool calls.
  5. Demonstrate a multi-step task: “Search for X, summarize it, and save a note.”

How to run: python tool_use_agent.py
Dependencies: anthropic