diff --git a/.github/workflows/link_check.yml b/.github/workflows/link_check.yml index 75d359002..c560293a0 100644 --- a/.github/workflows/link_check.yml +++ b/.github/workflows/link_check.yml @@ -49,5 +49,11 @@ jobs: - name: Check links in notebooks env: LANGCHAIN_API_KEY: test - shell: bash - run: poetry run pytest -o python_files=non_python_only --check-links --ignore="*.py" -k .ipynb --check-links-ignore "https://(api|web)\.smith\.langchain\.com/.*" --check-links-ignore "https://x.com/.*" --check-links-ignore "*.dcbadge.vercel.app*"./examples + shell: bash + run: | + if [ "${{ github.event_name }}" != "schedule" ]; then + CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep '\.ipynb$') + poetry run pytest -o python_files=non_python_only --check-links $CHANGED_FILES --check-links-ignore "https://(api|web)\.smith\.langchain\.com/.*" --check-links-ignore "https://x.com/.*" + else + poetry run pytest -o python_files=non_python_only --check-links --ignore="*.py" -k .ipynb --check-links-ignore "https://(api|web)\.smith\.langchain\.com/.*" --check-links-ignore "https://x.com/.*" ./examples + diff --git a/.markdown-link-check.config.json b/.markdown-link-check.config.json index ea411bc52..030951e49 100644 --- a/.markdown-link-check.config.json +++ b/.markdown-link-check.config.json @@ -1,3 +1,4 @@ { - "aliveStatusCodes": [200, 206, 402] + "aliveStatusCodes": [200, 206, 402], + "ignorePatterns": ["*dcbadge.vercel.app*"] } diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 10880c55d..d56e6f53d 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -51,7 +51,6 @@ plugins: - search: separator: '[\s\u200b\-_,:!=\[\]()"`/]+|\.(?!\d)|&[lg]t;|(?!\b)(?=[A-Z][a-z])' - autorefs - - meta - mkdocstrings: handlers: python: diff --git a/examples/agent_executor/high-level.ipynb b/examples/agent_executor/high-level.ipynb index d8422acac..17b9207ca 100644 --- a/examples/agent_executor/high-level.ipynb +++ b/examples/agent_executor/high-level.ipynb @@ -7,9 +7,15 @@ "source": [ "# (Deprecated) Agent Executor\n", "\n", - "The `create_agent_executor` function is deprecated in favor of [create_tool_calling_executor](../chat_agent_executor_with_function_calling/high-level-tools.ipynb).\n", + "The `create_agent_executor` function is deprecated in favor of [create_react_agent](../chat_agent_executor_with_function_calling/high-level-tools.ipynb).\n", "This was done to better align with the underlying model providers' migration from \"function calling\" to \"tool calling\", which typically supports parallel tool usage." ] + }, + { + "cell_type": "markdown", + "id": "8aa31ac5", + "metadata": {}, + "source": [] } ], "metadata": { diff --git a/examples/chat_agent_executor_with_function_calling/high-level-tools.ipynb b/examples/chat_agent_executor_with_function_calling/high-level-tools.ipynb index 358ce2447..d97a49c4d 100644 --- a/examples/chat_agent_executor_with_function_calling/high-level-tools.ipynb +++ b/examples/chat_agent_executor_with_function_calling/high-level-tools.ipynb @@ -5,7 +5,7 @@ "id": "8bcd1a3d-7c50-4f58-be4e-1ed654aa33be", "metadata": {}, "source": [ - "# Chat Executor: with tool calling\n", + "# ReAct agent with tool calling\n", "\n", "This notebook walks through an example creating a ReAct Agent that uses tool calling.\n", "This is useful for getting started quickly.\n", @@ -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_agent_executor\n", + "from langgraph.prebuilt import create_react_agent\n", "from langchain_core.messages import HumanMessage" ] }, @@ -64,7 +64,7 @@ "metadata": {}, "outputs": [], "source": [ - "app = chat_agent_executor.create_tool_calling_executor(model, tools)" + "app = create_react_agent(model, tools=tools)" ] }, { diff --git a/examples/chat_agent_executor_with_function_calling/high-level.ipynb b/examples/chat_agent_executor_with_function_calling/high-level.ipynb index 55d985dda..7dc9c4ac2 100644 --- a/examples/chat_agent_executor_with_function_calling/high-level.ipynb +++ b/examples/chat_agent_executor_with_function_calling/high-level.ipynb @@ -7,9 +7,15 @@ "source": [ "# (Deprecated) Chat Executor: with function calling\n", "\n", - "The function calling executor is deprecated in favor of [create_tool_calling_executor](../chat_agent_executor_with_function_calling/high-level-tools.ipynb).\n", + "The function calling executor is deprecated in favor of [create_react_agent](../chat_agent_executor_with_function_calling/high-level-tools.ipynb).\n", "This was done to better align with the underlying model providers' migration from \"function calling\" to \"tool calling\", which typically supports parallel tool usage." ] + }, + { + "cell_type": "markdown", + "id": "0a96f735", + "metadata": {}, + "source": [] } ], "metadata": { diff --git a/examples/plan-and-execute/plan-and-execute.ipynb b/examples/plan-and-execute/plan-and-execute.ipynb index 89c2f188d..cbd691966 100644 --- a/examples/plan-and-execute/plan-and-execute.ipynb +++ b/examples/plan-and-execute/plan-and-execute.ipynb @@ -44,20 +44,10 @@ "execution_count": 1, "id": "b451b58a-89bd-424f-8c06-0d9fe325e01b", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3.11 -m pip install --upgrade pip\u001b[0m\n" - ] - } - ], + "outputs": [], "source": [ "%%capture --no-stderr\n", - "%pip install --quiet -U langchain langchain_openai tavily-python" + "%pip install --quiet -U langchain-community langchain-openai tavily-python" ] }, { @@ -70,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "id": "ce438281-08d5-4804-afe7-e4089f7b016b", "metadata": {}, "outputs": [], @@ -78,8 +68,14 @@ "import os\n", "import getpass\n", "\n", - "os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\"OpenAI API Key:\")\n", - "os.environ[\"TAVILY_API_KEY\"] = getpass.getpass(\"Tavily API Key:\")" + "\n", + "def _set_env(var: str):\n", + " if not os.environ.get(var):\n", + " os.environ[var] = getpass.getpass(f\"{var}: \")\n", + "\n", + "\n", + "_set_env(\"OPENAI_API_KEY\")\n", + "_set_env(\"TAVILY_API_KEY\")" ] }, { @@ -92,13 +88,13 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "id": "01f460d1-f26f-47d1-ae76-de74d5d851de", "metadata": {}, "outputs": [], "source": [ "os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n", - "os.environ[\"LANGCHAIN_API_KEY\"] = getpass.getpass(\"LangSmith API Key:\")\n", + "_set_env(\"LANGCHAIN_API_KEY\")\n", "os.environ[\"LANGCHAIN_PROJECT\"] = \"Plan-and-execute\"" ] }, @@ -114,7 +110,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 3, "id": "25b9ec62-0675-4715-811c-9b32c635b22f", "metadata": {}, "outputs": [], @@ -137,67 +133,61 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "72d233ca-1dbf-4b43-b680-b3bf39e3691f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "================================\u001b[1m System Message \u001b[0m================================\n", + "\n", + "You are a helpful assistant.\n", + "\n", + "=============================\u001b[1m Messages Placeholder \u001b[0m=============================\n", + "\n", + "\u001b[33;1m\u001b[1;3m{{messages}}\u001b[0m\n" + ] + } + ], "source": [ "from langchain import hub\n", - "from langchain.agents import create_openai_functions_agent\n", "from langchain_openai import ChatOpenAI\n", + "from langgraph.prebuilt import create_react_agent\n", "\n", "# Get the prompt to use - you can modify this!\n", - "prompt = hub.pull(\"hwchase17/openai-functions-agent\")\n", + "prompt = hub.pull(\"wfh/react-agent-executor\")\n", + "prompt.pretty_print()\n", + "\n", "# Choose the LLM that will drive the agent\n", "llm = ChatOpenAI(model=\"gpt-4-turbo-preview\")\n", - "# Construct the OpenAI Functions agent\n", - "agent_runnable = create_openai_functions_agent(llm, tools, prompt)" + "agent_executor = create_react_agent(llm, tools, messages_modifier=prompt)" ] }, { "cell_type": "code", "execution_count": 7, - "id": "a3ea9bd3-87d9-4a78-aec6-8ab4bf34479b", - "metadata": {}, - "outputs": [], - "source": [ - "from langgraph.prebuilt import create_agent_executor" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "998aebde-c204-494f-930c-14747ed34861", - "metadata": {}, - "outputs": [], - "source": [ - "agent_executor = create_agent_executor(agent_runnable, tools)" - ] - }, - { - "cell_type": "code", - "execution_count": 9, "id": "746e697a-dec4-4342-a814-9b3456828169", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'input': 'who is the winnner of the us open',\n", - " 'chat_history': [],\n", - " 'agent_outcome': AgentFinish(return_values={'output': 'The winners of the US Open in 2023 are as follows:\\n\\n- **Golf:** Wyndham Clark won the 2023 US Open in golf, holding his nerve against Rory McIlroy.\\n \\n- **Tennis:** The 2023 US Open tennis tournament details include information about the event and its prize money, but the winner has not been specified in the provided information. As of the last update, Carlos Alcaraz won the 2022 US Open tennis title.'}, log='The winners of the US Open in 2023 are as follows:\\n\\n- **Golf:** Wyndham Clark won the 2023 US Open in golf, holding his nerve against Rory McIlroy.\\n \\n- **Tennis:** The 2023 US Open tennis tournament details include information about the event and its prize money, but the winner has not been specified in the provided information. As of the last update, Carlos Alcaraz won the 2022 US Open tennis title.'),\n", - " 'intermediate_steps': [(AgentActionMessageLog(tool='tavily_search_results_json', tool_input={'query': 'US Open winner 2023'}, log=\"\\nInvoking: `tavily_search_results_json` with `{'query': 'US Open winner 2023'}`\\n\\n\\n\", message_log=[AIMessage(content='', additional_kwargs={'function_call': {'arguments': '{\"query\":\"US Open winner 2023\"}', 'name': 'tavily_search_results_json'}})]),\n", - " '[{\\'url\\': \\'https://en.wikipedia.org/wiki/2023_U.S._Open_(golf)\\', \\'content\\': \\'Contents 2023 U.S. Open (golf) was selected to host the 123rd U.S. Open in June 2023. The USGA had made overtures to the club for at least 26 years. Final round[edit] Sunday, June 18, 2023 Third round[edit] Saturday, June 17, 2023Rory McIlroy falls short as Wyndham Clark holds nerve to win 2023 US Open. The Guardian. Archived from the original on June 19, 2023. Retrieved June 20, 2023.\\'}, {\\'url\\': \\'https://en.wikipedia.org/wiki/2023_US_Open_(tennis)\\', \\'content\\': \"The 2023 US Open is the 143rd consecutive edition of the tournament and will take place at the USTA Billie Jean King The total overall prize money for the 2023 US Open totals $65 million, 8% more than the 2022 edition.[4] Contents 2023 US Open (tennis) Wheelchair boys\\' singles Dahnon Ward Wheelchair girls\\' singles Ksénia Chasteau contract with ESPN, in which the broadcaster holds exclusive rights to the entire tournament and the US Open Series.Carlos Alcaraz defeats Casper Ruud for 2022 US Open title, world No. 1 ranking. US Open. Archived from the original on September 12, 2022. Retrieved September\\\\xa0...\"}]')]}" + "{'messages': [HumanMessage(content='who is the winnner of the us open', id='7c491c9f-cdbe-4761-b93b-3e4eeb526c97'),\n", + " AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_MMmwmxwxRH2hrmMbuBeMGsXW', 'function': {'arguments': '{\"query\":\"US Open 2023 winner\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]}, response_metadata={'token_usage': {'completion_tokens': 23, 'prompt_tokens': 97, 'total_tokens': 120}, 'model_name': 'gpt-4-turbo-preview', 'system_fingerprint': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-855f7cff-62a2-4dd8-b71b-707b507b00a4-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'US Open 2023 winner'}, 'id': 'call_MMmwmxwxRH2hrmMbuBeMGsXW'}]),\n", + " ToolMessage(content='[{\"url\": \"https://www.bbc.com/sport/tennis/66766337\", \"content\": \": Stephen Nolan goes in to find out\\\\nRelated Topics\\\\nTop Stories\\\\nTen Hag on Rashford plus transfer news, WSL deadline day\\\\nSpinner Leach doubtful for second Test in India\\\\nMcIlroy \\'changes tune\\' on LIV players\\' punishment\\\\nElsewhere on the BBC\\\\nDiscover the tropical paradise of Thailand\\\\nFrom the secrets of the South to the mysterious North...\\\\n Djokovic offered to help up Medvedev when the Russian fell to the court in the third set\\\\nDjokovic\\'s relentless returning continued to draw mistakes out of Medvedev, who was serving poorly and making loose errors, at the start of the second set.\\\\n It was clear to see Medvedev had needed to level by taking that second set to stand any real chance of victory and the feeling of the inevitable was heightened by the Russian needing treatment on a shoulder injury before the third set.\\\\n Djokovic shows again why he can never be written off\\\\nWhen Djokovic lost to 20-year-old Carlos Alcaraz in the Wimbledon final it felt like a changing-of-the-guard moment in the men\\'s game.\\\\n The inside story of Putin\\\\u2019s invasion of Ukraine\\\\nTold by the Presidents and Prime Ministers tasked with making the critical decisions\\\\nSurvival of the wittiest!\\\\n\"}, {\"url\": \"https://www.usopen.org/en_US/news/articles/2023-09-10/novak_djokovic_wins_24th_grand_slam_singles_title_at_2023_us_open.html\", \"content\": \"WHAT HAPPENED: Novak Djokovic handled the weight of history to defeat Daniil Medvedev on Sunday in the 2023 US Open men\\'s singles final. With a 6-3, 7-6(5), 6-3 victory, the 36-year-old won his 24th Grand Slam singles title, tying Margaret Court\\'s record and bolstering his case to be considered the greatest tennis player of all time.\"}, {\"url\": \"https://apnews.com/article/us-open-final-live-updates-djokovic-medvedev-8a4a26f8d77ef9ab2fb3efe1096dce7e\", \"content\": \"Novak Djokovic wins the US Open for his 24th Grand Slam title by beating Daniil Medvedev\\\\nNovak Djokovic, of Serbia, holds up the championship trophy after defeating Daniil Medvedev, of Russia, in the men\\\\u2019s singles final of the U.S. Open tennis championships, Sunday, Sept. 10, 2023, in New York. (AP Photo/Manu Fernandez)\\\\nDaniil Medvedev, of Russia, sits on the court after a rally against Novak Djokovic, of Serbia, during the men\\\\u2019s singles final of the U.S. Open tennis championships, Sunday, Sept. 10, 2023, in New York. (AP Photo/Manu Fernandez)\\\\nDaniil Medvedev, of Russia, sits on the court after a rally against Novak Djokovic, of Serbia, during the men\\\\u2019s singles final of the U.S. Open tennis championships, Sunday, Sept. 10, 2023, in New York. (AP Photo/Manu Fernandez)\\\\nDaniil Medvedev, of Russia, sits on the court after a rally against Novak Djokovic, of Serbia, during the men\\\\u2019s singles final of the U.S. Open tennis championships, Sunday, Sept. 10, 2023, in New York. Novak Djokovic, of Serbia, reveals a t-shirt honoring the number 24 and Kobe Bryant after defeating Daniil Medvedev, of Russia, in the men\\\\u2019s singles final of the U.S. Open tennis championships, Sunday, Sept. 10, 2023, in New York.\"}]', name='tavily_search_results_json', id='ca0ff812-6c7f-43c1-9d0e-427cfe8da332', tool_call_id='call_MMmwmxwxRH2hrmMbuBeMGsXW'),\n", + " AIMessage(content=\"The winner of the 2023 US Open men's singles was Novak Djokovic. He defeated Daniil Medvedev with a score of 6-3, 7-6(5), 6-3 in the final, winning his 24th Grand Slam singles title. This victory tied Margaret Court's record and bolstered Djokovic's claim to be considered one of the greatest tennis players of all time.\", response_metadata={'token_usage': {'completion_tokens': 89, 'prompt_tokens': 972, 'total_tokens': 1061}, 'model_name': 'gpt-4-turbo-preview', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-ef37a655-1ea6-470e-a310-8f125ca48015-0')]}" ] }, - "execution_count": 9, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "agent_executor.invoke(\n", - " {\"input\": \"who is the winnner of the us open\", \"chat_history\": []}\n", + " {\"messages\": [(\"user\", \"who is the winnner of the us open\")]}\n", ")" ] }, @@ -219,12 +209,11 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 8, "id": "8eeeaeea-8f10-4fbe-8e24-4e1a2381a009", "metadata": {}, "outputs": [], "source": [ - "from langchain_core.pydantic_v1 import BaseModel, Field\n", "from typing import List, Tuple, Annotated, TypedDict\n", "import operator\n", "\n", @@ -248,12 +237,12 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "id": "4a88626d-6dfd-4488-87f0-a9a0dd6da44c", "metadata": {}, "outputs": [], "source": [ - "from langchain_core.pydantic_v1 import BaseModel\n", + "from langchain_core.pydantic_v1 import BaseModel, Field\n", "\n", "\n", "class Plan(BaseModel):\n", @@ -266,46 +255,49 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 36, "id": "ec7b1867-1ea3-4df3-9a98-992a1c32ec49", "metadata": {}, "outputs": [], "source": [ - "from langchain.chains.openai_functions import create_structured_output_runnable\n", "from langchain_core.prompts import ChatPromptTemplate\n", "\n", - "planner_prompt = ChatPromptTemplate.from_template(\n", - " \"\"\"For the given objective, come up with a simple step by step plan. \\\n", + "planner_prompt = ChatPromptTemplate.from_messages(\n", + " [\n", + " (\n", + " \"system\",\n", + " \"\"\"For the given objective, come up with a simple step by step plan. \\\n", "This plan should involve individual tasks, that if executed correctly will yield the correct answer. Do not add any superfluous steps. \\\n", - "The result of the final step should be the final answer. Make sure that each step has all the information needed - do not skip steps.\n", - "\n", - "{objective}\"\"\"\n", + "The result of the final step should be the final answer. Make sure that each step has all the information needed - do not skip steps.\"\"\",\n", + " ),\n", + " (\"placeholder\", \"{messages}\"),\n", + " ]\n", ")\n", - "planner = create_structured_output_runnable(\n", - " Plan, ChatOpenAI(model=\"gpt-4-turbo-preview\", temperature=0), planner_prompt\n", - ")" + "planner = planner_prompt | ChatOpenAI(\n", + " model=\"gpt-4o\", temperature=0\n", + ").with_structured_output(Plan)" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 37, "id": "67ce37b7-e089-479b-bcb8-c3f5d9874613", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Plan(steps=['Identify the current year.', 'Search for the Australia Open winner of the current year.', 'Find the hometown of the identified winner.'])" + "Plan(steps=['Identify the current winner of the Australian Open.', 'Determine the hometown of the identified winner.'])" ] }, - "execution_count": 13, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "planner.invoke(\n", - " {\"objective\": \"what is the hometown of the current Australia open winner?\"}\n", + " {\"messages\": [(\"user\", \"what is the hometown of the current Australia open winner?\")]}\n", ")" ] }, @@ -321,12 +313,12 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 19, "id": "ec2d12cc-016a-44d1-aa08-4c5ce1e8fe2a", "metadata": {}, "outputs": [], "source": [ - "from langchain.chains.openai_functions import create_openai_fn_runnable\n", + "from typing import Union\n", "\n", "\n", "class Response(BaseModel):\n", @@ -335,6 +327,15 @@ " response: str\n", "\n", "\n", + "class Act(BaseModel):\n", + " \"\"\"Action to perform.\"\"\"\n", + "\n", + " action: Union[Response, Plan] = Field(\n", + " description=\"Action to perform. If you want to respond to user, use Response. \"\n", + " \"If you need to further use tools to get the answer, use Plan.\"\n", + " )\n", + "\n", + "\n", "replanner_prompt = ChatPromptTemplate.from_template(\n", " \"\"\"For the given objective, come up with a simple step by step plan. \\\n", "This plan should involve individual tasks, that if executed correctly will yield the correct answer. Do not add any superfluous steps. \\\n", @@ -353,11 +354,7 @@ ")\n", "\n", "\n", - "replanner = create_openai_fn_runnable(\n", - " [Plan, Response],\n", - " ChatOpenAI(model=\"gpt-4-turbo-preview\", temperature=0),\n", - " replanner_prompt,\n", - ")" + "replanner = replanner_prompt | ChatOpenAI(model=\"gpt-4o\", temperature=0).with_structured_output(Act)" ] }, { @@ -372,47 +369,54 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 54, "id": "6c8e0dad-bcea-4c9a-8922-0d820892e2d0", "metadata": {}, "outputs": [], "source": [ + "from typing import Literal\n", + "\n", + "\n", "async def execute_step(state: PlanExecute):\n", - " task = state[\"plan\"][0]\n", - " agent_response = await agent_executor.ainvoke({\"input\": task, \"chat_history\": []})\n", + " plan = state[\"plan\"]\n", + " plan_str = \"\\n\".join(f\"{i+1}. {step}\" for i, step in enumerate(plan))\n", + " task = plan[0]\n", + " task_formatted = f\"\"\"For the following plan:\n", + "{plan_str}\\n\\nYou are tasked with executing step {1}, {task}.\"\"\"\n", + " agent_response = await agent_executor.ainvoke({\"messages\": [(\"user\", task_formatted)]})\n", " return {\n", - " \"past_steps\": (task, agent_response[\"agent_outcome\"].return_values[\"output\"])\n", + " \"past_steps\": (task, agent_response[\"messages\"][-1].content),\n", " }\n", "\n", "\n", "async def plan_step(state: PlanExecute):\n", - " plan = await planner.ainvoke({\"objective\": state[\"input\"]})\n", + " plan = await planner.ainvoke({\"messages\": [(\"user\", state[\"input\"])]})\n", " return {\"plan\": plan.steps}\n", "\n", "\n", "async def replan_step(state: PlanExecute):\n", " output = await replanner.ainvoke(state)\n", - " if isinstance(output, Response):\n", - " return {\"response\": output.response}\n", + " if isinstance(output.action, Response):\n", + " return {\"response\": output.action.response}\n", " else:\n", - " return {\"plan\": output.steps}\n", + " return {\"plan\": output.action.steps}\n", "\n", "\n", - "def should_end(state: PlanExecute):\n", + "def should_end(state: PlanExecute) -> Literal[\"agent\", \"__end__\"]:\n", " if \"response\" in state and state[\"response\"]:\n", - " return \"True\"\n", + " return \"__end__\"\n", " else:\n", - " return \"False\"" + " return \"agent\"" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 55, "id": "e954cea0-5ccc-46c2-a27b-f5b7185b597d", "metadata": {}, "outputs": [], "source": [ - "from langgraph.graph import StateGraph, END\n", + "from langgraph.graph import StateGraph\n", "\n", "workflow = StateGraph(PlanExecute)\n", "\n", @@ -437,11 +441,6 @@ " \"replan\",\n", " # Next, we pass in the function that will determine which node is called next.\n", " should_end,\n", - " {\n", - " # If `tools`, then we call the tool node.\n", - " \"True\": END,\n", - " \"False\": \"agent\",\n", - " },\n", ")\n", "\n", "# Finally, we compile it!\n", @@ -452,7 +451,30 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 56, + "id": "7363e528", + "metadata": {}, + "outputs": [ + { + "data": { + "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFla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fqp8lUH1xe/bfqrDwCe2pyZo/Y1aTu5rma2sC+WK3ZNapFsu0GPc7dIAD0WW0HG3ACCOZJ6HqAf2VIfkqg+uL37b9VPkqg+uL37b9VY0eviLuYXsWstamuZV6OAPDRs7TgOOJOiNi2MjoRoj7n0V7W/gbw7tM+NOhYPj8SZGdS8w+zbmkrbWkgpUkhOwQQCCPRVlfJVB9cXv236qfJVB9cXv236q26D+7yZJorE/F8SLZR/J8X9Ywf4tqrfqEjhPbC6wt243aQll5t8NvS9oKkLC07Guo2kVNqu06ao0VSTvrb70vI7OBw0sJSdOTvrvyXkKUpWToClKUApSlAKUpQClKUApSlAKUpQClKUB//9k=", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from IPython.display import Image, display\n", + "\n", + "display(Image(app.get_graph(xray=True).draw_mermaid_png()))" + ] + }, + { + "cell_type": "code", + "execution_count": 57, "id": "b8ac1f67-e87a-427c-b4f7-44351295b788", "metadata": {}, "outputs": [ @@ -460,21 +482,23 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'plan': ['Wait until the 2024 Australian Open concludes.', 'Identify the winner of the 2024 Australian Open.', \"Research the winner's biography to find their hometown.\", 'The hometown of the 2024 Australian Open winner is the result found in the previous step.']}\n", - "{'past_steps': ('Wait until the 2024 Australian Open concludes.', \"I can't wait for real-time events. However, I can help you find out the schedule, expected dates, or any other information regarding the 2024 Australian Open. How can I assist you further?\")}\n", - "{'plan': ['Identify the winner of the 2024 Australian Open.', \"Research the winner's biography to find their hometown.\", 'The hometown of the 2024 Australian Open winner is the result found in the previous step.']}\n", - "{'past_steps': ('Identify the winner of the 2024 Australian Open.', \"The winners of the 2024 Australian Open were Jannik Sinner in the men's singles and Aryna Sabalenka in the women's singles. Jannik Sinner defeated Daniil Medvedev in the final, while specific details about Aryna Sabalenka's match are not provided in the information retrieved.\")}\n", - "{'plan': [\"Research Jannik Sinner's biography to find his hometown.\", \"Research Aryna Sabalenka's biography to find her hometown.\", 'The hometowns of the 2024 Australian Open winners are the results found in the previous steps.']}\n", - "{'past_steps': (\"Research Jannik Sinner's biography to find his hometown.\", 'Jannik Sinner was born in San Candido (Innichen), Italy, on August 16, 2001. This is considered his hometown.')}\n", - "{'plan': [\"Research Aryna Sabalenka's biography to find her hometown.\", 'The hometowns of the 2024 Australian Open winners are the results found in the previous steps.']}\n", - "{'past_steps': (\"Research Aryna Sabalenka's biography to find her hometown.\", 'Aryna Sabalenka was born in Minsk, the capital of Belarus.')}\n", - "{'response': 'The hometowns of the 2024 Australian Open winners are San Candido (Innichen), Italy for Jannik Sinner, and Minsk, Belarus for Aryna Sabalenka. No further steps are needed as the final answer has been reached.'}\n" + "{'plan': ['Identify the winner of the 2024 Australian Open.', 'Determine the hometown of the identified winner.']}\n", + "{'past_steps': ('Identify the winner of the 2024 Australian Open.', 'The winner of the 2024 Australian Open is Jannik Sinner. He claimed his first Grand Slam title in an epic comeback win over Daniil Medvedev.')}\n", + "{'plan': ['Determine the hometown of Jannik Sinner.']}\n", + "{'past_steps': ('Determine the hometown of Jannik Sinner.', \"Jannik Sinner's hometown is not directly mentioned in the provided excerpts. To ensure accurate information, it's advisable to check a reliable source like his official ATP profile or a detailed biography which often includes personal background details such as hometown.\")}\n", + "{'plan': [\"Check Jannik Sinner's official ATP profile or a detailed biography to find his hometown.\", 'Return the hometown of Jannik Sinner.']}\n", + "{'past_steps': (\"Check Jannik Sinner's official ATP profile or a detailed biography to find his hometown.\", \"Jannik Sinner's official ATP profile can be found at this URL: [ATP Tour - Jannik Sinner](https://www.atptour.com/en/players/jannik-sinner/s0ag/overview). This profile will contain detailed information including his biography, rankings, playing activity, and potentially his hometown.\")}\n", + "{'plan': [\"Visit Jannik Sinner's official ATP profile or a detailed biography to find his hometown.\", 'Return the hometown of Jannik Sinner.']}\n", + "{'past_steps': (\"Visit Jannik Sinner's official ATP profile or a detailed biography to find his hometown.\", \"Jannik Sinner's official ATP profile and other reliable sources do not explicitly mention his hometown in the search results provided. For detailed information, visiting his ATP profile directly or consulting a comprehensive biography would be recommended to find this specific information.\")}\n", + "{'plan': [\"Visit Jannik Sinner's official ATP profile or a detailed biography to find his hometown.\", 'Return the hometown of Jannik Sinner.']}\n", + "{'past_steps': (\"Visit Jannik Sinner's official ATP profile or a detailed biography to find his hometown.\", \"Jannik Sinner's official ATP profile can be accessed [here](https://www.atptour.com/en/players/jannik-sinner/s0ag/overview), although it does not directly provide his hometown in the snippet. For detailed information, such as his hometown, it might be necessary to visit the profile directly or consult other detailed biographies like the one available on [Wikipedia](https://en.wikipedia.org/wiki/Jannik_Sinner), which often include personal details such as hometowns.\")}\n", + "{'plan': [\"Visit Jannik Sinner's official ATP profile or his Wikipedia page to find his hometown.\", 'Return the hometown of Jannik Sinner.']}\n", + "{'past_steps': (\"Visit Jannik Sinner's official ATP profile or his Wikipedia page to find his hometown.\", \"Jannik Sinner's official ATP profile and Wikipedia page did not directly mention his hometown in the provided excerpts. However, further information can typically be found by visiting the full pages directly through the provided links:\\n\\n- [Jannik Sinner's ATP Tour Profile](https://www.atptour.com/en/players/jannik-sinner/s0ag/overview)\\n- [Jannik Sinner's Wikipedia Page](https://en.wikipedia.org/wiki/Jannik_Sinner)\\n\\nFor detailed information, including his hometown, I recommend checking these sources.\")}\n", + "{'response': 'The necessary steps to find the hometown of the 2024 Australian Open winner, Jannik Sinner, have already been completed. His hometown is Innichen, Italy.'}\n" ] } ], "source": [ - "from langchain_core.messages import HumanMessage\n", - "\n", "config = {\"recursion_limit\": 50}\n", "inputs = {\"input\": \"what is the hometown of the 2024 Australia open winner?\"}\n", "async for event in app.astream(inputs, config=config):\n",