Skip to content

Commit d764b76

Browse files
fix: patch store on runtime with langgraph>=0.6 (#105)
2 parents 68b1513 + 2bf3115 commit d764b76

File tree

3 files changed

+1274
-2122
lines changed

3 files changed

+1274
-2122
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "langmem"
3-
version = "0.0.28"
3+
version = "0.0.29"
44
description = "Prebuilt utilities for memory management and retrieval."
55
readme = "README.md"
66
requires-python = ">=3.10"
@@ -10,7 +10,7 @@ dependencies = [
1010
"langchain-core>=0.3.46",
1111
"langchain-openai>=0.3.1",
1212
"trustcall>=0.0.39",
13-
"langgraph>=0.3.23",
13+
"langgraph>=0.6.0,<0.7.0",
1414
"langchain-anthropic>=0.3.3",
1515
"langsmith>=0.3.8",
1616
"langgraph-checkpoint>=2.0.12",

src/langmem/reflection.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
from langchain_core.runnables import Runnable, RunnableConfig
1313
from langchain_core.runnables.config import var_child_runnable_config
14+
from langgraph._internal._constants import CONFIG_KEY_RUNTIME
1415
from langgraph.config import get_config
15-
from langgraph.constants import CONF, CONFIG_KEY_STORE
16+
from langgraph.constants import CONF
17+
from langgraph.runtime import Runtime
1618
from langgraph.store.base import BaseStore
1719
from langgraph_sdk import get_client, get_sync_client
1820
from langsmith.utils import ContextThreadPoolExecutor
@@ -294,7 +296,9 @@ def submit(
294296
with self._store_lock:
295297
if self._store is None:
296298
try:
297-
self._store = config[CONF][CONFIG_KEY_STORE]
299+
existing_store = config[CONF][CONFIG_KEY_RUNTIME].store
300+
if existing_store is None:
301+
raise KeyError()
298302
except KeyError:
299303
raise ValueError(
300304
"ReflectionExecutor could not resolve store to persist memories to."
@@ -421,7 +425,13 @@ def _process_queue(self: "LocalReflectionExecutor"):
421425
try:
422426
config = task.config or {}
423427
configurable = config.setdefault(CONF, {})
424-
configurable[CONFIG_KEY_STORE] = self._store
428+
if (runtime := configurable.get(CONFIG_KEY_RUNTIME)) is None:
429+
patched_runtime = Runtime(store=self._store)
430+
else:
431+
patched_runtime = typing.cast(Runtime, runtime).override(
432+
store=self._store
433+
)
434+
configurable[CONFIG_KEY_RUNTIME] = patched_runtime
425435
original = var_child_runnable_config.set(config)
426436
result = self._reflector.invoke(task.payload)
427437
var_child_runnable_config.set(original.old_value)
@@ -444,7 +454,13 @@ def _process_queue(self: "LocalReflectionExecutor"):
444454
try:
445455
config = task.config or {}
446456
configurable = config.setdefault(CONF, {})
447-
configurable[CONFIG_KEY_STORE] = self._store
457+
if (runtime := configurable.get(CONFIG_KEY_RUNTIME)) is None:
458+
patched_runtime = Runtime(store=self._store)
459+
else:
460+
patched_runtime = typing.cast(Runtime, runtime).override(
461+
store=self._store
462+
)
463+
configurable[CONFIG_KEY_RUNTIME] = patched_runtime
448464
original = var_child_runnable_config.set(config)
449465
result = self._reflector.invoke(task.payload)
450466
var_child_runnable_config.set(original.old_value)

0 commit comments

Comments
 (0)