Skip to content

Commit 971a64d

Browse files
committed
docs: more notebook examples
1 parent 9f9ff0d commit 971a64d

File tree

4 files changed

+138
-158
lines changed

4 files changed

+138
-158
lines changed

langgraph/docs/create-react-agent-memory.ipynb

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
},
5959
{
6060
"cell_type": "code",
61-
"execution_count": 1,
61+
"execution_count": 9,
6262
"id": "a213e11a-5c62-4ddb-a707-490d91add383",
6363
"metadata": {},
6464
"outputs": [],
@@ -69,18 +69,10 @@
6969
},
7070
{
7171
"cell_type": "code",
72-
"execution_count": 2,
72+
"execution_count": 10,
7373
"id": "23a1885c-04ab-4750-aefa-105891fddf3e",
7474
"metadata": {},
75-
"outputs": [
76-
{
77-
"name": "stdin",
78-
"output_type": "stream",
79-
"text": [
80-
"OPENAI_API_KEY: ········\n"
81-
]
82-
}
83-
],
75+
"outputs": [],
8476
"source": [
8577
"import getpass\n",
8678
"import os\n",
@@ -117,35 +109,24 @@
117109
},
118110
{
119111
"cell_type": "code",
120-
"execution_count": 3,
112+
"execution_count": 11,
121113
"id": "7a154152-973e-4b5d-aa13-48c617744a4c",
122114
"metadata": {},
123-
"outputs": [
124-
{
125-
"name": "stdout",
126-
"output_type": "stream",
127-
"text": [
128-
"22:31:51 redisvl.index.index INFO Index already exists, not overwriting.\n",
129-
"22:31:51 redisvl.index.index INFO Index already exists, not overwriting.\n",
130-
"22:31:51 redisvl.index.index INFO Index already exists, not overwriting.\n"
131-
]
132-
}
133-
],
115+
"outputs": [],
134116
"source": [
135-
"from typing import Literal\n",
136-
"\n",
137-
"from langchain_core.tools import tool\n",
138-
"\n",
139117
"# First we initialize the model we want to use.\n",
140118
"from langchain_openai import ChatOpenAI\n",
141119
"\n",
142-
"from langgraph.checkpoint.redis import RedisSaver\n",
143-
"from langgraph.prebuilt import create_react_agent\n",
144-
"\n",
145120
"model = ChatOpenAI(model=\"gpt-4o\", temperature=0)\n",
146121
"\n",
147122
"\n",
148123
"# For this tutorial we will use custom tool that returns pre-defined values for weather in two cities (NYC & SF)\n",
124+
"\n",
125+
"from typing import Literal\n",
126+
"\n",
127+
"from langchain_core.tools import tool\n",
128+
"\n",
129+
"\n",
149130
"@tool\n",
150131
"def get_weather(city: Literal[\"nyc\", \"sf\"]):\n",
151132
" \"\"\"Use this to get weather information.\"\"\"\n",
@@ -159,18 +140,19 @@
159140
"\n",
160141
"tools = [get_weather]\n",
161142
"\n",
162-
"# We can add \"chat memory\" to the graph with LangGraph's Redis checkpointer\n",
143+
"# We can add \"chat memory\" to the graph with LangGraph's Redi checkpointer\n",
163144
"# to retain the chat context between interactions\n",
164-
"\n",
145+
"from langgraph.checkpoint.redis import RedisSaver\n",
165146
"\n",
166147
"REDIS_URI = \"redis://redis:6379\"\n",
167148
"memory = None\n",
168149
"with RedisSaver.from_conn_string(REDIS_URI) as cp:\n",
169-
" cp.setup()\n",
170-
" memory = cp\n",
150+
" cp.setup()\n",
151+
" memory = cp\n",
171152
"\n",
172153
"# Define the graph\n",
173154
"\n",
155+
"from langgraph.prebuilt import create_react_agent\n",
174156
"\n",
175157
"graph = create_react_agent(model, tools=tools, checkpointer=memory)"
176158
]
@@ -187,7 +169,7 @@
187169
},
188170
{
189171
"cell_type": "code",
190-
"execution_count": 4,
172+
"execution_count": 12,
191173
"id": "16636975-5f2d-4dc7-ab8e-d0bea0830a28",
192174
"metadata": {},
193175
"outputs": [],
@@ -203,7 +185,7 @@
203185
},
204186
{
205187
"cell_type": "code",
206-
"execution_count": 5,
188+
"execution_count": 13,
207189
"id": "9ffff6c3-a4f5-47c9-b51d-97caaee85cd6",
208190
"metadata": {},
209191
"outputs": [
@@ -216,8 +198,8 @@
216198
"What's the weather in NYC?\n",
217199
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
218200
"Tool Calls:\n",
219-
" get_weather (call_Edwfw0WiyIJ7vt9xzU9xvyeg)\n",
220-
" Call ID: call_Edwfw0WiyIJ7vt9xzU9xvyeg\n",
201+
" get_weather (call_RHv6T6OBCn7eKOlm5qEpLK4P)\n",
202+
" Call ID: call_RHv6T6OBCn7eKOlm5qEpLK4P\n",
221203
" Args:\n",
222204
" city: nyc\n",
223205
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
@@ -247,7 +229,7 @@
247229
},
248230
{
249231
"cell_type": "code",
250-
"execution_count": 6,
232+
"execution_count": 14,
251233
"id": "187479f9-32fa-4611-9487-cf816ba2e147",
252234
"metadata": {},
253235
"outputs": [
@@ -260,7 +242,7 @@
260242
"What's it known for?\n",
261243
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
262244
"\n",
263-
"Could you please specify what \"it\" refers to? Are you asking about a specific city, person, event, or something else?\n"
245+
"Could you please specify what \"it\" refers to? Are you asking about a specific place, person, event, or something else?\n"
264246
]
265247
}
266248
],

0 commit comments

Comments
 (0)