|
37 | 37 | "text": [
|
38 | 38 | "\n",
|
39 | 39 | "--------------------------------------------------------------------------- \n",
|
40 |
| - "\u001b[91m[2024-10-23T12:15:51.582079]:\u001b[0m\n", |
| 40 | + "\u001b[91m[2024-10-29T15:48:06.329810]:\u001b[0m\n", |
41 | 41 | "\n",
|
42 | 42 | "What is the weather in New York?\n",
|
43 | 43 | "--------------------------------------------------------------------------- \n",
|
44 |
| - "\u001b[91m[2024-10-23T12:15:52.745820], writing_agent:\u001b[0m\n", |
| 44 | + "\u001b[91m[2024-10-29T15:48:08.085839], weather_agent:\u001b[0m\n", |
45 | 45 | "\n",
|
46 |
| - "The weather in New York is currently 73 degrees and sunny. TERMINATE\n", |
| 46 | + "The weather in New York is 73 degrees and sunny.\n", |
47 | 47 | "--------------------------------------------------------------------------- \n",
|
48 |
| - "\u001b[91m[2024-10-23T12:15:52.746210], Termination:\u001b[0m\n", |
| 48 | + "\u001b[91m[2024-10-29T15:48:08.086180], Termination:\u001b[0m\n", |
49 | 49 | "\n",
|
50 |
| - "Maximal number of messages 1 reached, current message count: 1\n", |
51 |
| - " TaskResult(messages=[TextMessage(source='user', content='What is the weather in New York?'), StopMessage(source='writing_agent', content='The weather in New York is currently 73 degrees and sunny. TERMINATE')])\n" |
| 50 | + "Maximum number of messages 2 reached, current message count: 2\n", |
| 51 | + " TaskResult(messages=[TextMessage(source='user', content='What is the weather in New York?'), TextMessage(source='weather_agent', content='The weather in New York is 73 degrees and sunny.')])\n" |
52 | 52 | ]
|
53 | 53 | }
|
54 | 54 | ],
|
55 | 55 | "source": [
|
56 | 56 | "import logging\n",
|
57 | 57 | "\n",
|
58 | 58 | "from autogen_agentchat import EVENT_LOGGER_NAME\n",
|
59 |
| - "from autogen_agentchat.agents import ToolUseAssistantAgent\n", |
| 59 | + "from autogen_agentchat.agents import AssistantAgent\n", |
60 | 60 | "from autogen_agentchat.logging import ConsoleLogHandler\n",
|
61 | 61 | "from autogen_agentchat.task import MaxMessageTermination\n",
|
62 | 62 | "from autogen_agentchat.teams import RoundRobinGroupChat\n",
|
63 |
| - "from autogen_core.components.tools import FunctionTool\n", |
64 | 63 | "from autogen_ext.models import OpenAIChatCompletionClient\n",
|
65 | 64 | "\n",
|
| 65 | + "# set up logging. You can define your own logger\n", |
66 | 66 | "logger = logging.getLogger(EVENT_LOGGER_NAME)\n",
|
67 | 67 | "logger.addHandler(ConsoleLogHandler())\n",
|
68 | 68 | "logger.setLevel(logging.INFO)\n",
|
|
73 | 73 | " return f\"The weather in {city} is 73 degrees and Sunny.\"\n",
|
74 | 74 | "\n",
|
75 | 75 | "\n",
|
76 |
| - "# wrap the tool for use with the agent\n", |
77 |
| - "get_weather_tool = FunctionTool(get_weather, description=\"Get the weather for a city\")\n", |
78 |
| - "\n", |
79 | 76 | "# define an agent\n",
|
80 |
| - "weather_agent = ToolUseAssistantAgent(\n", |
81 |
| - " name=\"writing_agent\",\n", |
| 77 | + "weather_agent = AssistantAgent(\n", |
| 78 | + " name=\"weather_agent\",\n", |
82 | 79 | " model_client=OpenAIChatCompletionClient(model=\"gpt-4o-2024-08-06\"),\n",
|
83 |
| - " registered_tools=[get_weather_tool],\n", |
| 80 | + " tools=[get_weather],\n", |
84 | 81 | ")\n",
|
85 | 82 | "\n",
|
86 | 83 | "# add the agent to a team\n",
|
87 |
| - "agent_team = RoundRobinGroupChat([weather_agent])\n", |
| 84 | + "agent_team = RoundRobinGroupChat([weather_agent], termination_condition=MaxMessageTermination(max_messages=2))\n", |
88 | 85 | "# Note: if running in a Python file directly you'll need to use asyncio.run(agent_team.run(...)) instead of await agent_team.run(...)\n",
|
89 | 86 | "result = await agent_team.run(\n",
|
90 | 87 | " task=\"What is the weather in New York?\",\n",
|
91 |
| - " termination_condition=MaxMessageTermination(max_messages=1),\n", |
92 | 88 | ")\n",
|
93 | 89 | "print(\"\\n\", result)"
|
94 | 90 | ]
|
|
97 | 93 | "cell_type": "markdown",
|
98 | 94 | "metadata": {},
|
99 | 95 | "source": [
|
100 |
| - "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 `ToolUseAssistantAgent` preset - an agent that can be given a function 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. " |
| 96 | + "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. " |
101 | 97 | ]
|
102 | 98 | },
|
103 | 99 | {
|
|
113 | 109 | ],
|
114 | 110 | "metadata": {
|
115 | 111 | "kernelspec": {
|
116 |
| - "display_name": ".venv", |
| 112 | + "display_name": "agnext", |
117 | 113 | "language": "python",
|
118 | 114 | "name": "python3"
|
119 | 115 | },
|
|
127 | 123 | "name": "python",
|
128 | 124 | "nbconvert_exporter": "python",
|
129 | 125 | "pygments_lexer": "ipython3",
|
130 |
| - "version": "3.12.6" |
| 126 | + "version": "3.11.9" |
131 | 127 | }
|
132 | 128 | },
|
133 | 129 | "nbformat": 4,
|
|
0 commit comments