Skip to content

Commit 12becdd

Browse files
authored
Update agentchat tutorial, refactor content (microsoft#4118)
Resolves Tutorial Chapter for Custom ChatAgent microsoft#4114 -- updated tutorial chapter on agents and custom agents Update README example to use tool call Added "Models" section in AgentChat tutorial. Added place holder for Tutorial Chapter for Swarm microsoft#4113.
1 parent 0e985d4 commit 12becdd

File tree

9 files changed

+562
-306
lines changed

9 files changed

+562
-306
lines changed

README.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,32 +101,45 @@ We look forward to your contributions!
101101
First install the packages:
102102

103103
```bash
104-
pip install 'autogen-agentchat==0.4.0.dev4' 'autogen-ext[docker]==0.4.0.dev4'
104+
pip install 'autogen-agentchat==0.4.0.dev4' 'autogen-ext[openai]==0.4.0.dev4'
105105
```
106106

107-
The following code uses code execution, you need to have [Docker installed](https://docs.docker.com/engine/install/)
108-
and running on your machine.
107+
The following code uses OpenAI's GPT-4o model and you need to provide your
108+
API key to run.
109+
To use Azure OpenAI models, follow the instruction
110+
[here](https://microsoft.github.io/autogen/dev/user-guide/core-user-guide/cookbook/azure-openai-with-aad-auth.html).
109111

110112
```python
111113
import asyncio
112-
from autogen_ext.code_executors import DockerCommandLineCodeExecutor
113-
from autogen_ext.models import OpenAIChatCompletionClient
114-
from autogen_agentchat.agents import CodeExecutorAgent, CodingAssistantAgent
114+
from autogen_agentchat.agents import AssistantAgent
115+
from autogen_agentchat.task import Console, TextMentionTermination
115116
from autogen_agentchat.teams import RoundRobinGroupChat
116-
from autogen_agentchat.task import TextMentionTermination, Console
117+
from autogen_ext.models import OpenAIChatCompletionClient
118+
119+
# Define a tool
120+
async def get_weather(city: str) -> str:
121+
return f"The weather in {city} is 73 degrees and Sunny."
117122

118123
async def main() -> None:
119-
async with DockerCommandLineCodeExecutor(work_dir="coding") as code_executor:
120-
code_executor_agent = CodeExecutorAgent("code_executor", code_executor=code_executor)
121-
coding_assistant_agent = CodingAssistantAgent(
122-
"coding_assistant", model_client=OpenAIChatCompletionClient(model="gpt-4o", api_key="YOUR_API_KEY")
123-
)
124-
termination = TextMentionTermination("TERMINATE")
125-
group_chat = RoundRobinGroupChat([coding_assistant_agent, code_executor_agent], termination_condition=termination)
126-
stream = group_chat.run_stream(
127-
task="Create a plot of NVDIA and TSLA stock returns YTD from 2024-01-01 and save it to 'nvidia_tesla_2024_ytd.png'."
128-
)
129-
await Console(stream)
124+
# Define an agent
125+
weather_agent = AssistantAgent(
126+
name="weather_agent",
127+
model_client=OpenAIChatCompletionClient(
128+
model="gpt-4o-2024-08-06",
129+
# api_key="YOUR_API_KEY",
130+
),
131+
tools=[get_weather],
132+
)
133+
134+
# Define termination condition
135+
termination = TextMentionTermination("TERMINATE")
136+
137+
# Define a team
138+
agent_team = RoundRobinGroupChat([weather_agent], termination_condition=termination)
139+
140+
# Run the team and stream messages to the console
141+
stream = agent_team.run_stream(task="What is the weather in New York?")
142+
await Console(stream)
130143

131144
asyncio.run(main())
132145
```

python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/index.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
myst:
33
html_meta:
44
"description lang=en": |
5-
User Guide for AgentChat, a high-level api for AutoGen
5+
User Guide for AgentChat, a high-level API for AutoGen
66
---
77

88
# AgentChat
99

10-
AgentChat is a high-level package for building multi-agent applications built on top of the [ `autogen-core`](../core-user-guide/index.md) package. For beginner users, AgentChat is the recommended starting point. For advanced users, [ `autogen-core`](../core-user-guide/index.md) provides more flexibility and control over the underlying components.
10+
AgentChat is a high-level API for building multi-agent applications.
11+
It is built on top of the [`autogen-core`](../core-user-guide/index.md) package.
12+
For beginner users, AgentChat is the recommended starting point.
13+
For advanced users, [`autogen-core`](../core-user-guide/index.md)'s event-driven
14+
programming model provides more flexibility and control over the underlying components.
1115

12-
AgentChat aims to provide intuitive defaults, such as **Agents** with preset behaviors and **Teams** with predefined communication protocols, to simplify building multi-agent applications.
16+
AgentChat aims to provide intuitive defaults, such as **Agents** with preset
17+
behaviors and **Teams** with predefined [multi-agent design patterns](../core-user-guide/design-patterns/index.md).
18+
to simplify building multi-agent applications.
1319

1420
```{include} warning.md
1521

python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/installation.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ Install the `autogen-agentchat` package using pip:
6464
pip install 'autogen-agentchat==0.4.0.dev4'
6565
```
6666

67+
## Install OpenAI for Model Client
68+
69+
To use the OpenAI and Azure OpenAI models, you need to install the following
70+
extensions:
71+
72+
```bash
73+
pip install 'autogen-ext[openai]==0.4.0.dev4'
74+
```
75+
6776
## Install Docker for Code Execution
6877

6978
We recommend using Docker for code execution.

python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/quickstart.ipynb

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,33 @@
1919
"For installation instructions, please refer to the [installation guide](./installation).\n",
2020
":::\n",
2121
"\n",
22+
"In AutoGen AgentChat, you can build applications quickly using preset agents.\n",
23+
"To illustrate this, we will begin with creating a team of a single agent\n",
24+
"that can use tools and respond to messages.\n",
2225
"\n",
23-
"\n",
24-
"An agent is a software entity that communicates via messages, maintains its own state, and performs actions in response to received messages or changes in its state. \n",
25-
"\n",
26-
"In AgentChat, agents can be rapidly implemented using preset agent configurations. To illustrate this, we will begin with creating an agent that can address tasks by responding to messages it receives. "
26+
"The following code uses the OpenAI model. If you haven't already, you need to\n",
27+
"install the following package and extension:"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"execution_count": null,
33+
"metadata": {
34+
"vscode": {
35+
"languageId": "shellscript"
36+
}
37+
},
38+
"outputs": [],
39+
"source": [
40+
"pip install 'autogen-agentchat==0.4.0.dev4' 'autogen-ext[openai]==0.4.0.dev4'"
41+
]
42+
},
43+
{
44+
"cell_type": "markdown",
45+
"metadata": {},
46+
"source": [
47+
"To use Azure OpenAI models and AAD authentication,\n",
48+
"you can follow the instructions [here](./tutorial/models.ipynb#azure-openai)."
2749
]
2850
},
2951
{
@@ -73,7 +95,10 @@
7395
" # Define an agent\n",
7496
" weather_agent = AssistantAgent(\n",
7597
" name=\"weather_agent\",\n",
76-
" model_client=OpenAIChatCompletionClient(model=\"gpt-4o-2024-08-06\"),\n",
98+
" model_client=OpenAIChatCompletionClient(\n",
99+
" model=\"gpt-4o-2024-08-06\",\n",
100+
" # api_key=\"YOUR_API_KEY\",\n",
101+
" ),\n",
77102
" tools=[get_weather],\n",
78103
" )\n",
79104
"\n",
@@ -83,7 +108,7 @@
83108
" # Define a team\n",
84109
" agent_team = RoundRobinGroupChat([weather_agent], termination_condition=termination)\n",
85110
"\n",
86-
" # Run the team and stream messages\n",
111+
" # Run the team and stream messages to the console\n",
87112
" stream = agent_team.run_stream(task=\"What is the weather in New York?\")\n",
88113
" await Console(stream)\n",
89114
"\n",
@@ -96,7 +121,8 @@
96121
"cell_type": "markdown",
97122
"metadata": {},
98123
"source": [
99-
"The code snippet above introduces two high level concepts in AgentChat: `Agent` and `Team`. An Agent helps us define what actions are taken when a message is received. Specifically, we use the `AssistantAgent` preset - an agent that can be given tools (functions) that it can then use to address tasks. A Team helps us define the rules for how agents interact with each other. In the `RoundRobinGroupChat` team, agents receive messages in a sequential round-robin fashion. "
124+
"The code snippet above introduces two high level concepts in AgentChat: *Agent* and *Team*. An Agent helps us define what actions are taken when a message is received. Specifically, we use the {py:class}`~autogen_agentchat.agents.AssistantAgent` preset - an agent that can be given access to a model (e.g., LLM) and tools (functions) that it can then use to address tasks. A Team helps us define the rules for how agents interact with each other. In the {py:class}`~autogen_agentchat.teams.RoundRobinGroupChat` team, agents respond in a sequential round-robin fashion.\n",
125+
"In this case, we have a single agent, so the same agent is used for each round."
100126
]
101127
},
102128
{

0 commit comments

Comments
 (0)