A chain-of-thought AI agent powered by Google Gemini that can fetch weather information and execute system commands through natural language queries.
- 🤖 Chain-of-thought reasoning with structured planning
- 🌤️ Real-time weather information using wttr.in API
- 💻 System command execution capability
- 🔄 Automatic tool selection and execution
- ⚡ Rate limiting to prevent API quota exhaustion
- 📝 JSON-structured responses using Pydantic models
- Python 3.8+
- Google Gemini API key
- Clone the repository:
git clone https://github.com/jaya6400/weather_agent_ai_app.git
cd weather_agent_ai_app- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install google-genai python-dotenv requests pydantic- Create a
.envfile in the project root:
GEMINI_API_KEY=your_gemini_api_key_here
Run the agent:
python file.py👉🏻 what is the weather in ranchi
🧠 Step 1: User needs Ranchi weather. Will call get_weather tool.
🛠️ Step 2: Calling get_weather(ranchi)
↳ Result: The weather in ranchi is Clear 15°C
🤖 Step 3: The current weather in Ranchi is Clear with a temperature of 15°C.
👉🏻 what is the weather in delhi
👉🏻 solve 2 + 3 * 5
The agent follows a 3-step chain-of-thought process:
- PLAN: Analyzes the user query and determines the action needed
- TOOL: Executes the appropriate tool (get_weather or run_command)
- OUTPUT: Returns the final result to the user
get_weather(city: str): Fetches current weather information for a cityrun_command(cmd: str): Executes system commands (use with caution)
The agent includes built-in rate limiting:
- 1-second delay between API calls
- Automatic retry with 10-second wait on 429 errors
- Maximum 5 steps per query to prevent infinite loops
weather_agent_ai_app/
├── agent.py # Main agent script
├── .env # Environment variables (API keys)
├── .gitignore # Git ignore file
└── README.md # This file
You can modify these settings in agent.py:
max_steps = 5: Maximum iterations per querytime.sleep(1): Delay between API calls (in seconds)model="gemini-2.0-flash-exp": Gemini model to use
run_command tool can execute system commands. Use with caution and avoid running untrusted commands.
Rate Limit Errors (429):
- The agent automatically handles these with retries
- If persistent, increase the delay in
time.sleep()
API Key Issues:
- Ensure your
.envfile contains a validGEMINI_API_KEY - Get your API key from Google AI Studio
MIT License
Contributions are welcome! Please feel free to submit a Pull Request.
- Powered by Google Gemini
- Weather data from wttr.in