Skip to content

A programming framework for agentic AI

Update agentchat quickstart to show how to handle multi-round user inputs (#4735)

Eric Zhu4bce1e914ac8
diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/quickstart.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/quickstart.ipynb
index cb2668162..a82ebed46 100644
--- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/quickstart.ipynb
+++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/quickstart.ipynb
@@ -12,8 +12,8 @@
"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",
+ "To illustrate this, we will begin with creating a team of a single tool-use\n",
+ "agent that you can chat with.\n",
"\n",
"The following code uses the OpenAI model. If you haven't already, you need to\n",
"install the following package and extension:"
@@ -42,7 +42,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {},
"outputs": [
{
@@ -50,30 +50,40 @@
"output_type": "stream",
"text": [
"---------- user ----------\n",
- "What is the weather in New York?\n",
+ "What is the weather in NYC?\n",
+ "---------- weather_agent ----------\n",
+ "[FunctionCall(id='call_vN04UiNJgqSz6g3MHt7Renig', arguments='{\"city\":\"New York City\"}', name='get_weather')]\n",
+ "[Prompt tokens: 75, Completion tokens: 16]\n",
+ "---------- weather_agent ----------\n",
+ "[FunctionExecutionResult(content='The weather in New York City is 73 degrees and Sunny.', call_id='call_vN04UiNJgqSz6g3MHt7Renig')]\n",
"---------- weather_agent ----------\n",
- "[FunctionCall(id='call_AhTZ2q3TNL8x0qs00e3wIZ7y', arguments='{\"city\":\"New York\"}', name='get_weather')]\n",
- "[Prompt tokens: 79, Completion tokens: 15]\n",
+ "The weather in New York City is 73 degrees and Sunny.\n",
+ "---------- Summary ----------\n",
+ "Number of messages: 4\n",
+ "Finish reason: Maximum number of turns 1 reached.\n",
+ "Total prompt tokens: 75\n",
+ "Total completion tokens: 16\n",
+ "Duration: 1.15 seconds\n",
+ "---------- user ----------\n",
+ "What is the weather in Seattle?\n",
"---------- weather_agent ----------\n",
- "[FunctionExecutionResult(content='The weather in New York is 73 degrees and Sunny.', call_id='call_AhTZ2q3TNL8x0qs00e3wIZ7y')]\n",
+ "[FunctionCall(id='call_BesYutZXJIMfu2TlDZgodIEj', arguments='{\"city\":\"Seattle\"}', name='get_weather')]\n",
+ "[Prompt tokens: 127, Completion tokens: 14]\n",
"---------- weather_agent ----------\n",
- "The weather in New York is currently 73 degrees and sunny.\n",
- "[Prompt tokens: 90, Completion tokens: 14]\n",
+ "[FunctionExecutionResult(content='The weather in Seattle is 73 degrees and Sunny.', call_id='call_BesYutZXJIMfu2TlDZgodIEj')]\n",
"---------- weather_agent ----------\n",
- "TERMINATE\n",
- "[Prompt tokens: 137, Completion tokens: 4]\n",
+ "The weather in Seattle is 73 degrees and Sunny.\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"
+ "Number of messages: 4\n",
+ "Finish reason: Maximum number of turns 1 reached.\n",
+ "Total prompt tokens: 127\n",
+ "Total completion tokens: 14\n",
+ "Duration: 2.38 seconds\n"
]
}
],
"source": [
"from autogen_agentchat.agents import AssistantAgent\n",
- "from autogen_agentchat.conditions import TextMentionTermination\n",
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
"from autogen_agentchat.ui import Console\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
@@ -95,15 +105,17 @@
" 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",
+ " # Define a team with a single agent and maximum auto-gen turns of 1.\n",
+ " agent_team = RoundRobinGroupChat([weather_agent], max_turns=1)\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",
+ " while True:\n",
+ " # Get user input from the console.\n",
+ " user_input = input(\"Enter a message (type 'exit' to leave): \")\n",
+ " if user_input.strip().lower() == \"exit\":\n",
+ " break\n",
+ " # Run the team and stream messages to the console.\n",
+ " stream = agent_team.run_stream(task=user_input)\n",
+ " await Console(stream)\n",
"\n",
"\n",
"# NOTE: if running this inside a Python script you'll need to use asyncio.run(main()).\n",