Quickstart#
Via AgentChat, you can build applications quickly using preset agents. To illustrate this, we will begin with creating a single tool-use agent.
pip install -U "autogen-ext[openai,azure]"
To use Azure OpenAI models and AAD authentication, you can follow the instructions here.
To use other models, see Models.
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import OpenAIChatCompletionClient
# Define a tool
async def get_weather(city: str) -> str:
"""Get the weather for a given city."""
return f"The weather in {city} is 73 degrees and Sunny."
async def main() -> None:
agent = AssistantAgent(
name="weather_agent",
model_client=OpenAIChatCompletionClient(
model="gpt-4o",
# api_key="YOUR_API_KEY",
),
tools=[get_weather],
system_message="You are a helpful assistant.",
reflect_on_tool_use=True,
)
await Console(agent.run_stream(task="What is the weather in New York?"))
# NOTE: if running this inside a Python script you'll need to use asyncio.run(main()).
await main()
---------- user ----------
What is the weather in New York?
---------- weather_agent ----------
[FunctionCall(id='call_ciy1Ecys9LH201cyim10xlnQ', arguments='{"city":"New York"}', name='get_weather')]
---------- weather_agent ----------
[FunctionExecutionResult(content='The weather in New York is 73 degrees and Sunny.', call_id='call_ciy1Ecys9LH201cyim10xlnQ')]
---------- weather_agent ----------
The weather in New York is currently 73 degrees and sunny.
What’s Next?#
Now that you have a basic understanding of how to define an agent, consider following the tutorial for a walkthrough on other features of AgentChat.