diff --git a/docs/docs/how-tos/streaming-from-final-node.ipynb b/docs/docs/how-tos/streaming-from-final-node.ipynb index bdd1e5340..aef5d346a 100644 --- a/docs/docs/how-tos/streaming-from-final-node.ipynb +++ b/docs/docs/how-tos/streaming-from-final-node.ipynb @@ -13,7 +13,31 @@ "id": "964686a6-8fed-4360-84d2-958c48186008", "metadata": {}, "source": [ - "A common use case is streaming from an agent is to stream LLM tokens from inside the final node. This guide demonstrates how you can do this.\n", + "
Prerequisites
\n", + "\n", + " This guide assumes familiarity with the following:\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", - " " + "" ] }, { @@ -73,7 +97,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "id": "5e62618d-0e0c-483c-acd3-40a26e61894a", "metadata": {}, "outputs": [], @@ -120,7 +144,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "id": "8c7339d2-1835-4b5a-a99c-a60e150280af", "metadata": {}, "outputs": [], @@ -164,28 +188,28 @@ " return {\"messages\": [response]}\n", "\n", "\n", - "workflow = StateGraph(MessagesState)\n", + "builder = StateGraph(MessagesState)\n", "\n", - "workflow.add_node(\"agent\", call_model)\n", - "workflow.add_node(\"tools\", tool_node)\n", + "builder.add_node(\"agent\", call_model)\n", + "builder.add_node(\"tools\", tool_node)\n", "# add a separate final node\n", - "workflow.add_node(\"final\", call_final_model)\n", + "builder.add_node(\"final\", call_final_model)\n", "\n", - "workflow.add_edge(START, \"agent\")\n", - "workflow.add_conditional_edges(\n", + "builder.add_edge(START, \"agent\")\n", + "builder.add_conditional_edges(\n", " \"agent\",\n", " should_continue,\n", ")\n", "\n", - "workflow.add_edge(\"tools\", \"agent\")\n", - "workflow.add_edge(\"final\", END)\n", + "builder.add_edge(\"tools\", \"agent\")\n", + "builder.add_edge(\"final\", END)\n", "\n", - "app = workflow.compile()" + "graph = builder.compile()" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "id": "2ab6d079-ba06-48ba-abe5-e72df24407af", "metadata": {}, "outputs": [ @@ -203,7 +227,7 @@ "source": [ "from IPython.display import display, Image\n", "\n", - "display(Image(app.get_graph().draw_mermaid_png()))" + "display(Image(graph.get_graph().draw_mermaid_png()))" ] }, { @@ -214,19 +238,6 @@ "## Stream outputs from the final node" ] }, - { - "cell_type": "code", - "execution_count": 5, - "id": "84d65cbe-4cfe-44f8-b49e-b37632887c91", - "metadata": {}, - "outputs": [], - "source": [ - "import warnings\n", - "from langchain_core._api import LangChainBetaWarning\n", - "\n", - "warnings.filterwarnings(\"ignore\", category=LangChainBetaWarning)" - ] - }, { "cell_type": "markdown", "id": "5cfaeb64-5506-4546-96c0-4891e6288ad9", @@ -260,8 +271,8 @@ "source": [ "from langchain_core.messages import HumanMessage\n", "\n", - "inputs = [HumanMessage(content=\"what is the weather in sf\")]\n", - "async for msg, metadata in app.astream({\"messages\": inputs}, stream_mode=\"messages\"):\n", + "inputs = {\"messages\": [HumanMessage(content=\"what is the weather in sf\")]}\n", + "for msg, metadata in graph.stream(inputs, stream_mode=\"messages\"):\n", " if (\n", " msg.content\n", " and not isinstance(msg, HumanMessage)\n", @@ -296,13 +307,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "Well| folks|,| looks| like| we|'ve| got| some| cloudy| skies| in| the| Big| Apple| today|.| So| grab| your| umbrella| just| in| case|,| and| don|'t| let| those| clouds| rain| on| your| parade|!|" + "Looks| like| we|'ve| got| some| clouds| roll|in|'| in| over| the| Big| Apple| today|,| folks|!| Keep| an| eye| out| for| some| over|cast| skies| in| NYC|.|" ] } ], "source": [ - "inputs = {\"messages\": [(\"human\", \"what's the weather in nyc?\")]}\n", - "async for event in app.astream_events(inputs, version=\"v2\"):\n", + "inputs = {\"messages\": [HumanMessage(content=\"what's the weather in nyc?\")]}\n", + "async for event in graph.astream_events(inputs, version=\"v2\"):\n", " kind = event[\"event\"]\n", " tags = event.get(\"tags\", [])\n", " # filter on the custom tag\n", diff --git a/docs/docs/how-tos/subgraph.ipynb b/docs/docs/how-tos/subgraph.ipynb index 0c48a7b7d..85addf889 100644 --- a/docs/docs/how-tos/subgraph.ipynb +++ b/docs/docs/how-tos/subgraph.ipynb @@ -11,7 +11,31 @@ "source": [ "# How to create subgraphs\n", "\n", - "For more complex systems, subgraphs are a useful design principle. Subgraphs allow you to create and manage different states in different parts of your graph. This allows you build things like [multi-agent teams](https://langchain-ai.github.io/langgraph/tutorials/multi_agent/hierarchical_agent_teams/), where each team can track its own separate state.\n", + "Prerequisites
\n", + "\n", + " This guide assumes familiarity with the following:\n", + "