disable parallel tool use

This commit is contained in:
Chester Curme
2025-01-17 10:15:06 -05:00
parent b35b892d74
commit 784b6afa11
+54 -31
View File
@@ -1180,7 +1180,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "08439bb4-91e8-4abb-a57a-2511877abcb7", "id": "da81116c-73f6-410a-858a-3a362dc16dd3",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -1222,7 +1222,13 @@
"tool = TavilySearchResults(max_results=2)\n", "tool = TavilySearchResults(max_results=2)\n",
"tools = [tool, human_assistance]\n", "tools = [tool, human_assistance]\n",
"llm = ChatAnthropic(model=\"claude-3-5-sonnet-20240620\")\n", "llm = ChatAnthropic(model=\"claude-3-5-sonnet-20240620\")\n",
"llm_with_tools = llm.bind_tools(tools)\n", "llm_with_tools = llm.bind_tools(\n",
" tools,\n",
" # Because we will be interrupting during tool execution,\n",
" # we disable parallel tool calling to avoid repeating any\n",
" # tool invocations when we resume.\n",
" tool_choice={\"type\": \"any\", \"disable_parallel_tool_use\": True},\n",
")\n",
"\n", "\n",
"\n", "\n",
"def chatbot(state: State):\n", "def chatbot(state: State):\n",
@@ -1260,7 +1266,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 2,
"id": "16cc6b14-f758-4590-beb7-7b76a6841521", "id": "16cc6b14-f758-4590-beb7-7b76a6841521",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -1280,7 +1286,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 3,
"id": "22ff19af-5a5b-4ca5-82d8-6a38445c24af", "id": "22ff19af-5a5b-4ca5-82d8-6a38445c24af",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@@ -1315,7 +1321,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 4,
"id": "9f318020-ab7e-415b-a5e2-eddec6d9f3a6", "id": "9f318020-ab7e-415b-a5e2-eddec6d9f3a6",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@@ -1328,12 +1334,12 @@
"I need some expert guidance for building an AI agent. Could you request assistance for me?\n", "I need some expert guidance for building an AI agent. Could you request assistance for me?\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n", "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"\n", "\n",
"[{'text': \"Certainly! I'd be happy to request expert assistance for you regarding building an AI agent. To do this, I'll use the human_assistance function to relay your request. Let me do that for you now.\", 'type': 'text'}, {'id': 'toolu_015tcCygn4UdBM24vg9NSycp', 'input': {'query': 'A user is seeking expert guidance for building an AI agent. Can you provide some professional advice or resources on this topic?'}, 'name': 'human_assistance', 'type': 'tool_use'}]\n", "[{'text': \"Certainly! I'd be happy to request expert assistance for you regarding building an AI agent. I'll use the human assistance function to ask for this guidance. Let me do that for you right away.\", 'type': 'text'}, {'id': 'toolu_01XufxDDxm3tXvuuX9h7C7v2', 'input': {'query': 'A user is seeking expert guidance for building an AI agent. Could you provide some key points or steps to consider when developing an AI agent?'}, 'name': 'human_assistance', 'type': 'tool_use'}]\n",
"Tool Calls:\n", "Tool Calls:\n",
" human_assistance (toolu_015tcCygn4UdBM24vg9NSycp)\n", " human_assistance (toolu_01XufxDDxm3tXvuuX9h7C7v2)\n",
" Call ID: toolu_015tcCygn4UdBM24vg9NSycp\n", " Call ID: toolu_01XufxDDxm3tXvuuX9h7C7v2\n",
" Args:\n", " Args:\n",
" query: A user is seeking expert guidance for building an AI agent. Can you provide some professional advice or resources on this topic?\n" " query: A user is seeking expert guidance for building an AI agent. Could you provide some key points or steps to consider when developing an AI agent?\n"
] ]
} }
], ],
@@ -1359,7 +1365,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 5,
"id": "9f511371-98b6-4513-b450-9143778f12dc", "id": "9f511371-98b6-4513-b450-9143778f12dc",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@@ -1369,7 +1375,7 @@
"('tools',)" "('tools',)"
] ]
}, },
"execution_count": 6, "execution_count": 5,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -1401,7 +1407,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 6,
"id": "df6d81bb-e674-44ef-a46e-17b1a8d2381a", "id": "df6d81bb-e674-44ef-a46e-17b1a8d2381a",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@@ -1411,32 +1417,40 @@
"text": [ "text": [
"==================================\u001b[1m Ai Message \u001b[0m==================================\n", "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"\n", "\n",
"[{'text': \"Certainly! I'd be happy to request expert assistance for you regarding building an AI agent. To do this, I'll use the human_assistance function to relay your request. Let me do that for you now.\", 'type': 'text'}, {'id': 'toolu_015tcCygn4UdBM24vg9NSycp', 'input': {'query': 'A user is seeking expert guidance for building an AI agent. Can you provide some professional advice or resources on this topic?'}, 'name': 'human_assistance', 'type': 'tool_use'}]\n", "[{'text': \"Certainly! I'd be happy to request expert assistance for you regarding building an AI agent. I'll use the human assistance function to ask for this guidance. Let me do that for you right away.\", 'type': 'text'}, {'id': 'toolu_01XufxDDxm3tXvuuX9h7C7v2', 'input': {'query': 'A user is seeking expert guidance for building an AI agent. Could you provide some key points or steps to consider when developing an AI agent?'}, 'name': 'human_assistance', 'type': 'tool_use'}]\n",
"Tool Calls:\n", "Tool Calls:\n",
" human_assistance (toolu_015tcCygn4UdBM24vg9NSycp)\n", " human_assistance (toolu_01XufxDDxm3tXvuuX9h7C7v2)\n",
" Call ID: toolu_015tcCygn4UdBM24vg9NSycp\n", " Call ID: toolu_01XufxDDxm3tXvuuX9h7C7v2\n",
" Args:\n", " Args:\n",
" query: A user is seeking expert guidance for building an AI agent. Can you provide some professional advice or resources on this topic?\n", " query: A user is seeking expert guidance for building an AI agent. Could you provide some key points or steps to consider when developing an AI agent?\n",
"=================================\u001b[1m Tool Message \u001b[0m=================================\n", "=================================\u001b[1m Tool Message \u001b[0m=================================\n",
"Name: human_assistance\n", "Name: human_assistance\n",
"\n", "\n",
"We, the experts are here to help! We'd recommend you check out LangGraph to build your agent. It's much more reliable and extensible than simple autonomous agents.\n", "We, the experts are here to help! We'd recommend you check out LangGraph to build your agent. It's much more reliable and extensible than simple autonomous agents.\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n", "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"\n", "\n",
"Thank you for your patience. I've received a response from the expert assistance. Here's the advice they provided:\n", "Thank you for your patience. I've received some expert advice regarding building an AI agent. Here's the guidance provided:\n",
"\n", "\n",
"The experts recommend that you check out LangGraph for building your AI agent. They suggest that LangGraph is a more reliable and extensible option compared to simple autonomous agents.\n", "The experts recommend looking into LangGraph for building your AI agent. They suggest that LangGraph is a more reliable and extensible option compared to simple autonomous agents.\n",
"\n", "\n",
"LangGraph is likely a framework or library designed specifically for creating AI agents. It seems to offer advantages in terms of reliability and extensibility, which are crucial factors when developing complex AI systems.\n", "LangGraph is a framework designed to help developers create more complex and capable AI agents. Here are a few key points about LangGraph:\n",
"\n", "\n",
"To follow up on this recommendation, you might want to:\n", "1. Reliability: LangGraph is noted for being more reliable than simpler agent architectures, which can be crucial for developing robust AI systems.\n",
"\n", "\n",
"1. Research LangGraph: Look for its official documentation, tutorials, and any community resources.\n", "2. Extensibility: The framework offers greater flexibility and extensibility, allowing you to create more sophisticated and adaptable AI agents.\n",
"2. Compare LangGraph with other agent-building frameworks to understand its unique benefits.\n",
"3. Check if LangGraph aligns with your specific goals and requirements for your AI agent project.\n",
"4. Look for examples or case studies of AI agents built with LangGraph to get a better idea of its capabilities.\n",
"\n", "\n",
"Would you like me to search for more specific information about LangGraph or any other aspect of building AI agents?\n" "3. Advanced Capabilities: LangGraph likely provides tools and structures for creating agents with more complex behaviors and decision-making processes.\n",
"\n",
"4. Structured Development: Using a framework like LangGraph can provide a more organized approach to building AI agents, potentially simplifying the development process.\n",
"\n",
"To get started with LangGraph, you might want to:\n",
"\n",
"1. Research LangGraph documentation and tutorials.\n",
"2. Understand the core concepts and components of the framework.\n",
"3. Set up your development environment to work with LangGraph.\n",
"4. Start with simple projects to familiarize yourself with its features before moving on to more complex agent designs.\n",
"\n",
"Would you like more specific information about LangGraph or any particular aspect of building AI agents? I'd be happy to request further assistance or search for more detailed information if needed.\n"
] ]
} }
], ],
@@ -1502,7 +1516,10 @@
"tool = TavilySearchResults(max_results=2)\n", "tool = TavilySearchResults(max_results=2)\n",
"tools = [tool, human_assistance]\n", "tools = [tool, human_assistance]\n",
"llm = ChatAnthropic(model=\"claude-3-5-sonnet-20240620\")\n", "llm = ChatAnthropic(model=\"claude-3-5-sonnet-20240620\")\n",
"llm_with_tools = llm.bind_tools(tools)\n", "llm_with_tools = llm.bind_tools(\n",
" tools,\n",
" tool_choice={\"type\": \"any\", \"disable_parallel_tool_use\": True},\n",
")\n",
"\n", "\n",
"\n", "\n",
"def chatbot(state: State):\n", "def chatbot(state: State):\n",
@@ -1540,7 +1557,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 7,
"id": "84627103-bcc8-4645-bd37-b93209fa09dd", "id": "84627103-bcc8-4645-bd37-b93209fa09dd",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -1572,7 +1589,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 8,
"id": "c4b65504-92c7-4c82-a6ee-824885d1a8a4", "id": "c4b65504-92c7-4c82-a6ee-824885d1a8a4",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -1631,7 +1648,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 9,
"id": "e256fa2e-6c13-42dd-a0a5-d206ee4139bf", "id": "e256fa2e-6c13-42dd-a0a5-d206ee4139bf",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -1647,7 +1664,10 @@
"tool = TavilySearchResults(max_results=2)\n", "tool = TavilySearchResults(max_results=2)\n",
"tools = [tool, human_assistance]\n", "tools = [tool, human_assistance]\n",
"llm = ChatAnthropic(model=\"claude-3-5-sonnet-20240620\")\n", "llm = ChatAnthropic(model=\"claude-3-5-sonnet-20240620\")\n",
"llm_with_tools = llm.bind_tools(tools)\n", "llm_with_tools = llm.bind_tools(\n",
" tools,\n",
" tool_choice={\"type\": \"any\", \"disable_parallel_tool_use\": True},\n",
")\n",
"\n", "\n",
"\n", "\n",
"def chatbot(state: State):\n", "def chatbot(state: State):\n",
@@ -1966,7 +1986,10 @@
"tool = TavilySearchResults(max_results=2)\n", "tool = TavilySearchResults(max_results=2)\n",
"tools = [tool, human_assistance]\n", "tools = [tool, human_assistance]\n",
"llm = ChatAnthropic(model=\"claude-3-5-sonnet-20240620\")\n", "llm = ChatAnthropic(model=\"claude-3-5-sonnet-20240620\")\n",
"llm_with_tools = llm.bind_tools(tools)\n", "llm_with_tools = llm.bind_tools(\n",
" tools,\n",
" tool_choice={\"type\": \"any\", \"disable_parallel_tool_use\": True},\n",
")\n",
"\n", "\n",
"\n", "\n",
"def chatbot(state: State):\n", "def chatbot(state: State):\n",