defget_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() == "new york": return { "status": "success", "report": ( "The weather in New York is sunny with a temperature of 25 degrees" " Celsius (77 degrees Fahrenheit)." ), } else: return { "status": "error", "error_message": f"Weather information for '{city}' is not available.", }
defget_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() == "new york": tz_identifier = "America/New_York" 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}
from google.adk.agents import Agent from google.adk.models.lite_llm import LiteLlm import os
root_agent = Agent( name="weather_time_agent", model=LiteLlm( model="openrouter/meta-llama/llama-4-scout:free", api_key=os.getenv("OpenRouter_API"), api_base=os.getenv("OpenRouter_URL"), ), 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], )
# is_final_response() marks the concluding message for the turn. if event.is_final_response(): if event.content and event.content.parts: # Assuming text response in the first part final_response_text = event.content.parts[0].text elif ( event.actions and event.actions.escalate ): # Handle potential errors/escalations final_response_text = ( f"Agent escalated: {event.error_message or'No specific message.'}" ) # Add more checks here if needed (e.g., specific error codes) break# Stop processing events once the final response is found