import os
import autogen
from typing import Annotated
from autogen import register_function
llm_config = {
"config_list": [{
"model": "gemini-2.5-flash",
"api_key": os.environ["GEMINI_API_KEY"],
"api_type": "google"
}]
}
assistant = autogen.AssistantAgent(
name="assistant",
llm_config=llm_config
)
user_proxy = autogen.UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER",
max_consecutive_auto_reply=5
)
def get_weather(city: Annotated[str, "City name"]) -> str:
"""Get current weather for a city."""
return f"The weather in {city} is 72 degrees and sunny."
def get_forecast(city: Annotated[str, "City name"], days: Annotated[int, "Number of days"]) -> str:
"""Get a multi-day weather forecast for a city."""
return f"{days}-day forecast for {city}: mostly sunny with highs around 70-75°F."
# Register tools — caller decides when to use them, executor runs the function
register_function(
get_weather,
caller=assistant,
executor=user_proxy,
name="get_weather",
description="Get current weather for a city",
)
register_function(
get_forecast,
caller=assistant,
executor=user_proxy,
name="get_forecast",
description="Get a multi-day weather forecast for a city",
)
# The entire conversation hierarchy is automatically traced
user_proxy.initiate_chat(
assistant,
message="What's the weather in Tokyo today, and what does the 3-day forecast look like?",
)