From 5235ad08ecb079313d28e45de3c165b027d365e6 Mon Sep 17 00:00:00 2001 From: Vadym Barda Date: Tue, 24 Sep 2024 10:51:22 -0400 Subject: [PATCH] docs: remove context channel (#1824) --- docs/docs/concepts/low_level.md | 4 - docs/docs/how-tos/index.md | 2 - docs/docs/how-tos/state-context-key.ipynb | 468 ---------------------- docs/mkdocs.yml | 1 - examples/state-context-key.ipynb | 33 -- 5 files changed, 508 deletions(-) delete mode 100644 docs/docs/how-tos/state-context-key.ipynb delete mode 100644 examples/state-context-key.ipynb diff --git a/docs/docs/concepts/low_level.md b/docs/docs/concepts/low_level.md index 47b70fc27..43f3093a7 100644 --- a/docs/docs/concepts/low_level.md +++ b/docs/docs/concepts/low_level.md @@ -140,10 +140,6 @@ class State(TypedDict): In this example, we've used the `Annotated` type to specify a reducer function (`operator.add`) for the second key (`bar`). Note that the first key remains unchanged. Let's assume the input to the graph is `{"foo": 1, "bar": ["hi"]}`. Let's then assume the first `Node` returns `{"foo": 2}`. This is treated as an update to the state. Notice that the `Node` does not need to return the whole `State` schema - just an update. After applying this update, the `State` would then be `{"foo": 2, "bar": ["hi"]}`. If the second node returns `{"bar": ["bye"]}` then the `State` would then be `{"foo": 2, "bar": ["hi", "bye"]}`. Notice here that the `bar` key is updated by adding the two lists together. -#### Context Reducer - -You can use `Context` channels to define shared resources (such as database connections) that are managed outside of your graph's nodes and excluded from checkpointing. The context manager provided to the Context channel is entered before the first step of the graph execution and exited after the last step, allowing you to set up and clean up resources for the duration of the graph invocation. Read this [how to](https://langchain-ai.github.io/langgraph/how-tos/state-context-key) to see an example of using the `Context` channel in your graph. - ### Working with Messages in Graph State #### Why use messages? diff --git a/docs/docs/how-tos/index.md b/docs/docs/how-tos/index.md index d73b8b4a3..518064348 100644 --- a/docs/docs/how-tos/index.md +++ b/docs/docs/how-tos/index.md @@ -75,7 +75,6 @@ These guides show how to use different streaming modes. ## State Management - [Use Pydantic model as state](state-model.ipynb) -- [Use a context object in state](state-context-key.ipynb) - [Have a separate input and output schema](input_output_schema.ipynb) - [Pass private state between nodes inside the graph](pass_private_state.ipynb) @@ -85,7 +84,6 @@ These guides show how to use different streaming modes. - [How to visualize your graph](visualization.ipynb) - [How to add runtime configuration to your graph](configuration.ipynb) - [How to use a Pydantic model as your state](state-model.ipynb) -- [How to use a context object in state](state-context-key.ipynb) - [How to add node retries](node-retries.ipynb) - [How to force function calling agent to structure output](react-agent-structured-output.ipynb) - [How to pass custom LangSmith run ID for graph runs](run-id-langsmith.ipynb) diff --git a/docs/docs/how-tos/state-context-key.ipynb b/docs/docs/how-tos/state-context-key.ipynb deleted file mode 100644 index a5262c1ca..000000000 --- a/docs/docs/how-tos/state-context-key.ipynb +++ /dev/null @@ -1,468 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "51466c8d-8ce4-4b3d-be4e-18fdbeda5f53", - "metadata": {}, - "source": [ - "# How to use a context object in state\n", - "\n", - "Sometimes you need some resources (like a database connection, a requests session, etc) to live for the duration of your graph execution, without being ever saved by the checkpointer.\n", - "\n", - "LangGraph supports decorating a state key with the Context channel, which will take care to \n", - "\n", - "- initialize the value before the graph starts executing, with access to the config passed in to invoke/stream\n", - "- run any cleanup code you need at the end of the graph execution, whether the graph succeeded or errored\n", - "\n", - "The argument to context channel should be either a ContextManager class or function." - ] - }, - { - "cell_type": "markdown", - "id": "7cbd446a-808f-4394-be92-d45ab818953c", - "metadata": {}, - "source": [ - "## Setup\n", - "\n", - "First we need to install the packages required" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "af4ce0ba-7596-4e5f-8bf8-0b0bd6e62833", - "metadata": {}, - "outputs": [], - "source": [ - "%%capture --no-stderr\n", - "%pip install --quiet -U langgraph langchain_openai" - ] - }, - { - "cell_type": "markdown", - "id": "0abe11f4-62ed-4dc4-8875-3db21e260d1d", - "metadata": {}, - "source": [ - "Next, we need to set API keys for OpenAI (the LLM we will use) and Tavily (the search tool we will use)" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "c903a1cf-2977-4e2d-ad7d-8b3946821d89", - "metadata": {}, - "outputs": [], - "source": [ - "import getpass\n", - "import os\n", - "\n", - "\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\")" - ] - }, - { - "cell_type": "markdown", - "id": "f0ed46a8-effe-4596-b0e1-a6a29ee16f5c", - "metadata": {}, - "source": [ - "
\n", - "

Set up LangSmith for LangGraph development

\n", - "

\n", - " Sign up for LangSmith to quickly spot issues and improve the performance of your LangGraph projects. LangSmith lets you use trace data to debug, test, and monitor your LLM apps built with LangGraph — read more about how to get started here. \n", - "

\n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "21ac643b-cb06-4724-a80c-2862ba4773f1", - "metadata": {}, - "source": [ - "## Set up the tools\n", - "\n", - "We will first define the tools we want to use.\n", - "For this simple example, we will use create a placeholder search engine.\n", - "However, it is really easy to create your own tools - see documentation [here](https://python.langchain.com/docs/how_to/custom_tools) on how to do that.\n" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "d7ef57dd-5d6e-4ad3-9377-a92201c1310e", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_core.tools import tool\n", - "\n", - "\n", - "@tool\n", - "def search(query: str):\n", - " \"\"\"Call to surf the web.\"\"\"\n", - " # This is a placeholder for the actual implementation\n", - " # Don't let the LLM know this though 😊\n", - " return \"The answer to your question lies within.\"\n", - "\n", - "\n", - "tools = [search]" - ] - }, - { - "cell_type": "markdown", - "id": "01885785-b71a-44d1-b1d6-7b5b14d53b58", - "metadata": {}, - "source": [ - "We can now wrap these tools in a simple [tool-calling node](https://langchain-ai.github.io/langgraph/reference/prebuilt/#toolnode)." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "5cf3331e-ccb3-41c8-aeb9-a840a94d41e7", - "metadata": {}, - "outputs": [], - "source": [ - "from langgraph.prebuilt import ToolNode\n", - "\n", - "tool_node = ToolNode(tools)" - ] - }, - { - "cell_type": "markdown", - "id": "5497ed70-fce3-47f1-9cad-46f912bad6a5", - "metadata": {}, - "source": [ - "## Set up the model\n", - "\n", - "Now we need to load the chat model we want to use.\n", - "Importantly, this should satisfy two criteria:\n", - "\n", - "1. It should work with messages. We will represent all agent state in the form of messages, so it needs to be able to work well with them.\n", - "2. It should work with OpenAI function calling. This means it should either be an OpenAI model or a model that exposes a similar interface.\n", - "\n", - "Note: these model requirements are not requirements for using LangGraph - they are just requirements for this one example.\n" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "892b54b9-75f0-4804-9ed0-88b5e5532989", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_openai import ChatOpenAI\n", - "\n", - "model = ChatOpenAI(temperature=0)" - ] - }, - { - "cell_type": "markdown", - "id": "a77995c0-bae2-4cee-a036-8688a90f05b9", - "metadata": {}, - "source": [ - "\n", - "After we've done this, we should make sure the model knows that it has these tools available to call.\n", - "We can do this by converting the LangChain tools into the format for OpenAI function calling, and then bind them to the model class.\n" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "cd3cbae5-d92c-4559-a4aa-44721b80d107", - "metadata": {}, - "outputs": [], - "source": [ - "model = model.bind_tools(tools)" - ] - }, - { - "cell_type": "markdown", - "id": "5e8a84b6-78ad-4f89-b64b-fb8c9e215a87", - "metadata": {}, - "source": [ - "## Define the context object\n", - "\n", - "Here we're defining the context object as a pydantic model, which is created by the factory function decorated with @contextmanager. @contextmanager ensures any cleanup code you need can be run at the end of the execution" - ] - }, - { - "cell_type": "markdown", - "id": "9e1428b9", - "metadata": {}, - "source": [ - "
\n", - "

Using Pydantic with LangChain

\n", - "

\n", - " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", - "

\n", - "
" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "dec610e7-728f-4a71-93e3-1c7d1a8d05bb", - "metadata": {}, - "outputs": [], - "source": [ - "import httpx\n", - "from contextlib import contextmanager\n", - "from langchain_core.runnables import RunnableConfig\n", - "\n", - "from pydantic import BaseModel\n", - "\n", - "\n", - "class AgentContext(BaseModel):\n", - " class Config:\n", - " arbitrary_types_allowed = True\n", - "\n", - " httpx_session: httpx.Client\n", - "\n", - "\n", - "@contextmanager\n", - "def make_agent_context(config: RunnableConfig):\n", - " # here you could read the config values passed invoke/stream to customize the context object\n", - "\n", - " # as an example, we create an httpx session, which could then be used in your graph's nodes\n", - " session = httpx.Client()\n", - " try:\n", - " yield AgentContext(httpx_session=session)\n", - " finally:\n", - " session.close()" - ] - }, - { - "cell_type": "markdown", - "id": "8e8b9211-93d0-4ad5-aa7a-9c09099c53ff", - "metadata": {}, - "source": [ - "## Define the agent state\n", - "\n", - "The main type of graph in `langgraph` is the [StateGraph](https://langchain-ai.github.io/langgraph/reference/graphs/#langgraph.graph.StateGraph).\n", - "This graph is parameterized by a state object that it passes around to each node.\n", - "Each node then returns operations to update that state.\n", - "These operations can either SET specific attributes on the state (e.g. overwrite the existing values) or ADD to the existing attribute.\n", - "Whether to set or add is denoted by annotating the state object you construct the graph with.\n", - "\n", - "For this example, the state we will track will just be a list of messages.\n", - "We want each node to just add messages to that list.\n", - "Therefore, we will use a `pydantic.BaseModel` with one key (`messages`) and annotate it so that the `messages` attribute is treated as \"append-only\".\n" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "ea793afa-2eab-4901-910d-6eed90cd6564", - "metadata": {}, - "outputs": [], - "source": [ - "import operator\n", - "from typing import Annotated, Sequence\n", - "\n", - "from langchain_core.messages import BaseMessage\n", - "from langgraph.channels.context import Context\n", - "\n", - "\n", - "class AgentState(BaseModel):\n", - " messages: Annotated[Sequence[BaseMessage], operator.add]\n", - " context: Annotated[AgentContext, Context(make_agent_context)]" - ] - }, - { - "cell_type": "markdown", - "id": "e03c5094-9297-4d19-a04e-3eedc75cefb4", - "metadata": {}, - "source": [ - "## Define the nodes\n", - "\n", - "We now need to define a few different nodes in our graph.\n", - "In `langgraph`, a node can be either a function or a [runnable](https://python.langchain.com/docs/concepts/#langchain-expression-language-lcel).\n", - "There are two main nodes we need for this:\n", - "\n", - "1. The agent: responsible for deciding what (if any) actions to take.\n", - "2. A function to invoke tools: if the agent decides to take an action, this node will then execute that action.\n", - "\n", - "We will also need to define some edges.\n", - "Some of these edges may be conditional.\n", - "The reason they are conditional is that based on the output of a node, one of several paths may be taken.\n", - "The path that is taken is not known until that node is run (the LLM decides).\n", - "\n", - "1. Conditional Edge: after the agent is called, we should either:\n", - " a. If the agent said to take an action, then the function to invoke tools should be called\n", - " b. If the agent said that it was finished, then it should finish\n", - "2. Normal Edge: after the tools are invoked, it should always go back to the agent to decide what to do next\n", - "\n", - "Let's define the nodes, as well as a function to decide how what conditional edge to take.\n", - "\n", - "**MODIFICATION**\n", - "\n", - "We define each node to receive the AgentState base model as its first argument." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "3b541bb9-900c-40d0-964d-7b5dfee30667", - "metadata": {}, - "outputs": [], - "source": [ - "# Define the function that determines whether to continue or not\n", - "def should_continue(state):\n", - " messages = state.messages\n", - " last_message = messages[-1]\n", - " # If there is no function call, then we finish\n", - " if not last_message.tool_calls:\n", - " return \"end\"\n", - " # Otherwise if there is, we continue\n", - " else:\n", - " return \"continue\"\n", - "\n", - "\n", - "# Define the function that calls the model\n", - "def call_model(state):\n", - " # using context value\n", - " req = state.context.httpx_session.get(\"https://www.langchain.com/\")\n", - " assert req.status_code == 200, req\n", - "\n", - " messages = state.messages\n", - " response = model.invoke(messages)\n", - " # We return a list, because this will get added to the existing list\n", - " return {\"messages\": [response]}" - ] - }, - { - "cell_type": "markdown", - "id": "ffd6e892-946c-4899-8cc0-7c9291c1f73b", - "metadata": {}, - "source": [ - "## Define the graph\n", - "\n", - "We can now put it all together and define the graph!" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "813ae66c-3b58-4283-a02a-36da72a2ab90", - "metadata": {}, - "outputs": [], - "source": [ - "from langgraph.graph import END, StateGraph, START\n", - "\n", - "# Define a new graph\n", - "workflow = StateGraph(AgentState)\n", - "\n", - "# Define the two nodes we will cycle between\n", - "workflow.add_node(\"agent\", call_model)\n", - "workflow.add_node(\"action\", tool_node)\n", - "\n", - "# Set the entrypoint as `agent`\n", - "# This means that this node is the first one called\n", - "workflow.add_edge(START, \"agent\")\n", - "\n", - "# We now add a conditional edge\n", - "workflow.add_conditional_edges(\n", - " # First, we define the start node. We use `agent`.\n", - " # This means these are the edges taken after the `agent` node is called.\n", - " \"agent\",\n", - " # Next, we pass in the function that will determine which node is called next.\n", - " should_continue,\n", - " # Finally we pass in a mapping.\n", - " # The keys are strings, and the values are other nodes.\n", - " # END is a special node marking that the graph should finish.\n", - " # What will happen is we will call `should_continue`, and then the output of that\n", - " # will be matched against the keys in this mapping.\n", - " # Based on which one it matches, that node will then be called.\n", - " {\n", - " # If `tools`, then we call the tool node.\n", - " \"continue\": \"action\",\n", - " # Otherwise we finish.\n", - " \"end\": END,\n", - " },\n", - ")\n", - "\n", - "# We now add a normal edge from `tools` to `agent`.\n", - "# This means that after `tools` is called, `agent` node is called next.\n", - "workflow.add_edge(\"action\", \"agent\")\n", - "\n", - "# Finally, we compile it!\n", - "# This compiles it into a LangChain Runnable,\n", - "# meaning you can use it as you would any other runnable\n", - "app = workflow.compile()" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "e09aaa63", - "metadata": {}, - "outputs": [ - { - "data": { - "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAA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4HzqZUxksTRzVY1shTr3q5Id2NmJsjNx3HZwI3UD7lmjPmlhP4fF9ldCL9uqI38xMREaRnhpzhbSeLmRcPuWaM+aWE/h8X2U9yzRnzSwn8Pi+yp7Wzznyj1NHMi4fcs0Z80sJ/D4vsp7lmjPmlhP4fF9lO1s858o9TRzIuH3LNGfNLCfw+L7Ke5Zoz5pYT+HxfZTtbPOfKPU0cyhvJyut8JFWPbOxrpbNlzOoiDonxtDj3AkvOw79mk9wUn7lmjPmlhP4fF9lT2NxNHDVRWx9OvRrgl3Y1omxs3PedmgDdRN+3TE7mZmYmNYxx05yaRwdtERc9UREQEREBQWb0Jp3Uc/b5PC0rljbbt5IW9rt8HOOu361Oor0V1W53qJxPgcFMPBvRpJJwUO5/wDck+0vnuNaM+Qof3kn2ldEXo73tPzKvOU5nmpfuNaM+Qof3kn2k9xrRnyFD+8k+0roid72n5lXnJmeal+41oz5Ch/eSfaT3GtGfIUP7yT7SuiJ3vafmVecmZ5qrR4WaRx8zJotPUXSsO7XzRCUtPwjm32P0q0gAAADYDzL6iwru13ZzXVM9ZyZmRERZoEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREH/9k=", - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "from IPython.display import Image, display\n", - "\n", - "display(Image(app.get_graph().draw_mermaid_png()))" - ] - }, - { - "cell_type": "markdown", - "id": "547c3931-3dae-4281-ad4e-4b51305594d4", - "metadata": {}, - "source": [ - "## Use it!\n", - "\n", - "We can now use it!\n", - "This now exposes the [same interface](https://python.langchain.com/docs/concepts/#langchain-expression-language-lcel) as all other LangChain runnables." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8edb04b9-40b6-46f1-a7a8-4b2d8aba7752", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_core.messages import HumanMessage\n", - "\n", - "inputs = {\"messages\": [HumanMessage(content=\"what is the weather in sf\")]}\n", - "for chunk in app.stream(inputs, stream_mode=\"values\"):\n", - " chunk[\"messages\"][-1].pretty_print()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.9" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 33bb7bda3..4745bd491 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -172,7 +172,6 @@ nav: - Transform inputs and outputs of a subgraph: how-tos/subgraph-transform-state.ipynb - State Management: - Use Pydantic model as state: how-tos/state-model.ipynb - - Use a context object in state: how-tos/state-context-key.ipynb - Have a separate input and output schema: how-tos/input_output_schema.ipynb - Pass private state between nodes inside the graph: how-tos/pass_private_state.ipynb - Other: diff --git a/examples/state-context-key.ipynb b/examples/state-context-key.ipynb deleted file mode 100644 index 931e94a19..000000000 --- a/examples/state-context-key.ipynb +++ /dev/null @@ -1,33 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "786b73a0", - "metadata": {}, - "source": [ - "This file has been moved to https://github.com/langchain-ai/langgraph/blob/main/docs/docs/how-tos/state-context-key.ipynb" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.8" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -}