Skip to content

Commit 4bce1e9

Browse files
authored
Update agentchat quickstart to show how to handle multi-round user inputs (#4735)
Update agentchat quickstart to show how to handle multi-round user inputs.
1 parent dda208f commit 4bce1e9

File tree

1 file changed

+37
-25
lines changed
  • python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide

1 file changed

+37
-25
lines changed

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

+37-25
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"metadata": {},
1313
"source": [
1414
"Via AgentChat, you can build applications quickly using preset agents.\n",
15-
"To illustrate this, we will begin with creating a team of a single agent\n",
16-
"that can use tools and respond to messages.\n",
15+
"To illustrate this, we will begin with creating a team of a single tool-use\n",
16+
"agent that you can chat with.\n",
1717
"\n",
1818
"The following code uses the OpenAI model. If you haven't already, you need to\n",
1919
"install the following package and extension:"
@@ -42,38 +42,48 @@
4242
},
4343
{
4444
"cell_type": "code",
45-
"execution_count": null,
45+
"execution_count": 2,
4646
"metadata": {},
4747
"outputs": [
4848
{
4949
"name": "stdout",
5050
"output_type": "stream",
5151
"text": [
5252
"---------- user ----------\n",
53-
"What is the weather in New York?\n",
53+
"What is the weather in NYC?\n",
54+
"---------- weather_agent ----------\n",
55+
"[FunctionCall(id='call_vN04UiNJgqSz6g3MHt7Renig', arguments='{\"city\":\"New York City\"}', name='get_weather')]\n",
56+
"[Prompt tokens: 75, Completion tokens: 16]\n",
57+
"---------- weather_agent ----------\n",
58+
"[FunctionExecutionResult(content='The weather in New York City is 73 degrees and Sunny.', call_id='call_vN04UiNJgqSz6g3MHt7Renig')]\n",
5459
"---------- weather_agent ----------\n",
55-
"[FunctionCall(id='call_AhTZ2q3TNL8x0qs00e3wIZ7y', arguments='{\"city\":\"New York\"}', name='get_weather')]\n",
56-
"[Prompt tokens: 79, Completion tokens: 15]\n",
60+
"The weather in New York City is 73 degrees and Sunny.\n",
61+
"---------- Summary ----------\n",
62+
"Number of messages: 4\n",
63+
"Finish reason: Maximum number of turns 1 reached.\n",
64+
"Total prompt tokens: 75\n",
65+
"Total completion tokens: 16\n",
66+
"Duration: 1.15 seconds\n",
67+
"---------- user ----------\n",
68+
"What is the weather in Seattle?\n",
5769
"---------- weather_agent ----------\n",
58-
"[FunctionExecutionResult(content='The weather in New York is 73 degrees and Sunny.', call_id='call_AhTZ2q3TNL8x0qs00e3wIZ7y')]\n",
70+
"[FunctionCall(id='call_BesYutZXJIMfu2TlDZgodIEj', arguments='{\"city\":\"Seattle\"}', name='get_weather')]\n",
71+
"[Prompt tokens: 127, Completion tokens: 14]\n",
5972
"---------- weather_agent ----------\n",
60-
"The weather in New York is currently 73 degrees and sunny.\n",
61-
"[Prompt tokens: 90, Completion tokens: 14]\n",
73+
"[FunctionExecutionResult(content='The weather in Seattle is 73 degrees and Sunny.', call_id='call_BesYutZXJIMfu2TlDZgodIEj')]\n",
6274
"---------- weather_agent ----------\n",
63-
"TERMINATE\n",
64-
"[Prompt tokens: 137, Completion tokens: 4]\n",
75+
"The weather in Seattle is 73 degrees and Sunny.\n",
6576
"---------- Summary ----------\n",
66-
"Number of messages: 5\n",
67-
"Finish reason: Text 'TERMINATE' mentioned\n",
68-
"Total prompt tokens: 306\n",
69-
"Total completion tokens: 33\n",
70-
"Duration: 1.43 seconds\n"
77+
"Number of messages: 4\n",
78+
"Finish reason: Maximum number of turns 1 reached.\n",
79+
"Total prompt tokens: 127\n",
80+
"Total completion tokens: 14\n",
81+
"Duration: 2.38 seconds\n"
7182
]
7283
}
7384
],
7485
"source": [
7586
"from autogen_agentchat.agents import AssistantAgent\n",
76-
"from autogen_agentchat.conditions import TextMentionTermination\n",
7787
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
7888
"from autogen_agentchat.ui import Console\n",
7989
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
@@ -95,15 +105,17 @@
95105
" tools=[get_weather],\n",
96106
" )\n",
97107
"\n",
98-
" # Define termination condition\n",
99-
" termination = TextMentionTermination(\"TERMINATE\")\n",
100-
"\n",
101-
" # Define a team\n",
102-
" agent_team = RoundRobinGroupChat([weather_agent], termination_condition=termination)\n",
108+
" # Define a team with a single agent and maximum auto-gen turns of 1.\n",
109+
" agent_team = RoundRobinGroupChat([weather_agent], max_turns=1)\n",
103110
"\n",
104-
" # Run the team and stream messages to the console\n",
105-
" stream = agent_team.run_stream(task=\"What is the weather in New York?\")\n",
106-
" await Console(stream)\n",
111+
" while True:\n",
112+
" # Get user input from the console.\n",
113+
" user_input = input(\"Enter a message (type 'exit' to leave): \")\n",
114+
" if user_input.strip().lower() == \"exit\":\n",
115+
" break\n",
116+
" # Run the team and stream messages to the console.\n",
117+
" stream = agent_team.run_stream(task=user_input)\n",
118+
" await Console(stream)\n",
107119
"\n",
108120
"\n",
109121
"# NOTE: if running this inside a Python script you'll need to use asyncio.run(main()).\n",

0 commit comments

Comments
 (0)