diff --git a/autogen/agentchat/contrib/swarm_agent.py b/autogen/agentchat/contrib/swarm_agent.py index fb99036680..428345b272 100644 --- a/autogen/agentchat/contrib/swarm_agent.py +++ b/autogen/agentchat/contrib/swarm_agent.py @@ -86,7 +86,7 @@ def _establish_swarm_agent(agent: ConversableAgent): def _swarm_agent_str(self: ConversableAgent) -> str: """Customise the __str__ method to show the agent name for transition messages.""" - return f"SwarmAgent --> {self.name}" + return f"Swarm agent --> {self.name}" agent._swarm_after_work = None diff --git a/notebook/agentchat_realtime_swarm.ipynb b/notebook/agentchat_realtime_swarm.ipynb index b7ade2c755..05b024b034 100644 --- a/notebook/agentchat_realtime_swarm.ipynb +++ b/notebook/agentchat_realtime_swarm.ipynb @@ -14,6 +14,17 @@ "In this notebook, we implement OpenAI's [airline customer service example](https://github.com/openai/swarm/tree/main/examples/airline) in AG2 using the RealtimeAgent for enhanced interaction." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "````mdx-code-block\n", + ":::note\n", + "This notebook has been updated as swarms can now accommodate any ConversableAgent.\n", + ":::\n", + "````" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -270,14 +281,14 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "from autogen import ON_CONDITION, SwarmAgent\n", + "from autogen import ON_CONDITION, ConversableAgent, register_hand_off\n", "\n", "# Triage Agent\n", - "triage_agent = SwarmAgent(\n", + "triage_agent = ConversableAgent(\n", " name=\"Triage_Agent\",\n", " system_message=triage_instructions(context_variables=context_variables),\n", " llm_config=llm_config,\n", @@ -285,7 +296,7 @@ ")\n", "\n", "# Flight Modification Agent\n", - "flight_modification = SwarmAgent(\n", + "flight_modification = ConversableAgent(\n", " name=\"Flight_Modification_Agent\",\n", " system_message=\"\"\"You are a Flight Modification Agent for a customer service airline.\n", " Your task is to determine if the user wants to cancel or change their flight.\n", @@ -295,7 +306,7 @@ ")\n", "\n", "# Flight Cancel Agent\n", - "flight_cancel = SwarmAgent(\n", + "flight_cancel = ConversableAgent(\n", " name=\"Flight_Cancel_Traversal\",\n", " system_message=STARTER_PROMPT + FLIGHT_CANCELLATION_POLICY,\n", " llm_config=llm_config,\n", @@ -303,7 +314,7 @@ ")\n", "\n", "# Flight Change Agent\n", - "flight_change = SwarmAgent(\n", + "flight_change = ConversableAgent(\n", " name=\"Flight_Change_Traversal\",\n", " system_message=STARTER_PROMPT + FLIGHT_CHANGE_POLICY,\n", " llm_config=llm_config,\n", @@ -311,7 +322,7 @@ ")\n", "\n", "# Lost Baggage Agent\n", - "lost_baggage = SwarmAgent(\n", + "lost_baggage = ConversableAgent(\n", " name=\"Lost_Baggage_Traversal\",\n", " system_message=STARTER_PROMPT + LOST_BAGGAGE_POLICY,\n", " llm_config=llm_config,\n", @@ -330,28 +341,30 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Register hand-offs\n", - "triage_agent.register_hand_off(\n", - " [\n", + "register_hand_off(\n", + " agent=triage_agent,\n", + " hand_to=[\n", " ON_CONDITION(flight_modification, \"To modify a flight\"),\n", " ON_CONDITION(lost_baggage, \"To find lost baggage\"),\n", - " ]\n", + " ],\n", ")\n", "\n", - "flight_modification.register_hand_off(\n", - " [\n", + "register_hand_off(\n", + " agent=flight_modification,\n", + " hand_to=[\n", " ON_CONDITION(flight_cancel, \"To cancel a flight\"),\n", " ON_CONDITION(flight_change, \"To change a flight\"),\n", - " ]\n", + " ],\n", ")\n", "\n", "transfer_to_triage_description = \"Call this function when a user needs to be transferred to a different agent and a different policy.\\nFor instance, if a user is asking about a topic that is not handled by the current agent, call this function.\"\n", "for agent in [flight_modification, flight_cancel, flight_change, lost_baggage]:\n", - " agent.register_hand_off(ON_CONDITION(triage_agent, transfer_to_triage_description))" + " register_hand_off(agent=agent, hand_to=ON_CONDITION(triage_agent, transfer_to_triage_description))" ] }, { diff --git a/notebook/agentchat_swarm.ipynb b/notebook/agentchat_swarm.ipynb index 56141046c2..9d1327f59e 100644 --- a/notebook/agentchat_swarm.ipynb +++ b/notebook/agentchat_swarm.ipynb @@ -16,6 +16,17 @@ "In this notebook, we implement OpenAI's [airline customer service example](https://github.com/openai/swarm/tree/main/examples/airline) in AG2." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "````mdx-code-block\n", + ":::note\n", + "This notebook has been updated as swarms can now accommodate any ConversableAgent.\n", + ":::\n", + "````" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -222,10 +233,10 @@ "metadata": {}, "outputs": [], "source": [ - "from autogen import ON_CONDITION, AfterWorkOption, SwarmAgent, initiate_swarm_chat\n", + "from autogen import ON_CONDITION, AfterWorkOption, ConversableAgent, initiate_swarm_chat, register_hand_off\n", "\n", "# Triage Agent\n", - "triage_agent = SwarmAgent(\n", + "triage_agent = ConversableAgent(\n", " name=\"Triage_Agent\",\n", " system_message=triage_instructions(context_variables=context_variables),\n", " llm_config=llm_config,\n", @@ -233,7 +244,7 @@ ")\n", "\n", "# Flight Modification Agent\n", - "flight_modification = SwarmAgent(\n", + "flight_modification = ConversableAgent(\n", " name=\"Flight_Modification_Agent\",\n", " system_message=\"\"\"You are a Flight Modification Agent for a customer service airline.\n", " Your task is to determine if the user wants to cancel or change their flight.\n", @@ -243,7 +254,7 @@ ")\n", "\n", "# Flight Cancel Agent\n", - "flight_cancel = SwarmAgent(\n", + "flight_cancel = ConversableAgent(\n", " name=\"Flight_Cancel_Traversal\",\n", " system_message=STARTER_PROMPT + FLIGHT_CANCELLATION_POLICY,\n", " llm_config=llm_config,\n", @@ -251,7 +262,7 @@ ")\n", "\n", "# Flight Change Agent\n", - "flight_change = SwarmAgent(\n", + "flight_change = ConversableAgent(\n", " name=\"Flight_Change_Traversal\",\n", " system_message=STARTER_PROMPT + FLIGHT_CHANGE_POLICY,\n", " llm_config=llm_config,\n", @@ -259,7 +270,7 @@ ")\n", "\n", "# Lost Baggage Agent\n", - "lost_baggage = SwarmAgent(\n", + "lost_baggage = ConversableAgent(\n", " name=\"Lost_Baggage_Traversal\",\n", " system_message=STARTER_PROMPT + LOST_BAGGAGE_POLICY,\n", " llm_config=llm_config,\n", @@ -283,23 +294,25 @@ "outputs": [], "source": [ "# Register hand-offs\n", - "triage_agent.register_hand_off(\n", - " [\n", + "register_hand_off(\n", + " agent=triage_agent,\n", + " hand_to=[\n", " ON_CONDITION(flight_modification, \"To modify a flight\"),\n", " ON_CONDITION(lost_baggage, \"To find lost baggage\"),\n", - " ]\n", + " ],\n", ")\n", "\n", - "flight_modification.register_hand_off(\n", - " [\n", + "register_hand_off(\n", + " agent=flight_modification,\n", + " hand_to=[\n", " ON_CONDITION(flight_cancel, \"To cancel a flight\"),\n", " ON_CONDITION(flight_change, \"To change a flight\"),\n", - " ]\n", + " ],\n", ")\n", "\n", "transfer_to_triage_description = \"Call this function when a user needs to be transferred to a different agent and a different policy.\\nFor instance, if a user is asking about a topic that is not handled by the current agent, call this function.\"\n", "for agent in [flight_modification, flight_cancel, flight_change, lost_baggage]:\n", - " agent.register_hand_off(ON_CONDITION(triage_agent, transfer_to_triage_description))" + " register_hand_off(agent=agent, hand_to=ON_CONDITION(triage_agent, transfer_to_triage_description))" ] }, { @@ -373,7 +386,7 @@ "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", "\n", "\u001b[32m***** Response from calling tool (call_Qgji9KAw1e3ktxykLU8v1wg7) *****\u001b[0m\n", - "SwarmAgent --> Flight_Modification_Agent\n", + "Swarm agent --> Flight_Modification_Agent\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", @@ -397,7 +410,7 @@ "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", "\n", "\u001b[32m***** Response from calling tool (call_QYu7uBko1EaEZ7VzxPwx2jNO) *****\u001b[0m\n", - "SwarmAgent --> Flight_Cancel_Traversal\n", + "Swarm agent --> Flight_Cancel_Traversal\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", diff --git a/notebook/agentchat_swarm_enhanced.ipynb b/notebook/agentchat_swarm_enhanced.ipynb index 6de59c5f54..d0388494b4 100644 --- a/notebook/agentchat_swarm_enhanced.ipynb +++ b/notebook/agentchat_swarm_enhanced.ipynb @@ -19,6 +19,17 @@ "- Nested chats" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "````mdx-code-block\n", + ":::note\n", + "This notebook has been updated as swarms can now accommodate any ConversableAgent.\n", + ":::\n", + "````" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -95,7 +106,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -107,10 +118,10 @@ " UPDATE_SYSTEM_MESSAGE,\n", " AfterWorkOption,\n", " ConversableAgent,\n", - " SwarmAgent,\n", " SwarmResult,\n", " UserProxyAgent,\n", " initiate_swarm_chat,\n", + " register_hand_off,\n", ")" ] }, @@ -276,7 +287,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -301,7 +312,7 @@ "Enquiring for Order ID: {order_id}\n", "\"\"\"\n", "\n", - "order_triage_agent = SwarmAgent(\n", + "order_triage_agent = ConversableAgent(\n", " name=\"order_triage_agent\",\n", " update_agent_state_before_reply=[\n", " UPDATE_SYSTEM_MESSAGE(order_triage_prompt),\n", @@ -312,7 +323,7 @@ "\n", "authentication_prompt = \"You are an authentication agent that verifies the identity of the customer.\"\n", "\n", - "authentication_agent = SwarmAgent(\n", + "authentication_agent = ConversableAgent(\n", " name=\"authentication_agent\",\n", " system_message=authentication_prompt,\n", " functions=[login_customer_by_username],\n", @@ -331,7 +342,7 @@ "Enquiring for Order ID: {order_id}\n", "\"\"\"\n", "\n", - "order_mgmt_agent = SwarmAgent(\n", + "order_mgmt_agent = ConversableAgent(\n", " name=\"order_mgmt_agent\",\n", " update_agent_state_before_reply=[\n", " UPDATE_SYSTEM_MESSAGE(order_management_prompt),\n", @@ -404,13 +415,14 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# HANDOFFS\n", - "order_triage_agent.register_hand_off(\n", - " [\n", + "register_hand_off(\n", + " agent=order_triage_agent,\n", + " hand_to=[\n", " ON_CONDITION(\n", " target=authentication_agent,\n", " condition=\"The customer is not logged in, authenticate the customer.\",\n", @@ -422,27 +434,29 @@ " available=\"logged_in\",\n", " ),\n", " AFTER_WORK(AfterWorkOption.REVERT_TO_USER),\n", - " ]\n", + " ],\n", ")\n", "\n", - "authentication_agent.register_hand_off(\n", - " [\n", + "register_hand_off(\n", + " agent=authentication_agent,\n", + " hand_to=[\n", " ON_CONDITION(\n", " target=order_triage_agent,\n", " condition=\"The customer is logged in, continue with the order triage.\",\n", " available=\"logged_in\",\n", " ),\n", " AFTER_WORK(AfterWorkOption.REVERT_TO_USER),\n", - " ]\n", + " ],\n", ")\n", "\n", "\n", - "def has_order_in_context(agent: SwarmAgent, messages: List[Dict[str, Any]]) -> bool:\n", + "def has_order_in_context(agent: ConversableAgent, messages: List[Dict[str, Any]]) -> bool:\n", " return agent.get_context(\"has_order_id\")\n", "\n", "\n", - "order_mgmt_agent.register_hand_off(\n", - " [\n", + "register_hand_off(\n", + " agent=order_mgmt_agent,\n", + " hand_to=[\n", " ON_CONDITION(\n", " target={\n", " \"chat_queue\": chat_queue,\n", @@ -457,7 +471,7 @@ " ),\n", " ON_CONDITION(target=order_triage_agent, condition=\"The customer has no more enquiries about this order.\"),\n", " AFTER_WORK(AfterWorkOption.REVERT_TO_USER),\n", - " ]\n", + " ],\n", ")" ] }, @@ -501,7 +515,7 @@ "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", "\n", "\u001b[32m***** Response from calling tool (call_RhIdaMav5FoXxvXiYhyDoivV) *****\u001b[0m\n", - "SwarmAgent --> authentication_agent\n", + "Swarm agent --> authentication_agent\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", @@ -602,7 +616,7 @@ "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", "\n", "\u001b[32m***** Response from calling tool (call_mXHJHDzVPTXWDhll0UH7w3QI) *****\u001b[0m\n", - "SwarmAgent --> order_mgmt_agent\n", + "Swarm agent --> order_mgmt_agent\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", @@ -764,7 +778,7 @@ "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", "\n", "\u001b[32m***** Response from calling tool (call_sYsVS1U3k3Cf2KbqKJ4hhyRa) *****\u001b[0m\n", - "SwarmAgent --> nested_chat_order_mgmt_agent_1\n", + "Swarm agent --> nested_chat_order_mgmt_agent_1\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", @@ -870,7 +884,7 @@ "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", "\n", "\u001b[32m***** Response from calling tool (call_VtBmcKhDAhh7JUz9aXyPq9Aj) *****\u001b[0m\n", - "SwarmAgent --> order_triage_agent\n", + "Swarm agent --> order_triage_agent\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", diff --git a/notebook/agentchat_swarm_graphrag_telemetry_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_telemetry_trip_planner.ipynb index 3c8cfefd6c..f6b7a384a8 100644 --- a/notebook/agentchat_swarm_graphrag_telemetry_trip_planner.ipynb +++ b/notebook/agentchat_swarm_graphrag_telemetry_trip_planner.ipynb @@ -17,6 +17,17 @@ "- Swarm orchestration utilising context variables" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "````mdx-code-block\n", + ":::note\n", + "This notebook has been updated as swarms can now accommodate any ConversableAgent.\n", + ":::\n", + "````" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -416,7 +427,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -433,10 +444,11 @@ " AFTER_WORK,\n", " ON_CONDITION,\n", " AfterWorkOption,\n", - " SwarmAgent,\n", + " ConversableAgent,\n", " SwarmResult,\n", " UserProxyAgent,\n", " initiate_swarm_chat,\n", + " register_hand_off,\n", ")" ] }, @@ -641,17 +653,17 @@ "source": [ "### Agents\n", "\n", - "Our SwarmAgents and a UserProxyAgent (human) which the swarm will interact with." + "Our Swarm agents and a UserProxyAgent (human) which the swarm will interact with." ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Planner agent, interacting with the customer and GraphRag agent, to create an itinerary\n", - "planner_agent = SwarmAgent(\n", + "planner_agent = ConversableAgent(\n", " name=\"planner_agent\",\n", " system_message=\"You are a trip planner agent. It is important to know where the customer is going, how many days, what they want to do.\"\n", " + \"You will work with another agent, graphrag_agent, to get information about restaurant and attractions. \"\n", @@ -664,7 +676,7 @@ ")\n", "\n", "# FalkorDB GraphRAG agent, utilising the FalkorDB to gather data for the Planner agent\n", - "graphrag_agent = SwarmAgent(\n", + "graphrag_agent = ConversableAgent(\n", " name=\"graphrag_agent\",\n", " system_message=\"Return a list of restaurants and/or attractions. List them separately and provide ALL the options in the location. Do not provide travel advice.\",\n", ")\n", @@ -678,7 +690,7 @@ "for config in structured_config_list:\n", " config[\"response_format\"] = Itinerary\n", "\n", - "structured_output_agent = SwarmAgent(\n", + "structured_output_agent = ConversableAgent(\n", " name=\"structured_output_agent\",\n", " system_message=\"You are a data formatting agent, format the provided itinerary in the context below into the provided format.\",\n", " llm_config={\"config_list\": structured_config_list, \"timeout\": 120},\n", @@ -686,7 +698,7 @@ ")\n", "\n", "# Route Timing agent, adding estimated travel times to the itinerary by utilising the Google Maps Platform\n", - "route_timing_agent = SwarmAgent(\n", + "route_timing_agent = ConversableAgent(\n", " name=\"route_timing_agent\",\n", " system_message=\"You are a route timing agent. YOU MUST call the update_itinerary_with_travel_times tool if you do not see the exact phrase 'Timed itinerary added to context with travel times' is seen in this conversation. Only after this please tell the customer 'Your itinerary is ready!'.\",\n", " llm_config=llm_config,\n", @@ -710,11 +722,12 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "planner_agent.register_hand_off(\n", + "register_hand_off(\n", + " agent=planner_agent,\n", " hand_to=[\n", " ON_CONDITION(\n", " graphrag_agent,\n", @@ -722,20 +735,18 @@ " ), # Get info from FalkorDB GraphRAG\n", " ON_CONDITION(structured_output_agent, \"Itinerary is confirmed by the customer\"),\n", " AFTER_WORK(AfterWorkOption.REVERT_TO_USER), # Revert to the customer for more information on their plans\n", - " ]\n", + " ],\n", ")\n", "\n", "\n", "# Back to the Planner when information has been retrieved\n", - "graphrag_agent.register_hand_off(hand_to=[AFTER_WORK(planner_agent)])\n", + "register_hand_off(agent=graphrag_agent, hand_to=[AFTER_WORK(planner_agent)])\n", "\n", "# Once we have formatted our itinerary, we can hand off to the route timing agent to add in the travel timings\n", - "structured_output_agent.register_hand_off(hand_to=[AFTER_WORK(route_timing_agent)])\n", + "register_hand_off(agent=structured_output_agent, hand_to=[AFTER_WORK(route_timing_agent)])\n", "\n", "# Finally, once the route timing agent has finished, we can terminate the swarm\n", - "route_timing_agent.register_hand_off(\n", - " hand_to=[AFTER_WORK(AfterWorkOption.TERMINATE)] # Once this agent has finished, the swarm can terminate\n", - ")" + "register_hand_off(agent=route_timing_agent, hand_to=[AFTER_WORK(AfterWorkOption.TERMINATE)])" ] }, { diff --git a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb index 86da0683eb..4a747f2ff7 100644 --- a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb +++ b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb @@ -16,6 +16,17 @@ "- Swarm orchestration utilising context variables" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "````mdx-code-block\n", + ":::note\n", + "This notebook has been updated as swarms can now accommodate any ConversableAgent.\n", + ":::\n", + "````" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -312,7 +323,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -329,10 +340,11 @@ " AFTER_WORK,\n", " ON_CONDITION,\n", " AfterWorkOption,\n", - " SwarmAgent,\n", + " ConversableAgent,\n", " SwarmResult,\n", " UserProxyAgent,\n", " initiate_swarm_chat,\n", + " register_hand_off,\n", ")" ] }, @@ -537,17 +549,17 @@ "source": [ "### Agents\n", "\n", - "Our SwarmAgents and a UserProxyAgent (human) which the swarm will interact with." + "Our Swarm agents and a UserProxyAgent (human) which the swarm will interact with." ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Planner agent, interacting with the customer and GraphRag agent, to create an itinerary\n", - "planner_agent = SwarmAgent(\n", + "planner_agent = ConversableAgent(\n", " name=\"planner_agent\",\n", " system_message=\"You are a trip planner agent. It is important to know where the customer is going, how many days, what they want to do.\"\n", " + \"You will work with another agent, graphrag_agent, to get information about restaurant and attractions. \"\n", @@ -560,7 +572,7 @@ ")\n", "\n", "# FalkorDB GraphRAG agent, utilising the FalkorDB to gather data for the Planner agent\n", - "graphrag_agent = SwarmAgent(\n", + "graphrag_agent = ConversableAgent(\n", " name=\"graphrag_agent\",\n", " system_message=\"Return a list of restaurants and/or attractions. List them separately and provide ALL the options in the location. Do not provide travel advice.\",\n", ")\n", @@ -574,7 +586,7 @@ "for config in structured_config_list:\n", " config[\"response_format\"] = Itinerary\n", "\n", - "structured_output_agent = SwarmAgent(\n", + "structured_output_agent = ConversableAgent(\n", " name=\"structured_output_agent\",\n", " system_message=\"You are a data formatting agent, format the provided itinerary in the context below into the provided format.\",\n", " llm_config={\"config_list\": structured_config_list, \"timeout\": 120},\n", @@ -582,7 +594,7 @@ ")\n", "\n", "# Route Timing agent, adding estimated travel times to the itinerary by utilising the Google Maps Platform\n", - "route_timing_agent = SwarmAgent(\n", + "route_timing_agent = ConversableAgent(\n", " name=\"route_timing_agent\",\n", " system_message=\"You are a route timing agent. YOU MUST call the update_itinerary_with_travel_times tool if you do not see the exact phrase 'Timed itinerary added to context with travel times' is seen in this conversation. Only after this please tell the customer 'Your itinerary is ready!'.\",\n", " llm_config=llm_config,\n", @@ -606,11 +618,12 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "planner_agent.register_hand_off(\n", + "register_hand_off(\n", + " agent=planner_agent,\n", " hand_to=[\n", " ON_CONDITION(\n", " graphrag_agent,\n", @@ -618,20 +631,18 @@ " ), # Get info from FalkorDB GraphRAG\n", " ON_CONDITION(structured_output_agent, \"Itinerary is confirmed by the customer\"),\n", " AFTER_WORK(AfterWorkOption.REVERT_TO_USER), # Revert to the customer for more information on their plans\n", - " ]\n", + " ],\n", ")\n", "\n", "\n", "# Back to the Planner when information has been retrieved\n", - "graphrag_agent.register_hand_off(hand_to=[AFTER_WORK(planner_agent)])\n", + "register_hand_off(agent=graphrag_agent, hand_to=[AFTER_WORK(planner_agent)])\n", "\n", "# Once we have formatted our itinerary, we can hand off to the route timing agent to add in the travel timings\n", - "structured_output_agent.register_hand_off(hand_to=[AFTER_WORK(route_timing_agent)])\n", + "register_hand_off(agent=structured_output_agent, hand_to=[AFTER_WORK(route_timing_agent)])\n", "\n", "# Finally, once the route timing agent has finished, we can terminate the swarm\n", - "route_timing_agent.register_hand_off(\n", - " hand_to=[AFTER_WORK(AfterWorkOption.TERMINATE)] # Once this agent has finished, the swarm can terminate\n", - ")" + "register_hand_off(agent=route_timing_agent, hand_to=[AFTER_WORK(AfterWorkOption.TERMINATE)])" ] }, { @@ -692,7 +703,7 @@ "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", "\n", "\u001b[32m***** Response from calling tool (call_vQMpso8aOomdfq8S2uCRlnzj) *****\u001b[0m\n", - "SwarmAgent --> graphrag_agent\n", + "Swarm agent --> graphrag_agent\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", @@ -908,7 +919,7 @@ "\n", "--------------------------------------------------------------------------------\n", "\u001b[32m***** Response from calling tool (call_NBw71N4pS66h8VLlgu5nvveN) *****\u001b[0m\n", - "SwarmAgent --> structured_output_agent\n", + "Swarm agent --> structured_output_agent\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", @@ -1152,15 +1163,15 @@ } ], "metadata": { - "front_matter": { - "description": "FalkorDB GraphRAG utilises a knowledge graph and can be added as a capability to agents. Together with a swarm orchestration of agents is highly effective at providing a RAG capability.", - "tags": [ - "RAG", - "tool/function", - "swarm" - ] - }, - "kernelspec": { + "front_matter": { + "description": "FalkorDB GraphRAG utilises a knowledge graph and can be added as a capability to agents. Together with a swarm orchestration of agents is highly effective at providing a RAG capability.", + "tags": [ + "RAG", + "tool/function", + "swarm" + ] + }, + "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" diff --git a/test/agentchat/contrib/test_swarm.py b/test/agentchat/contrib/test_swarm.py index 12d5a6f634..4d8917aaff 100644 --- a/test/agentchat/contrib/test_swarm.py +++ b/test/agentchat/contrib/test_swarm.py @@ -68,7 +68,7 @@ def test_after_work_initialization(): after_work = AFTER_WORK("TERMINATE") assert after_work.agent == AfterWorkOption.TERMINATE - # Test with SwarmAgent + # Test with ConversableAgent agent = ConversableAgent("test") after_work = AFTER_WORK(agent) assert after_work.agent == agent @@ -431,7 +431,7 @@ def test_invalid_parameters(): def test_non_swarm_in_hand_off(): - """Test that SwarmAgents in the group chat are the only agents in hand-offs""" + """Test that agents in the group chat are the only agents in hand-offs""" agent1 = ConversableAgent("agent1") bad_agent = NotConversableAgent("bad_agent") @@ -566,7 +566,7 @@ def hello_world(context_variables: dict) -> SwarmResult: value = "Hello, World!" return SwarmResult(values=value, context_variables=context_variables, agent="agent_2") - # Create SwarmAgent instances + # Create agent instances agent_1 = ConversableAgent( name="agent_1", system_message="Your task is to call hello_world() function.", diff --git a/test/agentchat/test_conversable_agent.py b/test/agentchat/test_conversable_agent.py index 49e10009db..db3b9fa116 100755 --- a/test/agentchat/test_conversable_agent.py +++ b/test/agentchat/test_conversable_agent.py @@ -616,7 +616,7 @@ def currency_calculator( assert ( currency_calculator(base={"currency": "USD", "amount": 110.11}, quote_currency="EUR") - == '{"currency": "EUR", "amount": 100.1}' + == '{"currency":"EUR","amount":100.1}' ) assert not inspect.iscoroutinefunction(currency_calculator) @@ -654,7 +654,7 @@ async def currency_calculator( assert ( await currency_calculator(base={"currency": "USD", "amount": 110.11}, quote_currency="EUR") - == '{"currency": "EUR", "amount": 100.1}' + == '{"currency":"EUR","amount":100.1}' ) assert inspect.iscoroutinefunction(currency_calculator) diff --git a/website/blog/2024-11-17-Swarm/index.mdx b/website/blog/2024-11-17-Swarm/index.mdx index fb56da9084..4e0b707d1c 100644 --- a/website/blog/2024-11-17-Swarm/index.mdx +++ b/website/blog/2024-11-17-Swarm/index.mdx @@ -51,6 +51,12 @@ Besides these core features, AG2 provides: This feature builds on GroupChat, offering a simpler interface to use swarm orchestration. For comparison, see two implementations of the same example: one [using swarm orchestration](/notebooks/agentchat_swarm) and another [naive implementation with GroupChat (Legacy)](/notebooks/agentchat_swarm_w_groupchat_legacy). +````mdx-code-block +:::note +This blog has been updated as swarms can now accommodate any ConversableAgent. +::: +```` + ## Handoffs Before we dive into a swarm example, an important concept in swarm orchestration is when and how an agent hands off to another agent. @@ -64,12 +70,14 @@ The following are the prioritized handoffs for each iteration of the swarm. 3. **Agent-level: After work hand off**: When no tool calls are made it can use an, optional, `AFTER_WORK` handoff that is a preset option or a nominated swarm agent. 4. **Swarm-level: After work handoff**: If the agent does not have an `AFTER_WORK` handoff, the swarm's `AFTER_WORK` handoff will be used. -In the following code sample a `SwarmAgent` named `responder` has: +In the following code sample a `ConversableAgent` named `responder` has: - Two conditional handoffs registered (`ON_CONDITION`), specifying the agent to hand off to and the condition to trigger the handoff. - An after-work handoff (`AFTER_WORK`) nominated using one of the preset options (`TERMINATE`, `REVERT_TO_USER`, `STAY`). This could also be a swarm agent. ```python -responder.register_hand_off( +from autogen import register_hand_off, ON_CONDITION, AfterWorkOption +register_hand_off( + agent=responder, hand_to=[ ON_CONDITION(weather, "If you need weather data, hand off to the Weather_Agent"), ON_CONDITION(travel_advisor, "If you have weather data but need formatted recommendations, hand off to the Travel_Advisor_Agent"), @@ -91,8 +99,8 @@ history, context, last_agent = initiate_swarm_chat( ## Creating a swarm -1. Define the functions that can be used by your `SwarmAgent`s. -2. Create your `SwarmAgent`s (which derives from `ConversableAgent`). +1. Define the functions that can be used by your `ConversableAgent`s. +2. Create your `ConversableAgent`s. 3. For each swarm agent, specify the handoffs (transitions to another agent) and what to do when they have finished their work (termed *After Work*). 4. Optionally, create your context dictionary. 5. Call `initiate_swarm_chat`. @@ -102,7 +110,7 @@ history, context, last_agent = initiate_swarm_chat( This example of managing refunds demonstrates the context handling, swarm and agent-level conditional and after work hand offs, and the human-in-the-loop feature. ```python -from autogen import initiate_swarm_chat, SwarmAgent, SwarmResult, ON_CONDITION, AFTER_WORK, AfterWorkOption +from autogen import initiate_swarm_chat, ConversableAgent, SwarmResult, ON_CONDITION, AFTER_WORK, AfterWorkOption from autogen import UserProxyAgent import os @@ -118,7 +126,7 @@ context_variables = { } # Functions that our swarm agents will be assigned -# They can return a SwarmResult, a SwarmAgent, or a string +# They can return a SwarmResult, a ConversableAgent, or a string # SwarmResult allows you to update context_variables and/or hand off to another agent def verify_customer_identity(passport_number: str, context_variables: dict) -> str: context_variables["passport_number"] = passport_number @@ -134,7 +142,7 @@ def process_refund_payment(context_variables: dict) -> str: return SwarmResult(values="Payment processed successfully", context_variables=context_variables) # Swarm Agents, similar to ConversableAgent, but with functions and hand offs (specified later) -customer_service = SwarmAgent( +customer_service = ConversableAgent( name="CustomerServiceRep", system_message="""You are a customer service representative. First verify the customer's identity by asking for the customer's passport number, @@ -144,7 +152,7 @@ customer_service = SwarmAgent( functions=[verify_customer_identity], ) -refund_specialist = SwarmAgent( +refund_specialist = ConversableAgent( name="RefundSpecialist", system_message="""You are a refund specialist. Review the case and approve the refund, then transfer to the payment processor.""", @@ -152,7 +160,7 @@ refund_specialist = SwarmAgent( functions=[approve_refund_and_transfer], ) -payment_processor = SwarmAgent( +payment_processor = ConversableAgent( name="PaymentProcessor", system_message="""You are a payment processor. Process the refund payment and provide a confirmation message to the customer.""", @@ -160,7 +168,7 @@ payment_processor = SwarmAgent( functions=[process_refund_payment], ) -satisfaction_surveyor = SwarmAgent( +satisfaction_surveyor = ConversableAgent( name="SatisfactionSurveyor", system_message="""You are a customer satisfaction specialist. Ask the customer to rate their experience with the refund process.""", @@ -169,14 +177,16 @@ satisfaction_surveyor = SwarmAgent( # Conditional and After work hand offs -customer_service.register_hand_off( +register_hand_off( + agent=customer_service, hand_to=[ ON_CONDITION(refund_specialist, "After customer verification, transfer to refund specialist"), AFTER_WORK(AfterWorkOption.REVERT_TO_USER) ] ) -payment_processor.register_hand_off( +register_hand_off( + agent=payment_processor, hand_to=[ AFTER_WORK(satisfaction_surveyor), ] @@ -273,7 +283,7 @@ Next speaker: Tool_Execution Tool_Execution (to chat_manager): ***** Response from calling tool (call_Jz1viRLeJuOltPRcKfYZ8bgH) ***** -SwarmAgent --> RefundSpecialist +Swarm agent --> RefundSpecialist ********************************************************************** -------------------------------------------------------------------------------- @@ -358,7 +368,6 @@ Context Variables: ### Notes - Behind-the-scenes, swarm agents are supported by a tool execution agent, that executes tools on their behalf. Hence, the appearance of `Tool Execution` in the output. -- Currently only swarm agents can be added to a swarm. This is to maintain their ability to manage context variables, auto-execute functions, and support hand offs. Eventually, we may allow ConversableAgent to have the same capability and make "SwarmAgent" a simpler subclass with certain defaults changed (like AssistantAgent and UserProxyAgent). - Would you like to enhance the swarm feature or have found a bug? Please let us know by creating an issue on the [AG2 GitHub](https://github.com/ag2ai/ag2/issues). ## For Further Reading diff --git a/website/blog/2024-12-20-RealtimeAgent/index.mdx b/website/blog/2024-12-20-RealtimeAgent/index.mdx index 931fe0b24b..0171e72050 100644 --- a/website/blog/2024-12-20-RealtimeAgent/index.mdx +++ b/website/blog/2024-12-20-RealtimeAgent/index.mdx @@ -215,7 +215,7 @@ FLIGHT_CANCELLATION_POLICY = """ #### **Agents Definition** ```python -triage_agent = SwarmAgent( +triage_agent = ConversableAgent( name="Triage_Agent", system_message=triage_instructions(context_variables=context_variables), llm_config=llm_config, @@ -225,7 +225,7 @@ triage_agent = SwarmAgent( - **Triage Agent:** Routes the user's request to the appropriate specialized agent based on the topic. ```python -flight_cancel = SwarmAgent( +flight_cancel = ConversableAgent( name="Flight_Cancel_Traversal", system_message=STARTER_PROMPT + FLIGHT_CANCELLATION_POLICY, llm_config=llm_config, @@ -235,8 +235,9 @@ flight_cancel = SwarmAgent( - **Flight Cancel Agent:** Handles cancellations, including refunds and flight credits, while ensuring policy steps are strictly followed. ```python -flight_modification.register_hand_off( - [ +register_hand_off( + agent=flight_modification, + hand_to=[ ON_CONDITION(flight_cancel, "To cancel a flight"), ON_CONDITION(flight_change, "To change a flight"), ] diff --git a/website/docs/topics/swarm.ipynb b/website/docs/topics/swarm.ipynb index 53caaee7e4..bc124833d2 100644 --- a/website/docs/topics/swarm.ipynb +++ b/website/docs/topics/swarm.ipynb @@ -11,7 +11,7 @@ "- **Headoffs**: Agents can transfer control to another agent via function calls, enabling smooth transitions within workflows. \n", "- **Context Variables**: Agents can dynamically update shared variables through function calls, maintaining context and adaptability throughout the process.\n", "\n", - "Instead of sending a task to a single LLM agent, you can assign it to a swarm of agents. Each agent in the swarm can decide whether to hand off the task to another agent. The chat terminates when the last active agent's response is a plain string (i.e., it doesn't suggest a tool call or handoff). " + "Instead of sending a task to a single LLM agent, you can assign it to a swarm of agents. Each agent in the swarm can decide whether to hand off the task to another agent. The chat terminates when the last active agent's response is a plain string (i.e., it doesn't suggest a tool call or handoff)." ] }, { @@ -21,9 +21,11 @@ "## Components\n", "We now introduce the main components that need to be used to create a swarm chat. \n", "\n", - "### Create a `SwarmAgent`\n", + "### Agents\n", "\n", - "All the agents passed to the swarm chat should be instances of `SwarmAgent`. `SwarmAgent` is very similar to `AssistantAgent`, but it has some additional features to support function registration and handoffs. When creating a `SwarmAgent`, you can pass in a list of functions. These functions will be converted to schemas to be passed to the LLMs, and you don't need to worry about registering the functions for execution. You can also pass back a `SwarmResult` class, where you can return a value, the next agent to call, and update context variables at the same time.\n", + "Any ConversableAgent-based agent can participate in a swarm. Agents will automatically be given additional features to support their participation in the swarm.\n", + "\n", + "When creating an agent, you can pass in a list of functions (through the `functions` parameter upon initialization). These functions will be converted to schemas to be passed to the LLMs, and you don't need to worry about registering the functions for execution. You can also pass back a `SwarmResult` class, where you can return a value, the next agent to call, and update context variables at the same time.\n", "\n", "**Notes for creating the function calls** \n", "- For input arguments, you must define the type of the argument, otherwise, the registration will fail (e.g. `arg_name: str`). \n", @@ -35,12 +37,14 @@ "While you can create a function to decide what next agent to call, we provide a quick way to register the handoff using `ON_CONDITION`. We will craft this transition function and add it to the LLM config directly.\n", "\n", "```python\n", - "agent_2 = SwarmAgent(...)\n", - "agent_3 = SwarmAgent(...)\n", + "from autogen import register_hand_off, ConversableAgent, ON_CONDITION\n", + "\n", + "agent_2 = ConversableAgent(...)\n", + "agent_3 = ConversableAgent(...)\n", "\n", - "# Register the handoff\n", - "agent_1 = SwarmAgent(...)\n", - "agent_1.handoff(hand_to=[ON_CONDITION(agent_2, \"condition_1\"), ON_CONDITION(agent_3, \"condition_2\")])\n", + "# Register the handoff using register_hand_off\n", + "agent_1 = ConversableAgent(...)\n", + "register_hand_off(agent=agent_1, hand_to=[ON_CONDITION(agent_2, \"condition_1\"), ON_CONDITION(agent_3, \"condition_2\")])\n", "\n", "# This is equivalent to:\n", "def transfer_to_agent_2():\n", @@ -51,8 +55,8 @@ " \"\"\"condition_2\"\"\"\n", " return agent_3\n", " \n", - "agent_1 = SwarmAgent(..., functions=[transfer_to_agent_2, transfer_to_agent_3])\n", - "# You can also use agent_1.add_functions to add more functions after initialization\n", + "agent_1 = ConversableAgent(..., functions=[transfer_to_agent_2, transfer_to_agent_3])\n", + "# You can also use agent_1._add_functions to add more functions after initialization\n", "```\n", "\n", "### Registering Handoffs to a nested chat\n", @@ -121,7 +125,8 @@ "Finally, we add the nested chat as a handoff in the same way as we do to an agent:\n", "\n", "```python\n", - "agent_1.handoff(\n", + "register_hand_off(\n", + " agent=agent_1,\n", " hand_to=[ON_CONDITION(\n", " target={\n", " \"chat_queue\":[nested_chats],\n", @@ -156,7 +161,7 @@ "- `REVERT_TO_USER`: Revert to the user agent. Only if a user agent is passed in when initializing. (See below for more details)\n", "\n", "The callable function signature is:\n", - "`def my_after_work_func(last_speaker: SwarmAgent, messages: List[Dict[str, Any]], groupchat: GroupChat) -> Union[AfterWorkOption, SwarmAgent, str]:`\n", + "`def my_after_work_func(last_speaker: ConversableAgent, messages: List[Dict[str, Any]], groupchat: GroupChat) -> Union[AfterWorkOption, ConversableAgent, str]:`\n", "\n", "Note: there should only be one `AFTER_WORK`, if your requirement is more complex, use the callable function parameter.\n", "\n", @@ -164,23 +169,23 @@ "\n", "```python\n", "# Register the handoff to an agent\n", - "agent_1.handoff(hand_to=[\n", + "register_hand_off(agent=agent_1, hand_to=[\n", " ON_CONDITION(...), \n", " ON_CONDITION(...),\n", " AFTER_WORK(agent_4) # Fallback to agent_4 if no ON_CONDITION handoff is suggested\n", "])\n", "\n", "# Register the handoff to an AfterWorkOption\n", - "agent_2.handoff(hand_to=[AFTER_WORK(AfterWorkOption.TERMINATE)]) # Terminate the chat if no handoff is suggested\n", + "register_hand_off(agent=agent_2, hand_to=[AFTER_WORK(AfterWorkOption.TERMINATE)]) # Terminate the chat if no handoff is suggested\n", "\n", - "def my_after_work_func(last_speaker: SwarmAgent, messages: List[Dict[str, Any]], groupchat: GroupChat) -> Union[AfterWorkOption, SwarmAgent, str]:\n", + "def my_after_work_func(last_speaker: ConversableAgent, messages: List[Dict[str, Any]], groupchat: GroupChat) -> Union[AfterWorkOption, ConversableAgent, str]:\n", " if last_speaker.get_context(\"agent_1_done\"):\n", " return agent_2\n", " else:\n", " return AfterWorkOption.TERMINATE\n", "\n", "# Register the handoff to a function that will return an agent or AfterWorkOption\n", - "agent_3.handoff(hand_to=[AFTER_WORK(my_after_work_func)])\n", + "register_hand_off(agent=agent_3, hand_to=[AFTER_WORK(my_after_work_func)])\n", "\n", "# Register the swarm level AFTER_WORK that becomes the default for agents that don't have one specified\n", "chat_history, context_variables, last_active_agent = initiate_swarm_chat(\n", @@ -200,7 +205,7 @@ "\n", "It can be useful to update a swarm agent's state before they reply. For example, using an agent's context variables you could change their system message based on the state of the workflow.\n", "\n", - "When initialising a swarm agent use the `update_agent_state_before_reply` parameter to register updates that run after the agent is selected, but before they reply.\n", + "When initialising an agent use the `update_agent_state_before_reply` parameter to register updates that run after the agent is selected, but before they reply.\n", "\n", "`update_agent_state_before_reply` takes a list of any combination of the following (executing them in the provided order):\n", "\n", @@ -210,6 +215,8 @@ "Below is an example of setting these up when creating a Swarm agent.\n", "\n", "```python\n", + "from autogen import UPDATE_SYSTEM_MESSAGE, ConversableAgent\n", + "\n", "# Creates a system message string\n", "def create_system_prompt_function(my_agent: ConversableAgent, messages: List[Dict[]]) -> str:\n", " preferred_name = my_agent.get_context(\"preferred_name\", \"(name not provided)\")\n", @@ -224,8 +231,8 @@ " agent.set_context(\"context_key\", 43)\n", " agent.update_system_message(\"You are a customer service representative.\")\n", "\n", - "# Create the SwarmAgent and set agent updates\n", - "customer_service = SwarmAgent(\n", + "# Create the swarm agent and set agent updates\n", + "customer_service = ConversableAgent(\n", " name=\"CustomerServiceRep\",\n", " system_message=\"You are a customer service representative.\",\n", " update_agent_state_before_reply=[\n", @@ -320,9 +327,10 @@ " AFTER_WORK,\n", " ON_CONDITION,\n", " AfterWorkOption,\n", - " SwarmAgent,\n", + " ConversableAgent,\n", " SwarmResult,\n", " initiate_swarm_chat,\n", + " register_hand_off,\n", ")\n", "\n", "\n", @@ -332,8 +340,8 @@ " return SwarmResult(value=\"success\", context_variables=context_variables)\n", "\n", "\n", - "# 2. A function that returns an SwarmAgent object\n", - "def transfer_to_agent_2() -> SwarmAgent:\n", + "# 2. A function that returns a ConversableAgent object\n", + "def transfer_to_agent_2() -> ConversableAgent:\n", " \"\"\"Transfer to agent 2\"\"\"\n", " return agent_2\n", "\n", @@ -354,34 +362,34 @@ " return SwarmResult(value=\"success\", context_variables=context_variables)\n", "\n", "\n", - "agent_1 = SwarmAgent(\n", + "agent_1 = ConversableAgent(\n", " name=\"Agent_1\",\n", " system_message=\"You are Agent 1, first, call the function to update context 1, and transfer to Agent 2\",\n", " llm_config=llm_config,\n", " functions=[update_context_1, transfer_to_agent_2],\n", ")\n", "\n", - "agent_2 = SwarmAgent(\n", + "agent_2 = ConversableAgent(\n", " name=\"Agent_2\",\n", " system_message=\"You are Agent 2, call the function that updates context 2 and transfer to Agent 3\",\n", " llm_config=llm_config,\n", " functions=[update_context_2_and_transfer_to_3],\n", ")\n", "\n", - "agent_3 = SwarmAgent(\n", + "agent_3 = ConversableAgent(\n", " name=\"Agent_3\",\n", " system_message=\"You are Agent 3, tell a joke\",\n", " llm_config=llm_config,\n", ")\n", "\n", - "agent_4 = SwarmAgent(\n", + "agent_4 = ConversableAgent(\n", " name=\"Agent_4\",\n", " system_message=\"You are Agent 4, call the function to get a random number\",\n", " llm_config=llm_config,\n", " functions=[get_random_number],\n", ")\n", "\n", - "agent_5 = SwarmAgent(\n", + "agent_5 = ConversableAgent(\n", " name=\"Agent_5\",\n", " system_message=\"Update context 3 with the random number.\",\n", " llm_config=llm_config,\n", @@ -390,9 +398,9 @@ "\n", "\n", "# This is equivalent to writing a transfer function\n", - "agent_3.register_hand_off(ON_CONDITION(agent_4, \"Transfer to Agent 4\"))\n", + "register_hand_off(agent=agent_3, hand_to=ON_CONDITION(agent_4, \"Transfer to Agent 4\"))\n", "\n", - "agent_4.register_hand_off([AFTER_WORK(agent_5)])\n", + "register_hand_off(agent=agent_4, hand_to=[AFTER_WORK(agent_5)])\n", "\n", "print(\"Agent 1 function schema:\")\n", "for func_schema in agent_1.llm_config[\"tools\"]:\n", @@ -608,7 +616,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -701,25 +709,26 @@ "\n", "user_agent = UserProxyAgent(name=\"User\", code_execution_config=False)\n", "\n", - "agent_6 = SwarmAgent(\n", + "agent_6 = ConversableAgent(\n", " name=\"Agent_6\",\n", " system_message=\"You are Agent 6. Your job is to tell jokes.\",\n", " llm_config=llm_config,\n", ")\n", "\n", - "agent_7 = SwarmAgent(\n", + "agent_7 = ConversableAgent(\n", " name=\"Agent_7\",\n", " system_message=\"You are Agent 7, explain the joke.\",\n", " llm_config=llm_config,\n", ")\n", "\n", - "agent_6.register_hand_off(\n", - " [\n", + "register_hand_off(\n", + " agent=agent_6,\n", + " hand_to=[\n", " ON_CONDITION(\n", " agent_7, \"Used to transfer to Agent 7. Don't call this function, unless the user explicitly tells you to.\"\n", " ),\n", " AFTER_WORK(AfterWorkOption.REVERT_TO_USER),\n", - " ]\n", + " ],\n", ")\n", "\n", "chat_result, _, _ = initiate_swarm_chat(\n",