From 02ea5238971335f8dc01cd55dac674d5663c71a8 Mon Sep 17 00:00:00 2001 From: Chester Curme Date: Fri, 17 Jan 2025 11:02:25 -0500 Subject: [PATCH] udpate --- docs/docs/tutorials/introduction.ipynb | 90 +++++++++++++++----------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/docs/docs/tutorials/introduction.ipynb b/docs/docs/tutorials/introduction.ipynb index 8e40e8b66..cf6c15ca0 100644 --- a/docs/docs/tutorials/introduction.ipynb +++ b/docs/docs/tutorials/introduction.ipynb @@ -1227,7 +1227,12 @@ "\n", "\n", "def chatbot(state: State):\n", - " return {\"messages\": [llm_with_tools.invoke(state[\"messages\"])]}\n", + " message = llm_with_tools.invoke(state[\"messages\"])\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", + " assert(len(message.tool_calls) <= 1)\n", + " return {\"messages\": [message]}\n", "\n", "\n", "graph_builder.add_node(\"chatbot\", chatbot)\n", @@ -1261,7 +1266,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "16cc6b14-f758-4590-beb7-7b76a6841521", "metadata": {}, "outputs": [], @@ -1281,7 +1286,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "22ff19af-5a5b-4ca5-82d8-6a38445c24af", "metadata": {}, "outputs": [ @@ -1316,7 +1321,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "id": "9f318020-ab7e-415b-a5e2-eddec6d9f3a6", "metadata": {}, "outputs": [ @@ -1329,12 +1334,12 @@ "I need some expert guidance for building an AI agent. Could you request assistance for me?\n", "==================================\u001b[1m Ai Message \u001b[0m==================================\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. 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_01ABUqneqnuHNuo1vhfDFQCW', 'input': {'query': 'A user is requesting expert guidance for building an AI agent. Could you please provide some expert advice or resources on this topic?'}, 'name': 'human_assistance', 'type': 'tool_use'}]\n", "Tool Calls:\n", - " human_assistance (toolu_015tcCygn4UdBM24vg9NSycp)\n", - " Call ID: toolu_015tcCygn4UdBM24vg9NSycp\n", + " human_assistance (toolu_01ABUqneqnuHNuo1vhfDFQCW)\n", + " Call ID: toolu_01ABUqneqnuHNuo1vhfDFQCW\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 requesting expert guidance for building an AI agent. Could you please provide some expert advice or resources on this topic?\n" ] } ], @@ -1360,7 +1365,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "9f511371-98b6-4513-b450-9143778f12dc", "metadata": {}, "outputs": [ @@ -1370,7 +1375,7 @@ "('tools',)" ] }, - "execution_count": 6, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -1402,7 +1407,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "df6d81bb-e674-44ef-a46e-17b1a8d2381a", "metadata": {}, "outputs": [ @@ -1412,32 +1417,37 @@ "text": [ "==================================\u001b[1m Ai Message \u001b[0m==================================\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. 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_01ABUqneqnuHNuo1vhfDFQCW', 'input': {'query': 'A user is requesting expert guidance for building an AI agent. Could you please provide some expert advice or resources on this topic?'}, 'name': 'human_assistance', 'type': 'tool_use'}]\n", "Tool Calls:\n", - " human_assistance (toolu_015tcCygn4UdBM24vg9NSycp)\n", - " Call ID: toolu_015tcCygn4UdBM24vg9NSycp\n", + " human_assistance (toolu_01ABUqneqnuHNuo1vhfDFQCW)\n", + " Call ID: toolu_01ABUqneqnuHNuo1vhfDFQCW\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 requesting expert guidance for building an AI agent. Could you please provide some expert advice or resources on this topic?\n", "=================================\u001b[1m Tool Message \u001b[0m=================================\n", "Name: human_assistance\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", "==================================\u001b[1m Ai Message \u001b[0m==================================\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 your request for guidance on building an AI agent. Here's what the experts have suggested:\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 that you look into LangGraph for building your AI agent. They mention that LangGraph is a more reliable and extensible option compared to simple autonomous agents.\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 likely a framework or library designed specifically for creating AI agents with advanced capabilities. Here are a few points to consider based on this recommendation:\n", "\n", - "To follow up on this recommendation, you might want to:\n", + "1. Reliability: The experts emphasize that LangGraph is more reliable than simpler autonomous agent approaches. This could mean it has better stability, error handling, or consistent performance.\n", "\n", - "1. Research LangGraph: Look for its official documentation, tutorials, and any community resources.\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", + "2. Extensibility: LangGraph is described as more extensible, which suggests that it probably offers a flexible architecture that allows you to easily add new features or modify existing ones as your agent's requirements evolve.\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: Given that it's recommended over \"simple autonomous agents,\" LangGraph likely provides more sophisticated tools and techniques for building complex AI agents.\n", + "\n", + "To get started with LangGraph, you might want to:\n", + "\n", + "1. Search for the official LangGraph documentation or website to learn more about its features and how to use it.\n", + "2. Look for tutorials or guides specifically focused on building AI agents with LangGraph.\n", + "3. Check if there are any community forums or discussion groups where you can ask questions and get support from other developers using LangGraph.\n", + "\n", + "If you'd like more specific information about LangGraph or have any questions about this recommendation, please feel free to ask, and I can request further assistance from the experts.\n" ] } ], @@ -1652,7 +1662,9 @@ "\n", "\n", "def chatbot(state: State):\n", - " return {\"messages\": [llm_with_tools.invoke(state[\"messages\"])]}\n", + " message = llm_with_tools.invoke(state[\"messages\"])\n", + " assert(len(message.tool_calls) <= 1)\n", + " return {\"messages\": [message]}\n", "\n", "\n", "graph_builder = StateGraph(State)\n", @@ -1695,10 +1707,10 @@ "Can you look up when LangGraph was released? When you have the answer, use the human_assistance tool for review.\n", "==================================\u001b[1m Ai Message \u001b[0m==================================\n", "\n", - "[{'text': \"Certainly! I'll start by searching for information about LangGraph's release date using the Tavily search engine. Then, I'll use the human_assistance tool for review. Let's begin with the search.\", 'type': 'text'}, {'id': 'toolu_01APsgm3wwYXyZQcZJNb3rGJ', 'input': {'query': 'LangGraph release date'}, 'name': 'tavily_search_results_json', 'type': 'tool_use'}]\n", + "[{'text': \"Certainly! I'll start by searching for information about LangGraph's release date using the Tavily search function. Then, I'll use the human_assistance tool for review.\", 'type': 'text'}, {'id': 'toolu_01JoXQPgTVJXiuma8xMVwqAi', 'input': {'query': 'LangGraph release date'}, 'name': 'tavily_search_results_json', 'type': 'tool_use'}]\n", "Tool Calls:\n", - " tavily_search_results_json (toolu_01APsgm3wwYXyZQcZJNb3rGJ)\n", - " Call ID: toolu_01APsgm3wwYXyZQcZJNb3rGJ\n", + " tavily_search_results_json (toolu_01JoXQPgTVJXiuma8xMVwqAi)\n", + " Call ID: toolu_01JoXQPgTVJXiuma8xMVwqAi\n", " Args:\n", " query: LangGraph release date\n", "=================================\u001b[1m Tool Message \u001b[0m=================================\n", @@ -1707,10 +1719,10 @@ "[{\"url\": \"https://blog.langchain.dev/langgraph-cloud/\", \"content\": \"We also have a new stable release of LangGraph. By LangChain 6 min read Jun 27, 2024 (Oct '24) Edit: Since the launch of LangGraph Cloud, we now have multiple deployment options alongside LangGraph Studio - which now fall under LangGraph Platform. LangGraph Cloud is synonymous with our Cloud SaaS deployment option.\"}, {\"url\": \"https://changelog.langchain.com/announcements/langgraph-cloud-deploy-at-scale-monitor-carefully-iterate-boldly\", \"content\": \"LangChain - Changelog | ☁ 🚀 LangGraph Cloud: Deploy at scale, monitor LangChain LangSmith LangGraph LangChain LangSmith LangGraph LangChain LangSmith LangGraph LangChain Changelog Sign up for our newsletter to stay up to date DATE: The LangChain Team LangGraph LangGraph Cloud ☁ 🚀 LangGraph Cloud: Deploy at scale, monitor carefully, iterate boldly DATE: June 27, 2024 AUTHOR: The LangChain Team LangGraph Cloud is now in closed beta, offering scalable, fault-tolerant deployment for LangGraph agents. LangGraph Cloud also includes a new playground-like studio for debugging agent failure modes and quick iteration: Join the waitlist today for LangGraph Cloud. And to learn more, read our blog post announcement or check out our docs. Subscribe By clicking subscribe, you accept our privacy policy and terms and conditions.\"}]\n", "==================================\u001b[1m Ai Message \u001b[0m==================================\n", "\n", - "[{'text': 'Based on the search results, it appears that LangGraph was released before June 27, 2024. The search results mention a \"new stable release of LangGraph\" and \"LangGraph Cloud\" being announced on that date. However, the exact initial release date of LangGraph is not clearly stated in these results.\\n\\nGiven this information, I\\'ll use the human_assistance tool to review and possibly get more precise information about LangGraph\\'s initial release date.', 'type': 'text'}, {'id': 'toolu_01JtZJvDho75gcLbqcHHp4if', 'input': {'name': 'Assistant', 'birthday': '2023-01-01'}, 'name': 'human_assistance', 'type': 'tool_use'}]\n", + "[{'text': \"Based on the search results, it appears that LangGraph was already in existence before June 27, 2024, when LangGraph Cloud was announced. However, the search results don't provide a specific release date for the original LangGraph. \\n\\nGiven this information, I'll use the human_assistance tool to review and potentially provide more accurate information about LangGraph's initial release date.\", 'type': 'text'}, {'id': 'toolu_01JDQAV7nPqMkHHhNs3j3XoN', 'input': {'name': 'Assistant', 'birthday': '2023-01-01'}, 'name': 'human_assistance', 'type': 'tool_use'}]\n", "Tool Calls:\n", - " human_assistance (toolu_01JtZJvDho75gcLbqcHHp4if)\n", - " Call ID: toolu_01JtZJvDho75gcLbqcHHp4if\n", + " human_assistance (toolu_01JDQAV7nPqMkHHhNs3j3XoN)\n", + " Call ID: toolu_01JDQAV7nPqMkHHhNs3j3XoN\n", " Args:\n", " name: Assistant\n", " birthday: 2023-01-01\n" @@ -1752,10 +1764,10 @@ "text": [ "==================================\u001b[1m Ai Message \u001b[0m==================================\n", "\n", - "[{'text': 'Based on the search results, it appears that LangGraph was released before June 27, 2024. The search results mention a \"new stable release of LangGraph\" and \"LangGraph Cloud\" being announced on that date. However, the exact initial release date of LangGraph is not clearly stated in these results.\\n\\nGiven this information, I\\'ll use the human_assistance tool to review and possibly get more precise information about LangGraph\\'s initial release date.', 'type': 'text'}, {'id': 'toolu_01JtZJvDho75gcLbqcHHp4if', 'input': {'name': 'Assistant', 'birthday': '2023-01-01'}, 'name': 'human_assistance', 'type': 'tool_use'}]\n", + "[{'text': \"Based on the search results, it appears that LangGraph was already in existence before June 27, 2024, when LangGraph Cloud was announced. However, the search results don't provide a specific release date for the original LangGraph. \\n\\nGiven this information, I'll use the human_assistance tool to review and potentially provide more accurate information about LangGraph's initial release date.\", 'type': 'text'}, {'id': 'toolu_01JDQAV7nPqMkHHhNs3j3XoN', 'input': {'name': 'Assistant', 'birthday': '2023-01-01'}, 'name': 'human_assistance', 'type': 'tool_use'}]\n", "Tool Calls:\n", - " human_assistance (toolu_01JtZJvDho75gcLbqcHHp4if)\n", - " Call ID: toolu_01JtZJvDho75gcLbqcHHp4if\n", + " human_assistance (toolu_01JDQAV7nPqMkHHhNs3j3XoN)\n", + " Call ID: toolu_01JDQAV7nPqMkHHhNs3j3XoN\n", " Args:\n", " name: Assistant\n", " birthday: 2023-01-01\n", @@ -1767,13 +1779,13 @@ "\n", "Thank you for the human assistance. I can now provide you with the correct information about LangGraph's release date.\n", "\n", - "LangGraph was initially released on January 17, 2024. This information comes directly from the human assistance, which provided a correction to my earlier uncertainty.\n", + "LangGraph was initially released on January 17, 2024. This information comes from the human assistance correction, which is more accurate than the search results I initially found.\n", "\n", "To summarize:\n", - "- Initial search results were not clear about the exact release date of LangGraph.\n", - "- Human assistance provided the precise release date: January 17, 2024.\n", + "1. LangGraph's original release date: January 17, 2024\n", + "2. LangGraph Cloud announcement: June 27, 2024\n", "\n", - "This demonstrates the importance of verifying information, especially for newer technologies or products where online search results might not always provide the most up-to-date or accurate information.\n" + "It's worth noting that LangGraph had been in development and use for some time before the LangGraph Cloud announcement, but the official initial release of LangGraph itself was on January 17, 2024.\n" ] } ], @@ -1851,7 +1863,7 @@ "text/plain": [ "{'configurable': {'thread_id': '1',\n", " 'checkpoint_ns': '',\n", - " 'checkpoint_id': '1efd4395-61ae-6f14-8006-fb093210b222'}}" + " 'checkpoint_id': '1efd4ec5-cf69-6352-8006-9278f1730162'}}" ] }, "execution_count": 8,