diff --git a/notebook/agentchat_swarm_enhanced.ipynb b/notebook/agentchat_swarm_enhanced.ipynb index 101737f87a..2a368f621a 100644 --- a/notebook/agentchat_swarm_enhanced.ipynb +++ b/notebook/agentchat_swarm_enhanced.ipynb @@ -46,9 +46,18 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n" + ] + } + ], "source": [ "import autogen\n", "\n", @@ -86,7 +95,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -114,7 +123,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -140,7 +149,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -195,7 +204,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -267,7 +276,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -341,7 +350,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -395,7 +404,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -461,9 +470,424 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "Can you help me with my order.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: order_triage_agent\n", + "\u001b[0m\n", + "\u001b[33morder_triage_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_RhIdaMav5FoXxvXiYhyDoivV): transfer_order_triage_agent_to_authentication_agent *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m********************************************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION transfer_order_triage_agent_to_authentication_agent...\u001b[0m\n", + "\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", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: authentication_agent\n", + "\u001b[0m\n", + "\u001b[33mauthentication_agent\u001b[0m (to chat_manager):\n", + "\n", + "I can assist you with your order, but first, I'll need to verify your identity. Please provide your username.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "barry\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: authentication_agent\n", + "\u001b[0m\n", + "\u001b[33mauthentication_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_gEx5FZ86W62p1vXCVNAkue7t): login_customer_by_username *****\u001b[0m\n", + "Arguments: \n", + "{\"username\":\"barry\"}\n", + "\u001b[32m*******************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION login_customer_by_username...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_gEx5FZ86W62p1vXCVNAkue7t) *****\u001b[0m\n", + "User barry not found. Please ask for the correct username.\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: authentication_agent\n", + "\u001b[0m\n", + "\u001b[33mauthentication_agent\u001b[0m (to chat_manager):\n", + "\n", + "It seems that there is no account associated with the username \"barry.\" Could you please double-check and provide the correct username?\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "mark\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: authentication_agent\n", + "\u001b[0m\n", + "\u001b[33mauthentication_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_XmbzzNw7PsYFYsTSVKoylATA): login_customer_by_username *****\u001b[0m\n", + "Arguments: \n", + "{\"username\":\"mark\"}\n", + "\u001b[32m*******************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION login_customer_by_username...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_XmbzzNw7PsYFYsTSVKoylATA) *****\u001b[0m\n", + "Welcome back our customer, Mark Sze! Please continue helping them.\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: order_triage_agent\n", + "\u001b[0m\n", + "\u001b[33morder_triage_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_mXHJHDzVPTXWDhll0UH7w3QI): transfer_order_triage_agent_to_order_mgmt_agent *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m****************************************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION transfer_order_triage_agent_to_order_mgmt_agent...\u001b[0m\n", + "\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", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: order_mgmt_agent\n", + "\u001b[0m\n", + "\u001b[33morder_mgmt_agent\u001b[0m (to chat_manager):\n", + "\n", + "Sure, Mark! Could you please provide me with the Order ID you are enquiring about?\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "TR14234\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: order_mgmt_agent\n", + "\u001b[0m\n", + "\u001b[33morder_mgmt_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_UMS0fVQEAW9Hkqo3paa6ZDp5): check_order_id *****\u001b[0m\n", + "Arguments: \n", + "{\"order_id\": \"TR14234\"}\n", + "\u001b[32m*******************************************************************************\u001b[0m\n", + "\u001b[32m***** Suggested tool call (call_ERAQ8vgnCagMuvCthkZ6E5l7): record_order_id *****\u001b[0m\n", + "Arguments: \n", + "{\"order_id\": \"TR14234\"}\n", + "\u001b[32m********************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION check_order_id...\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION record_order_id...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_UMS0fVQEAW9Hkqo3paa6ZDp5) *****\u001b[0m\n", + "Order ID TR14234 is invalid. Please ask for the correct order ID.\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m***** Response from calling tool (call_ERAQ8vgnCagMuvCthkZ6E5l7) *****\u001b[0m\n", + "Order ID Recorded: TR14234\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: order_mgmt_agent\n", + "\u001b[0m\n", + "\u001b[33morder_mgmt_agent\u001b[0m (to chat_manager):\n", + "\n", + "It seems that the Order ID \"TR14234\" is invalid. Could you please double-check and provide the correct Order ID?\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "TR14234\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: order_mgmt_agent\n", + "\u001b[0m\n", + "\u001b[33morder_mgmt_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_DqbSSNveiHpMydYE7pOyfkaP): check_order_id *****\u001b[0m\n", + "Arguments: \n", + "{\"order_id\":\"TR14234\"}\n", + "\u001b[32m*******************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION check_order_id...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_DqbSSNveiHpMydYE7pOyfkaP) *****\u001b[0m\n", + "Order ID TR14234 is invalid. Please ask for the correct order ID.\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: order_triage_agent\n", + "\u001b[0m\n", + "\u001b[33morder_triage_agent\u001b[0m (to chat_manager):\n", + "\n", + "The Order ID \"TR14234\" still appears to be invalid. Could you please verify and provide the correct Order ID or any additional information that might help us find your order?\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "TR13845\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: order_triage_agent\n", + "\u001b[0m\n", + "\u001b[33morder_triage_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_miEIpNwDd1FFGLenwUB3oPMq): check_order_id *****\u001b[0m\n", + "Arguments: \n", + "{\"order_id\": \"TR13845\"}\n", + "\u001b[32m*******************************************************************************\u001b[0m\n", + "\u001b[32m***** Suggested tool call (call_uHRdFcp41PIp4KWCuHUdWQxo): record_order_id *****\u001b[0m\n", + "Arguments: \n", + "{\"order_id\": \"TR13845\"}\n", + "\u001b[32m********************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION check_order_id...\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION record_order_id...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_miEIpNwDd1FFGLenwUB3oPMq) *****\u001b[0m\n", + "Order ID TR13845 is valid.\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m***** Response from calling tool (call_uHRdFcp41PIp4KWCuHUdWQxo) *****\u001b[0m\n", + "Order ID Recorded: TR13845\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: order_mgmt_agent\n", + "\u001b[0m\n", + "\u001b[33morder_mgmt_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_sYsVS1U3k3Cf2KbqKJ4hhyRa): transfer_order_mgmt_agent_to_nested_chat_order_mgmt_agent_1 *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m****************************************************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION transfer_order_mgmt_agent_to_nested_chat_order_mgmt_agent_1...\u001b[0m\n", + "\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", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: nested_chat_order_mgmt_agent_1\n", + "\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[34mStarting a new chat....\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[33mnested_chat_order_mgmt_agent_1\u001b[0m (to order_retrieval_agent):\n", + "\n", + "Order TR13845 for matress is currently shipped. The shipping address is 123 Main St, State College, PA 12345.\n", + "Context:\n", + "Order ID TR13845 is valid.\n", + "Order ID Recorded: TR13845\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33morder_retrieval_agent\u001b[0m (to nested_chat_order_mgmt_agent_1):\n", + "\n", + "It looks like order TR13845 for a mattress has been shipped. The shipping address for this order is 123 Main St, State College, PA 12345. If you need further details about this order, just let me know!\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[34mStarting a new chat....\u001b[0m\n", + "\u001b[34m\n", + "********************************************************************************\u001b[0m\n", + "\u001b[33mnested_chat_order_mgmt_agent_1\u001b[0m (to order_summariser_agent):\n", + "\n", + "Summarise the order details provided in a tabulated, text-based, order sheet format\n", + "Context: \n", + "It looks like order TR13845 for a mattress has been shipped. The shipping address for this order is 123 Main St, State College, PA 12345. If you need further details about this order, just let me know!\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[31m\n", + ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", + "\u001b[33morder_summariser_agent\u001b[0m (to nested_chat_order_mgmt_agent_1):\n", + "\n", + "```\n", + "Order Summary:\n", + "----------------------------------------------------\n", + "Order Number : TR13845\n", + "Product : Mattress\n", + "Status : Shipped\n", + "Shipping Address : 123 Main St, \n", + " State College, PA 12345\n", + "----------------------------------------------------\n", + "```\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[33mnested_chat_order_mgmt_agent_1\u001b[0m (to chat_manager):\n", + "\n", + "```\n", + "Order Summary:\n", + "----------------------------------------------------\n", + "Order Number : TR13845\n", + "Product : Mattress\n", + "Status : Shipped\n", + "Shipping Address : 123 Main St, \n", + " State College, PA 12345\n", + "----------------------------------------------------\n", + "```\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: order_mgmt_agent\n", + "\u001b[0m\n", + "\u001b[33morder_mgmt_agent\u001b[0m (to chat_manager):\n", + "\n", + "Your order with the Order Number TR13845, which involves a \"Mattress,\" has already been shipped. It is on its way to 123 Main St, State College, PA 12345. \n", + "\n", + "If you have any more questions or need further assistance, feel free to ask!\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "All good\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: order_mgmt_agent\n", + "\u001b[0m\n", + "\u001b[33morder_mgmt_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_VtBmcKhDAhh7JUz9aXyPq9Aj): transfer_order_mgmt_agent_to_order_triage_agent *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m****************************************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION transfer_order_mgmt_agent_to_order_triage_agent...\u001b[0m\n", + "\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", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: order_triage_agent\n", + "\u001b[0m\n", + "\u001b[33morder_triage_agent\u001b[0m (to chat_manager):\n", + "\n", + "I'm glad we could assist you, Mark! If you have any more inquiries in the future or need further support, feel free to reach out. Have a great day!\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n" + ] + } + ], "source": [ "chat_history = initiate_swarm_chat(\n", " initial_agent=order_triage_agent,\n",