from smolagents import Tool from datetime import datetime import pytz class TimeZoneConversionTool(Tool): name = "timezone_converter" description = "Converts time between two time zones." inputs = { "time": {"type": "string", "description": "Time in 'YYYY-MM-DD HH:MM' format"}, "from_timezone": {"type": "string", "description": "Original time zone"}, "to_timezone": {"type": "string", "description": "Target time zone"} } output_type = "string" def forward(self, time: str, from_timezone: str, to_timezone: str): from_zone = pytz.timezone(from_timezone) to_zone = pytz.timezone(to_timezone) naive_time = datetime.strptime(time, "%Y-%m-%d %H:%M") local_time = from_zone.localize(naive_time) converted_time = local_time.astimezone(to_zone) return converted_time.strftime("%Y-%m-%d %H:%M")