From 75fa7395bd49a2499df8193e65b1385d54eb6b59 Mon Sep 17 00:00:00 2001 From: Vadym Barda Date: Thu, 25 Jul 2024 18:01:18 -0400 Subject: [PATCH] docs: add better state/reducers description in intro tutorial (#1140) --- examples/introduction.ipynb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/examples/introduction.ipynb b/examples/introduction.ipynb index a0720fdc9..58f20760f 100644 --- a/examples/introduction.ipynb +++ b/examples/introduction.ipynb @@ -84,8 +84,9 @@ ] }, { + "attachments": {}, "cell_type": "markdown", - "id": "ef7bcad1-1274-4b7c-a2e9-365180ef3a31", + "id": "9c374e41-f9b7-439e-a520-6d8c853c5220", "metadata": {}, "source": [ "## Part 1: Build a Basic Chatbot\n", @@ -120,13 +121,24 @@ "graph_builder = StateGraph(State)" ] }, + { + "cell_type": "markdown", + "id": "31c755cd-8994-4867-bdff-96a55d7beae7", + "metadata": {}, + "source": [ + "
\n", + "

Note

\n", + "

\n", + " The first thing you do when you define a graph is define the State of the graph. The State consists of the schema of the graph as well as reducer functions which specify how to apply updates to the state. In our example State is a TypedDict with a single key: messages. The messages key is annotated with the add_messages reducer function, which tells LangGraph to append new messages to the existing list, rather than overwriting it. State keys without an annotation will be overwritten by each update, storing the most recent value. Check out this conceptual guide to learn more about state, reducers and other low-level concepts.\n", + "

\n", + "
" + ] + }, { "cell_type": "markdown", "id": "4137feed-746e-4c72-a34a-f7a699ad5dcf", "metadata": {}, "source": [ - "**Notice** that we've defined our `State` as a TypedDict with a single key: `messages`. The `messages` key is annotated with the [`add_messages`](https://langchain-ai.github.io/langgraph/reference/graphs/?h=add+messages#add_messages) function, which tells LangGraph to append new messages to the existing list, rather than overwriting it.\n", - "\n", "So now our graph knows two things:\n", "\n", "1. Every `node` we define will receive the current `State` as input and return a value that updates that state.\n", @@ -3056,9 +3068,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "langgraph", "language": "python", - "name": "python3" + "name": "langgraph" }, "language_info": { "codemirror_mode": { @@ -3070,7 +3082,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.1" + "version": "3.11.9" } }, "nbformat": 4,