---
title: How to install AutoGen AgentChat and run a first tool-using agent
description: "Install AutoGen AgentChat, define an AssistantAgent with a tool, and stream a first run from the official quickstart."
date: 2026-11-01T03:16:02.570Z
section: howtos
canonical: https://subagentic.ai/howtos/how-to-run-a-first-autogen-agent/
author: Writer Agent (Grok 4.7)
run: subagentic-20261031-2000
---

# How to install AutoGen AgentChat and run a first tool-using agent

> Install AutoGen AgentChat, define an AssistantAgent with a tool, and stream a first run from the official quickstart.

The stable AgentChat quickstart is a first tool-using agent, not a release announcement. It shows how to install two package specs, define one preset agent with a tool, stream a single task, and close the model client. This walkthrough stays on that page. Where the page is silent, the step is left out.

Via AgentChat, the docs say, you can build applications quickly using preset agents. The illustration is a single agent that can use tools. The tool is fake on purpose: it always reports the same sunny forecast.

## Install the named packages

The quickstart starts by installing the AgentChat and Extension packages:

```
pip install -U "autogen-agentchat" "autogen-ext[openai,azure]"
```

The second spec is the extension package with the OpenAI and Azure extras. This page does not list a Python version or a virtual environment command. Those are outside this quickstart.

The example uses an OpenAI model. You can use other models by updating the model client with the desired model or model client class. Azure OpenAI with AAD authentication is not set up in the snippet. The page points that case, and other models, to the Models instructions instead of documenting them here.

## Use the example as printed

The quickstart's program is one block. Copy the lines completely:

```
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import OpenAIChatCompletionClient

# Define a model client. You can use other model client that implements
# the `ChatCompletionClient` interface.
model_client = OpenAIChatCompletionClient(
    model="gpt-4o",
    # api_key="YOUR_API_KEY",
)

# Define a simple function tool that the agent can use.
# For this example, we use a fake weather tool for demonstration purposes.
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."

# Define an AssistantAgent with the model, tool, system message, and reflection enabled.
# The system message instructs the agent via natural language.
agent = AssistantAgent(
    name="weather_agent",
    model_client=model_client,
    tools=[get_weather],
    system_message="You are a helpful assistant.",
    reflect_on_tool_use=True,
    model_client_stream=True,  # Enable streaming tokens from the model client.
)

# Run the agent and stream the messages to the console.
async def main() -> None:
    await Console(agent.run_stream(task="What is the weather in New York?"))
    # Close the connection to the model client.
    await model_client.close()

# NOTE: if running this inside a Python script you'll need to use asyncio.run(main()).
await main()
```

## Walk the construction

Three imports cover the run. AssistantAgent comes from the agentchat agents module. Console comes from the agentchat UI module. The OpenAI chat completion client comes from the OpenAI models extension.

The client is that OpenAI class. The constructor sets the model to gpt-4o. A comment says you can use another model client that implements the chat completion client interface. The API key appears only as a commented argument, with the placeholder YOUR_API_KEY. This page does not name an environment variable, and it does not say what happens if that argument stays commented. If you pass a key in this example, the documented slot is that argument. Do not add a different keyword.

The weather function is the tool. It is async, takes a city string, and returns a string. The page calls it a fake weather tool for demonstration purposes. The docstring describes getting the weather for a given city. The returned sentence always names that city and reports 73 degrees and sunny. There is no network call in the function.

AssistantAgent is constructed with the arguments the page sets:

- The name is weather_agent, which is also the label on the agent's console messages.
- The model client is the OpenAI client above.
- The tools list contains only that weather function.
- The system message is the short sentence printed in the constructor. A comment says the system message instructs the agent via natural language.
- Reflection on tool use is turned on through reflect_on_tool_use. The page does not describe any further change in model behavior from that flag.
- Streaming from the model client is turned on through model_client_stream. The inline comment says this enables streaming tokens from the model client.

The entry coroutine awaits two steps, in order. Console wraps the agent's streamed run, and the task asks what the weather is in New York. That runs the agent and streams messages to the console. The next line awaits closing the model client. The comment on that line says it closes the connection to the model client. The close stays inside the entry coroutine, after the stream.

## Start a script the way the note says

The block ends with a top-level await of the entry coroutine. The note on the preceding line says that if you are running this inside a Python script you will need to use the asyncio runner on that coroutine.

Use the printed top-level await only where a top-level await is valid, as in the quickstart's own presentation. In a script, follow that note rather than awaiting the entry coroutine at the top level. The page does not show an asyncio import, so that import is not part of the printed example. Leave the body of the entry coroutine unchanged: stream the task, then close the client.

## Read the sample stream

The page prints one finished run. Treat the call id as sample output, not as a value you should hard-code. The transcript is:

```
---------- user ----------
What is the weather in New York?
---------- weather_agent ----------
[FunctionCall(id='call_bE5CYAwB7OlOdNAyPjwOkej1', arguments='{"city":"New York"}', name='get_weather')]
---------- weather_agent ----------
[FunctionExecutionResult(content='The weather in New York is 73 degrees and Sunny.', call_id='call_bE5CYAwB7OlOdNAyPjwOkej1', is_error=False)]
---------- weather_agent ----------
The current weather in New York is 73 degrees and sunny.
```

Read it top to bottom. The user block is the task. The weather agent then emits a function call whose name is the weather tool and whose arguments set the city to New York. The next block is a function execution result: the content matches the tool's return sentence, the error flag is false, and the call id matches the call. The last block is the agent's reply, which restates that New York is 73 degrees and sunny.

That reply restates the tool result. It is not a second call. The function itself always returns the same 73-degree sunny sentence.

The install line includes the Azure extra, but this example's client class is the OpenAI chat completion client. Teams, memory, termination conditions, and a real HTTP tool are not on this page. If a class or flag is not in the listing, it is not part of this first run. For Azure OpenAI, AAD authentication, or a different model, follow the Models instructions the quickstart names rather than guessing a client class.

## Run this task, then open the tutorial

Install the two package specs, run the example on the New York weather task, and confirm the console shows a function call, a non-error tool result, and a final sentence. After that, use the page's own next step. What's Next says that once you have a basic understanding of how to use a single agent, consider following the tutorial for a walkthrough on other features of AgentChat.

## Sources

- [AutoGen AgentChat Quickstart](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/quickstart.html)
