🌦️ Weather Vibes Agent Cookbook
Learn how to build an Agentic System for a smart weather application in a Python-based tech stack.
Overview
This cookbook demonstrates how to build an agentic system for a smart weather application in a Python-based tech stack. We’ll create a Weather Vibes agent that not only gets the weather, but recommends a song to set the mood based on the weather. Thanks to Galileo’s Python SDK we’ll be able to check the application’s performance and tool selection.
What you’ll build:
A command-line agent that:
- Fetches current weather for any location
- Generates item recommendations based on the weather
- Finds YouTube videos matching the weather mood
- Captures detailed traces and metrics for analysis
What you’ll learn:
- Building multi-service AI agents
- Integrating with external APIs
- Analyzing agent performance
The application leverages multiple tools to create its final end result.
- Umbrella Decider - determines if you should/should not take an umbrella.
- Weather Retriever - gets the current weather based on geographic location
- YouTube Retriever - calls the YouTube API key guided by a prompt to retrieve a video that represents the current “vibes” of the weather.
Finally, we’ll run this application to demonstrate Galileo’s Agent Evaluation functionality, where it will determine the success of each run and tool call.
Requirements
- Python package manager + some familiarity with Python (for the sake of this cookbook, we’ll use UV)
- OpenAI Key to assist get one here
- WeatherAPI Key get a free key here
- YouTube Data API Key get a free key here
- A free Galileo Developer Account
Note, this cookbook assumes that you have already created an account on https://app.galileo.ai — if you haven’t, take a moment to create your account, and subsequently create a new project.
Your project name will become the GALILEO_PROJECT_KEY, while your log stream will become the GALILEO_LOG_STREAM. If you left it as default, the log stream key will be my-log-stream
.
Sample Application
To see a completed version of this application and other examples using the Galileo SDK, check out our SDK Examples Repository
Environment Setup
Ingredients:
- git
- Python environment tools
- Package manager (pip or uv)
Steps:
-
Clone the repository:
-
Create a virtual environment: on Windows
on Mac Using a standard virtual environment
Or using uv (faster)
-
Install dependencies: Using pip
OR using uv
-
Create a .env file in the project root:
Understanding the Agent Architecture
The Weather Vibes Agent consists of several key components:
đź§ Agent Core (agent/weather_vibes_agent.py
)
Handles the main agent logic, coordinates tools, and processes requests.
🛠️ Tools
Specialized modules for specific tasks:
- Weather Tool (
tools/weather_tool.py
): Fetches weather data from WeatherAPI - Recommendations Tool (
tools/recommendation_tool.py
): Generates weather-appropriate item suggestions - YouTube Tool (
tools/youtube_tool.py
): Finds videos matching the weather mood
📝 Descriptor (descriptor.py
)
Defines the agent’s capabilities, inputs, outputs, and configuration in a format that the OpenAI model can understand.
🔍 Instrumentation (agent.py
)
Wraps the agent with Galileo monitoring for observability.
đź“‘ Templates (templates/
)
Contains Jinja templates for generating system prompts.
Main Agent Workflow
The main workflow in agent.py
ties everything together and adds Galileo instrumentation.
Key Ingredients:
- Galileo context
- Logging decorators
- Workflow spans
- Error handling
How it works:
-
Setting Up the Context:
-
Creating the Main Span:
-
Creating the Workflow Span:
-
Tool Execution: Each tool call is wrapped with its own span.
-
Result Aggregation: Results from all tools are combined into a single response.
Galileo’s Role: Galileo creates a hierarchical trace structure:
- The entrypoint span contains the entire run
- The workflow span tracks the main agent logic
- Individual tool spans track specific operations
- Metadata captures important context
This lets you analyze the complete flow and identify bottlenecks or errors.
The Weather Tool
Let’s examine the Weather Tool to understand how it works and where Galileo fits in.
Key Ingredients:
- WeatherAPI
- Async HTTP requests
- Error handling
- Response parsing
How it works:
-
API Integration: The tool makes requests to the WeatherAPI to get current weather data.
-
Request Formatting:
-
Response Processing: The tool extracts and formats relevant information from the API response:
-
Error Handling: The tool includes robust error handling to gracefully manage API failures.
Where Galileo Comes In:
The tool itself doesn’t directly use Galileo. Instead, the main agent.py
wraps the tool execution with Galileo’s @log
decorator:
This creates a span in Galileo that:
- Captures the input location and units
- Records the tool’s output
- Measures execution time
- Tracks any errors
The Recommendations Tool
This tool generates clothing and item recommendations based on weather conditions.
Key Ingredients:
- OpenAI API
- Weather condition mapping
- JSON response parsing
How it works:
-
Prompt Engineering: The tool constructs a prompt for the LLM using the weather data:
-
LLM Integration: The tool calls OpenAI from within the Galileo Python SDK to generate recommendations. The default is to use GPT 4o for its success in tool-calling, however feel free to use whatever model suits your fancy. Do note that every model will have its own strengths and weaknesses.
-
Response Parsing: The tool processes the LLM’s response to extract a clean list of recommendations.
Galileo Integration: Similar to the Weather Tool, recommendations are traced with:
This allows you to analyze:
- How different weather inputs affect recommendations
- LLM response quality
- Processing time
See this within the Galileo log stream as pictured below.
The YouTube Tool
This tool finds videos that match the current weather condition or mood.
Key Ingredients:
- YouTube Data API
- Weather-to-mood mapping
- Search query construction
How it works:
-
Mood Mapping: The tool maps weather conditions to appropriate moods:
-
Query Construction: The tool builds a YouTube search query:
-
API Integration: The tool searches YouTube and selects an appropriate video.
Galileo Integration: Like the other tools, YouTube searches are traced with:
This helps you monitor:
- YouTube API success rate
- Query effectiveness
- Response times
We can see the results of the YouTube tool by opening up an individual span within the Galileo application and reviewing the tool selection, and latency of the tool call.
Running the Agent
Now that you understand how it all works, let’s run the agent!
Steps:
-
Basic Usage:
-
Advanced Options:
-
Expected Output: You should see:
- Weather information for the specified location
- Recommendations based on the weather
- A YouTube video matching the weather mood
- Confirmation that Galileo traces have been collected
Viewing Traces in Galileo
Now it’s time to see the results of our instrumentation in Galileo!
Steps:
-
Log into Galileo: Visit app.galileo.ai and log in.
-
View Your Traces:
- Navigate to the Traces section
- Look for the
weather_vibes_agent
log stream - Click on a recent trace
-
Explore the Hierarchy: You’ll see a visualization showing:
- The main entrypoint span
- The workflow span
- Individual tool spans
-
Analyze Performance: In the trace view, you can:
- See the execution time for each component
- View the input and output data
- Identify any errors or warnings
- Compare multiple runs
-
Identify Optimization Opportunities: Look for:
- Slow API calls
- Bottlenecks in the workflow
- Error patterns
- Response quality issues
Extending the Agent
Want to make the Weather Vibes Agent even better? Here are some ideas:
Add New Tools
Create a new tool file in the tools/
directory:
Add More Instrumentation
Add custom metrics to your Galileo spans:
Implement Caching
Add caching to improve performance:
Conclusion
You’ve now learned how to build, run, and monitor the Weather Vibes Agent with Galileo!
Key Takeaways:
- Multi-tool agents can combine various APIs into a unified experience
- Galileo observability provides valuable insights into agent performance
- Well-structured tracing helps identify issues and optimization opportunities
Next Steps:
- Check out the Galileo YouTube Channel to see what you can build!
- Star the Galileo SDK-examples repoto bookmark more ways to get started with the Galileo SDK.
- Follow Galileo on LinkedIn to stay in touch with the latest news and resources.
Happy building! 🚀
Common Issues and Solutions
Here are some problems you might encounter and how to fix them:
Import Errors
Problem: ModuleNotFoundError: No module named 'weather_vibes'
Solution:
- Fix the imports in
agent/weather_vibes_agent.py
- Or create a symbolic link:
ln -s . weather_vibes
API Key Issues
Problem: “Invalid API key” errors
Solution:
- Double-check your
.env
file - For OpenWeatherMap, new keys take a few hours to activate
- For YouTube, ensure the API is enabled in Google Cloud Console
Template Issues
Problem: Jinja template errors
Solution:
Galileo Connection Issues
Problem: Traces aren’t showing up in Galileo
Solution:
- Confirm your API key is valid
- Check internet connectivity
- Ensure
flush()
is being called at the end of execution