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:
- Define 2–3 simple tools as Python functions (e.g.
web_search(query)→ fake results,calculator(expr)→ eval result,get_weather(city)→ hardcoded response). - 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).
- Cap the loop at 10 iterations to prevent runaway execution.
- 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:
- Define tool schemas using the
toolsparameter in the Anthropic messages API. - Include at least:
search_documents(query: str),create_note(title: str, body: str),list_notes(). - Implement mock backends for each tool.
- Run an agentic loop: call Claude → execute any requested tools → feed
tool_resultmessages back → repeat until no more tool calls. - Demonstrate a multi-step task: “Search for X, summarize it, and save a note.”
How to run: python tool_use_agent.py
Dependencies: anthropic