From 0ec39f87772b17d6fc5a5c708cfa073226de76ee Mon Sep 17 00:00:00 2001 From: William Fu-Hinthorn <13333726+hinthornw@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:23:08 -0800 Subject: [PATCH 1/2] Add support --- langgraph.json | 8 +++++++- pyproject.toml | 7 ++++--- src/chatbot/graph.py | 4 ++-- src/memory_graph/graph.py | 3 ++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/langgraph.json b/langgraph.json index ee9be20..b96e90e 100644 --- a/langgraph.json +++ b/langgraph.json @@ -6,5 +6,11 @@ }, "env": ".env", "python_version": "3.11", - "dependencies": ["."] + "dependencies": ["."], + "store": { + "index": { + "dims": 1536, + "embed": "openai:text-embedding-3-small" + } + } } diff --git a/pyproject.toml b/pyproject.toml index e22c337..6fb4418 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,13 +9,14 @@ readme = "README.md" license = { text = "MIT" } requires-python = ">=3.9" dependencies = [ - "langgraph>=0.2.32,<0.3.0", + "langgraph>=0.2.53,<0.3.0", + "langgraph-checkpoint>=2.0.8", # Optional (for selecting different models) "langchain-openai>=0.2.1", "langchain-anthropic>=0.2.1", - "langchain>=0.3.1", + "langchain>=0.3.8", "python-dotenv>=1.0.1", - "langgraph-sdk>=0.1.32", + "langgraph-sdk>=0.1.40", "trustcall>=0.0.21", ] diff --git a/src/chatbot/graph.py b/src/chatbot/graph.py index ba81690..b4db54b 100644 --- a/src/chatbot/graph.py +++ b/src/chatbot/graph.py @@ -13,7 +13,6 @@ from chatbot.configuration import ChatConfigurable from chatbot.utils import format_memories, init_model - @dataclass class ChatState: """The state of the chatbot.""" @@ -29,7 +28,8 @@ async def bot( namespace = (configurable.user_id,) # This lists ALL user memories in the provided namespace (up to the `limit`) # you can also filter by content. - items = await store.asearch(namespace) + query = "\n".join(str(message.content) for message in state.messages) + items = await store.asearch(namespace, query=query, limit=10) model = init_model(configurable.model) prompt = configurable.system_prompt.format( diff --git a/src/memory_graph/graph.py b/src/memory_graph/graph.py index 09c1da0..76b6f43 100644 --- a/src/memory_graph/graph.py +++ b/src/memory_graph/graph.py @@ -80,7 +80,8 @@ async def handle_insertion_memory( namespace = (configurable.user_id, "events", state.function_name) # Fetch existing memories from the store (5 most recent ones) for the this (insert) memory schema - existing_items = await store.asearch(namespace, limit=5) + query = "\n".join(str(message.content) for message in state.messages)[-3000:] + existing_items = await store.asearch(namespace, query=query, limit=5) # Get the configuration for this memory schema (identified by function_name) memory_config = next( From b9a922a2540d22953ee4af922610f0fcbf29cf00 Mon Sep 17 00:00:00 2001 From: William Fu-Hinthorn <13333726+hinthornw@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:24:43 -0800 Subject: [PATCH 2/2] Update --- .gitignore | 2 ++ src/chatbot/graph.py | 1 + 2 files changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b8af3ff..c00e3bd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ __pycache__/ # C extensions *.so +.langgraph_api +.vscode # Distribution / packaging .Python diff --git a/src/chatbot/graph.py b/src/chatbot/graph.py index b4db54b..9612faf 100644 --- a/src/chatbot/graph.py +++ b/src/chatbot/graph.py @@ -13,6 +13,7 @@ from chatbot.configuration import ChatConfigurable from chatbot.utils import format_memories, init_model + @dataclass class ChatState: """The state of the chatbot."""