From 1ffdd7b93dee42afbce34d319d67736c894c12b8 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Mon, 15 Jan 2024 15:34:17 -0800 Subject: [PATCH] cr --- README.md | 8 ++++---- .../high-level.ipynb | 4 ++-- .../respond-in-format.ipynb | 16 ++++------------ langgraph/prebuilt/__init__.py | 4 ++-- .../{chat_executor.py => chat_agent_executor.py} | 0 5 files changed, 12 insertions(+), 20 deletions(-) rename langgraph/prebuilt/{chat_executor.py => chat_agent_executor.py} (100%) diff --git a/README.md b/README.md index 21fe41dfa..823ffb483 100644 --- a/README.md +++ b/README.md @@ -618,10 +618,10 @@ tool_executor = ToolExecutor(tools) It then exposes a [runnable interface](https://python.langchain.com/docs/expression_language/interface). It can be used to call tools: you can pass in an [AgentAction](https://python.langchain.com/docs/modules/agents/concepts#agentaction) and it will look up the relevant tool and call it with the appropriate input. -### chat_executor.create_function_calling_executor +### chat_agent_executor.create_function_calling_executor ```python -from langgraph.prebuilt import chat_executor +from langgraph.prebuilt import chat_agent_executor ``` This is a helper function for creating a graph that works with a chat model that utilizes function calling. @@ -631,13 +631,13 @@ The model must be one that supports OpenAI function calling. ```python from langchain_openai import ChatOpenAI from langchain_community.tools.tavily_search import TavilySearchResults -from langgraph.prebuilt import chat_executor +from langgraph.prebuilt import chat_agent_executor from langchain_core.messages import HumanMessage tools = [TavilySearchResults(max_results=1)] model = ChatOpenAI() -app = chat_executor.create_function_calling_executor(model, tools) +app = chat_agent_executor.create_function_calling_executor(model, tools) inputs = {"messages": [HumanMessage(content="what is the weather in sf")]} for s in app.stream(inputs): diff --git a/examples/chat_executor_with_function_calling/high-level.ipynb b/examples/chat_executor_with_function_calling/high-level.ipynb index 9eed3d07c..f4fc724fc 100644 --- a/examples/chat_executor_with_function_calling/high-level.ipynb +++ b/examples/chat_executor_with_function_calling/high-level.ipynb @@ -32,7 +32,7 @@ "source": [ "from langchain_openai import ChatOpenAI\n", "from langchain_community.tools.tavily_search import TavilySearchResults\n", - "from langgraph.prebuilt import chat_executor\n", + "from langgraph.prebuilt import chat_agent_executor\n", "from langchain_core.messages import HumanMessage" ] }, @@ -64,7 +64,7 @@ "metadata": {}, "outputs": [], "source": [ - "app = chat_executor.create_function_calling_executor(model, tools)" + "app = chat_agent_executor.create_function_calling_executor(model, tools)" ] }, { diff --git a/examples/chat_executor_with_function_calling/respond-in-format.ipynb b/examples/chat_executor_with_function_calling/respond-in-format.ipynb index 8ca16498b..08e3a3ced 100644 --- a/examples/chat_executor_with_function_calling/respond-in-format.ipynb +++ b/examples/chat_executor_with_function_calling/respond-in-format.ipynb @@ -26,7 +26,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "af4ce0ba-7596-4e5f-8bf8-0b0bd6e62833", "metadata": {}, "outputs": [], @@ -393,19 +393,19 @@ "\n", "Output from node 'action':\n", "---\n", - "{'messages': [FunctionMessage(content=\"[{'url': 'https://www.whereandwhen.net/when/north-america/california/san-francisco-ca/january/', 'content': 'Best time to go to San Francisco? Weather in San Francisco in january 2024 How was the weather last january? Here is the day by day recorded weather in San Francisco in january 2023: Seasonal average climate and temperature of San Francisco in january The climate of San Francisco in january is tolerableWeather in San Francisco in january 2024. The weather in San Francisco in january comes from statistical datas on the past years. You can view the weather statistics the entire month, but also by using the tabs for the beginning, the middle and the end of the month. ... 15-01-2023 50°F to 52°F. 16-01-2023 45°F to 52°F. 17-01-2023 45°F to ...'}]\", name='tavily_search_results_json')]}\n", + "{'messages': [FunctionMessage(content=\"[{'url': 'https://weatherspark.com/h/m/557/2024/1/Historical-Weather-in-January-2024-in-San-Francisco-California-United-States', 'content': 'January 2024 Weather History in San Francisco California, United States Daily Precipitation in January 2024 in San Francisco Observed Weather in January 2024 in San Francisco San Francisco Temperature History January 2024 Hourly Temperature in January 2024 in San Francisco Hours of Daylight and Twilight in January 2024 in San FranciscoThis report shows the past weather for San Francisco, providing a weather history for January 2024. It features all historical weather data series we have available, including the San Francisco temperature history for January 2024. You can drill down from year to month and even day level reports by clicking on the graphs.'}]\", name='tavily_search_results_json')]}\n", "\n", "---\n", "\n", "Output from node 'agent':\n", "---\n", - "{'messages': [AIMessage(content='', additional_kwargs={'function_call': {'arguments': '{\\n \"temperature\": 50,\\n \"other_notes\": \"Tolerable weather\"\\n}', 'name': 'Response'}})]}\n", + "{'messages': [AIMessage(content='', additional_kwargs={'function_call': {'arguments': '{\\n \"temperature\": 60,\\n \"other_notes\": \"Partly cloudy\"\\n}', 'name': 'Response'}})]}\n", "\n", "---\n", "\n", "Output from node '__end__':\n", "---\n", - "{'messages': [HumanMessage(content='what is the weather in sf'), AIMessage(content='', additional_kwargs={'function_call': {'arguments': '{\\n \"query\": \"weather in San Francisco\"\\n}', 'name': 'tavily_search_results_json'}}), FunctionMessage(content=\"[{'url': 'https://www.whereandwhen.net/when/north-america/california/san-francisco-ca/january/', 'content': 'Best time to go to San Francisco? Weather in San Francisco in january 2024 How was the weather last january? Here is the day by day recorded weather in San Francisco in january 2023: Seasonal average climate and temperature of San Francisco in january The climate of San Francisco in january is tolerableWeather in San Francisco in january 2024. The weather in San Francisco in january comes from statistical datas on the past years. You can view the weather statistics the entire month, but also by using the tabs for the beginning, the middle and the end of the month. ... 15-01-2023 50°F to 52°F. 16-01-2023 45°F to 52°F. 17-01-2023 45°F to ...'}]\", name='tavily_search_results_json'), AIMessage(content='', additional_kwargs={'function_call': {'arguments': '{\\n \"temperature\": 50,\\n \"other_notes\": \"Tolerable weather\"\\n}', 'name': 'Response'}})]}\n", + "{'messages': [HumanMessage(content='what is the weather in sf'), AIMessage(content='', additional_kwargs={'function_call': {'arguments': '{\\n \"query\": \"weather in San Francisco\"\\n}', 'name': 'tavily_search_results_json'}}), FunctionMessage(content=\"[{'url': 'https://weatherspark.com/h/m/557/2024/1/Historical-Weather-in-January-2024-in-San-Francisco-California-United-States', 'content': 'January 2024 Weather History in San Francisco California, United States Daily Precipitation in January 2024 in San Francisco Observed Weather in January 2024 in San Francisco San Francisco Temperature History January 2024 Hourly Temperature in January 2024 in San Francisco Hours of Daylight and Twilight in January 2024 in San FranciscoThis report shows the past weather for San Francisco, providing a weather history for January 2024. It features all historical weather data series we have available, including the San Francisco temperature history for January 2024. You can drill down from year to month and even day level reports by clicking on the graphs.'}]\", name='tavily_search_results_json'), AIMessage(content='', additional_kwargs={'function_call': {'arguments': '{\\n \"temperature\": 60,\\n \"other_notes\": \"Partly cloudy\"\\n}', 'name': 'Response'}})]}\n", "\n", "---\n", "\n" @@ -424,14 +424,6 @@ " print(value)\n", " print(\"\\n---\\n\")" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "08ae8246-11d5-40e1-8567-361e5bef8917", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/langgraph/prebuilt/__init__.py b/langgraph/prebuilt/__init__.py index e85922374..fb2340d42 100644 --- a/langgraph/prebuilt/__init__.py +++ b/langgraph/prebuilt/__init__.py @@ -1,5 +1,5 @@ from langgraph.prebuilt.agent_executor import create_agent_executor -from langgraph.prebuilt import chat_executor +from langgraph.prebuilt import chat_agent_executor from langgraph.prebuilt.tool_executor import ToolExecutor, ToolInvocation -__all__ = ["create_agent_executor", "chat_executor", "ToolExecutor", ToolInvocation] +__all__ = ["create_agent_executor", "chat_agent_executor", "ToolExecutor", ToolInvocation] diff --git a/langgraph/prebuilt/chat_executor.py b/langgraph/prebuilt/chat_agent_executor.py similarity index 100% rename from langgraph/prebuilt/chat_executor.py rename to langgraph/prebuilt/chat_agent_executor.py