|
12 | 12 | "metadata": {},
|
13 | 13 | "source": [
|
14 | 14 | "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", |
17 | 17 | "\n",
|
18 | 18 | "The following code uses the OpenAI model. If you haven't already, you need to\n",
|
19 | 19 | "install the following package and extension:"
|
|
42 | 42 | },
|
43 | 43 | {
|
44 | 44 | "cell_type": "code",
|
45 |
| - "execution_count": null, |
| 45 | + "execution_count": 2, |
46 | 46 | "metadata": {},
|
47 | 47 | "outputs": [
|
48 | 48 | {
|
49 | 49 | "name": "stdout",
|
50 | 50 | "output_type": "stream",
|
51 | 51 | "text": [
|
52 | 52 | "---------- 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", |
54 | 59 | "---------- 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", |
57 | 69 | "---------- 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", |
59 | 72 | "---------- 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", |
62 | 74 | "---------- 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", |
65 | 76 | "---------- 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" |
71 | 82 | ]
|
72 | 83 | }
|
73 | 84 | ],
|
74 | 85 | "source": [
|
75 | 86 | "from autogen_agentchat.agents import AssistantAgent\n",
|
76 |
| - "from autogen_agentchat.conditions import TextMentionTermination\n", |
77 | 87 | "from autogen_agentchat.teams import RoundRobinGroupChat\n",
|
78 | 88 | "from autogen_agentchat.ui import Console\n",
|
79 | 89 | "from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
|
|
95 | 105 | " tools=[get_weather],\n",
|
96 | 106 | " )\n",
|
97 | 107 | "\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", |
103 | 110 | "\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", |
107 | 119 | "\n",
|
108 | 120 | "\n",
|
109 | 121 | "# NOTE: if running this inside a Python script you'll need to use asyncio.run(main()).\n",
|
|
0 commit comments