Skip to content

About

A lightweight Python AI agent implementing the ReAct (Reasoning and Acting) pattern. Powered by Claude and equipped with weather and search tools for travel planning.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

🤖 Simple Claude ReAct Agent

This is a lightweight AI Agent example built with Python. It implements the classic ReAct (Reasoning and Acting) pattern, enabling large language models to solve complex tasks through a continuous "Thought -> Action -> Observation" loop.

This project is designed around a "Smart Travel Assistant" scenario, utilizing the Anthropic Claude API as the reasoning engine and integrating external tools to fetch real-time data.

✨ Features

  • ReAct Core Loop: Demonstrates how to guide the LLM via system prompts to generate structured Thought and Action responses, which are then automatically parsed and executed by the script.
  • Tool Use:
    • 🌤️ Real-time Weather: Fetches current weather conditions via wttr.in (No API key required).
    • 🔍 Web Search Integration: Integrates the Tavily Search API to gather optimized, LLM-friendly attraction recommendations based on the weather.
  • Infinite Loop Prevention: Built-in maximum loop count (default is 5) to prevent runaway processes and unnecessary API costs.
  • Robust Regex Parsing: Utilizes regular expressions to accurately extract and truncate action instructions from the model's output.

🛠️ Getting Started

1. Prerequisites

Ensure you have Python 3.8 or higher installed. It is highly recommended to use a virtual environment.

python -m venv venv
source venv/bin/activate  # On Windows use: venv\Scripts\activate

2. Install Dependencies
    pip install anthropic tavily-python requests

3. Configure Environment Variables
    export ANTHROPIC_API_KEY="your-anthropic-api-key"
    export TAVILY_API_KEY="your-tavily-api-key"

4. Usage
python agent.py

About

A lightweight Python AI agent implementing the ReAct (Reasoning and Acting) pattern. Powered by Claude and equipped with weather and search tools for travel planning.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages