Skip to content

Instantly share code, notes, and snippets.

@marttp
Created June 20, 2025 02:07
Show Gist options
  • Save marttp/2b924b1ed483858203a99270f9325c12 to your computer and use it in GitHub Desktop.
Save marttp/2b924b1ed483858203a99270f9325c12 to your computer and use it in GitHub Desktop.
import datetime
from zoneinfo import ZoneInfo
from google.adk.agents import Agent
def get_weather(city: str) -> dict:
"""Retrieves the current weather report for a specified city.
Args:
city (str): The name of the city for which to retrieve the weather report.
Returns:
dict: status and result or error msg.
"""
if city.lower() == "bangkok":
return {
"status": "success",
"report": (
"The weather in Bangkok is hot and humid with a temperature of 32 degrees"
" Celsius (90 degrees Fahrenheit)."
),
}
else:
return {
"status": "error",
"error_message": f"Weather information for '{city}' is not available.",
}
def get_current_time(city: str) -> dict:
"""Returns the current time in a specified city.
Args:
city (str): The name of the city for which to retrieve the current time.
Returns:
dict: status and result or error msg.
"""
if city.lower() == "bangkok":
tz_identifier = "Asia/Bangkok"
else:
return {
"status": "error",
"error_message": (f"Sorry, I don't have timezone information for {city}."),
}
tz = ZoneInfo(tz_identifier)
now = datetime.datetime.now(tz)
report = f'The current time in {city} is {now.strftime("%Y-%m-%d %H:%M:%S %Z%z")}'
return {"status": "success", "report": report}
root_agent = Agent(
name="weather_time_agent",
model="gemini-2.0-flash",
description=("Agent to answer questions about the time and weather in a city."),
instruction=(
"You are a helpful agent who can answer user questions about the time and weather in a city."
),
tools=[get_weather, get_current_time],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment