class WeatherTool(BaseTool): """A tool for retrieving weather information""" def get_name(self) -> str: return "get_weather" def get_description(self) -> str: return "Retrieves current weather information for a specified city. Use this when users ask about weather conditions, temperature, or forecasts." def get_parameters(self) -> Dict[str, Any]: return { "type": "object", "properties": { "city": { "type": "string", "description": "The city name (e.g., 'New York', 'London', 'Tokyo')" }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"], "description": "Temperature unit preference" } }, "required": ["city"] } def execute(self, city: str, unit: str = "celsius") -> Dict[str, Any]: """ Simulates weather data retrieval. In production, this would call a real weather API. """ # Simulated weather data weather_database = { "new york": {"temp": 22, "condition": "Partly cloudy", "humidity": 65}, "london": {"temp": 15, "condition": "Rainy", "humidity": 80}, "tokyo": {"temp": 28, "condition": "Sunny", "humidity": 55}, "paris": {"temp": 18, "condition": "Overcast", "humidity": 70}, } city_key = city.lower() if city_key not in weather_database: return { "error": f"Weather data not available for {city}", "available_cities": list(weather_database.keys()) } data = weather_database[city_key] temp = data["temp"] # Convert temperature if needed if unit == "fahrenheit": temp = (temp * 9/5) + 32 return { "city": city, "temperature": round(temp, 1), "unit": unit, "condition": data["condition"], "humidity": data["humidity"] } __ __