-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
337 additions
and
360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
308 changes: 150 additions & 158 deletions
308
python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/quickstart.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,160 +1,152 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Quickstart" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"```{include} warning.md\n", | ||
"\n", | ||
"```\n", | ||
"\n", | ||
":::{note}\n", | ||
"For installation instructions, please refer to the [installation guide](./installation).\n", | ||
":::\n", | ||
"\n", | ||
"In AutoGen AgentChat, you can build applications quickly using preset agents.\n", | ||
"To illustrate this, we will begin with creating a team of a single agent\n", | ||
"that can use tools and respond to messages.\n", | ||
"\n", | ||
"The following code uses the OpenAI model. If you haven't already, you need to\n", | ||
"install the following package and extension:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "shellscript" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"pip install 'autogen-agentchat==0.4.0.dev8' 'autogen-ext[openai]==0.4.0.dev8'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"To use Azure OpenAI models and AAD authentication,\n", | ||
"you can follow the instructions [here](./tutorial/models.ipynb#azure-openai)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"---------- user ----------\n", | ||
"What is the weather in New York?\n", | ||
"---------- weather_agent ----------\n", | ||
"[FunctionCall(id='call_AhTZ2q3TNL8x0qs00e3wIZ7y', arguments='{\"city\":\"New York\"}', name='get_weather')]\n", | ||
"[Prompt tokens: 79, Completion tokens: 15]\n", | ||
"---------- weather_agent ----------\n", | ||
"[FunctionExecutionResult(content='The weather in New York is 73 degrees and Sunny.', call_id='call_AhTZ2q3TNL8x0qs00e3wIZ7y')]\n", | ||
"---------- weather_agent ----------\n", | ||
"The weather in New York is currently 73 degrees and sunny.\n", | ||
"[Prompt tokens: 90, Completion tokens: 14]\n", | ||
"---------- weather_agent ----------\n", | ||
"TERMINATE\n", | ||
"[Prompt tokens: 137, Completion tokens: 4]\n", | ||
"---------- Summary ----------\n", | ||
"Number of messages: 5\n", | ||
"Finish reason: Text 'TERMINATE' mentioned\n", | ||
"Total prompt tokens: 306\n", | ||
"Total completion tokens: 33\n", | ||
"Duration: 1.43 seconds\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from autogen_agentchat.agents import AssistantAgent\n", | ||
"from autogen_agentchat.task import Console, TextMentionTermination\n", | ||
"from autogen_agentchat.teams import RoundRobinGroupChat\n", | ||
"from autogen_ext.models import OpenAIChatCompletionClient\n", | ||
"\n", | ||
"\n", | ||
"# Define a tool\n", | ||
"async def get_weather(city: str) -> str:\n", | ||
" return f\"The weather in {city} is 73 degrees and Sunny.\"\n", | ||
"\n", | ||
"\n", | ||
"async def main() -> None:\n", | ||
" # Define an agent\n", | ||
" weather_agent = AssistantAgent(\n", | ||
" name=\"weather_agent\",\n", | ||
" model_client=OpenAIChatCompletionClient(\n", | ||
" model=\"gpt-4o-2024-08-06\",\n", | ||
" # api_key=\"YOUR_API_KEY\",\n", | ||
" ),\n", | ||
" tools=[get_weather],\n", | ||
" )\n", | ||
"\n", | ||
" # Define termination condition\n", | ||
" termination = TextMentionTermination(\"TERMINATE\")\n", | ||
"\n", | ||
" # Define a team\n", | ||
" agent_team = RoundRobinGroupChat([weather_agent], termination_condition=termination)\n", | ||
"\n", | ||
" # Run the team and stream messages to the console\n", | ||
" stream = agent_team.run_stream(task=\"What is the weather in New York?\")\n", | ||
" await Console(stream)\n", | ||
"\n", | ||
"\n", | ||
"# NOTE: if running this inside a Python script you'll need to use asyncio.run(main()).\n", | ||
"await main()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"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", | ||
"In this case, we have a single agent, so the same agent is used for each round." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## What's Next?\n", | ||
"\n", | ||
"Now that you have a basic understanding of how to define an agent and a team, consider following the [tutorial](./tutorial/index) for a walkthrough on other features of AgentChat.\n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Quickstart" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Via AgentChat, you can build applications quickly using preset agents.\n", | ||
"To illustrate this, we will begin with creating a team of a single agent\n", | ||
"that can use tools and respond to messages.\n", | ||
"\n", | ||
"The following code uses the OpenAI model. If you haven't already, you need to\n", | ||
"install the following package and extension:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "shellscript" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"pip install 'autogen-agentchat==0.4.0.dev8' 'autogen-ext[openai]==0.4.0.dev8'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"To use Azure OpenAI models and AAD authentication,\n", | ||
"you can follow the instructions [here](./tutorial/models.ipynb#azure-openai)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"---------- user ----------\n", | ||
"What is the weather in New York?\n", | ||
"---------- weather_agent ----------\n", | ||
"[FunctionCall(id='call_AhTZ2q3TNL8x0qs00e3wIZ7y', arguments='{\"city\":\"New York\"}', name='get_weather')]\n", | ||
"[Prompt tokens: 79, Completion tokens: 15]\n", | ||
"---------- weather_agent ----------\n", | ||
"[FunctionExecutionResult(content='The weather in New York is 73 degrees and Sunny.', call_id='call_AhTZ2q3TNL8x0qs00e3wIZ7y')]\n", | ||
"---------- weather_agent ----------\n", | ||
"The weather in New York is currently 73 degrees and sunny.\n", | ||
"[Prompt tokens: 90, Completion tokens: 14]\n", | ||
"---------- weather_agent ----------\n", | ||
"TERMINATE\n", | ||
"[Prompt tokens: 137, Completion tokens: 4]\n", | ||
"---------- Summary ----------\n", | ||
"Number of messages: 5\n", | ||
"Finish reason: Text 'TERMINATE' mentioned\n", | ||
"Total prompt tokens: 306\n", | ||
"Total completion tokens: 33\n", | ||
"Duration: 1.43 seconds\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from autogen_agentchat.agents import AssistantAgent\n", | ||
"from autogen_agentchat.task import Console, TextMentionTermination\n", | ||
"from autogen_agentchat.teams import RoundRobinGroupChat\n", | ||
"from autogen_ext.models import OpenAIChatCompletionClient\n", | ||
"\n", | ||
"\n", | ||
"# Define a tool\n", | ||
"async def get_weather(city: str) -> str:\n", | ||
" return f\"The weather in {city} is 73 degrees and Sunny.\"\n", | ||
"\n", | ||
"\n", | ||
"async def main() -> None:\n", | ||
" # Define an agent\n", | ||
" weather_agent = AssistantAgent(\n", | ||
" name=\"weather_agent\",\n", | ||
" model_client=OpenAIChatCompletionClient(\n", | ||
" model=\"gpt-4o-2024-08-06\",\n", | ||
" # api_key=\"YOUR_API_KEY\",\n", | ||
" ),\n", | ||
" tools=[get_weather],\n", | ||
" )\n", | ||
"\n", | ||
" # Define termination condition\n", | ||
" termination = TextMentionTermination(\"TERMINATE\")\n", | ||
"\n", | ||
" # Define a team\n", | ||
" agent_team = RoundRobinGroupChat([weather_agent], termination_condition=termination)\n", | ||
"\n", | ||
" # Run the team and stream messages to the console\n", | ||
" stream = agent_team.run_stream(task=\"What is the weather in New York?\")\n", | ||
" await Console(stream)\n", | ||
"\n", | ||
"\n", | ||
"# NOTE: if running this inside a Python script you'll need to use asyncio.run(main()).\n", | ||
"await main()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"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", | ||
"In this case, we have a single agent, so the same agent is used for each round." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## What's Next?\n", | ||
"\n", | ||
"Now that you have a basic understanding of how to define an agent and a team, consider following the [tutorial](./tutorial/index) for a walkthrough on other features of AgentChat.\n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.