Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(langchain): accept mapping values in LangGraph store (#5980)

Zayn Jarvis8fe792dd1497
diff --git a/examples/langchain/src/langchain_openviking/store.py b/examples/langchain/src/langchain_openviking/store.py
index 1c546faa9..34aa37d28 100644
--- a/examples/langchain/src/langchain_openviking/store.py
+++ b/examples/langchain/src/langchain_openviking/store.py
@@ -7,6 +7,7 @@ from __future__ import annotations
import asyncio
import json
import logging
+from collections.abc import Mapping
from datetime import datetime, timezone
from typing import TYPE_CHECKING, Any, Iterable
from urllib.parse import quote, unquote
@@ -160,7 +161,7 @@ class OpenVikingStore(BaseStore):
self,
namespace: tuple[str, ...],
key: str,
- value: dict[str, Any],
+ value: Mapping[str, Any],
index: bool | list[str] | None = None,
*,
ttl: Any = None,
@@ -173,7 +174,7 @@ class OpenVikingStore(BaseStore):
namespace = tuple(namespace)
now = datetime.now(timezone.utc)
data_uri = self._data_uri(namespace, key)
- record = self._write_record(data_uri, namespace, key, value, now)
+ record = self._write_record(data_uri, namespace, key, dict(value), now)
effective_index = self.index if index is None else index
index_uri = self._index_uri(namespace, key)
diff --git a/tests/unit/test_langchain_integration.py b/tests/unit/test_langchain_integration.py
index 3d7bcf90c..c182032d9 100644
--- a/tests/unit/test_langchain_integration.py
+++ b/tests/unit/test_langchain_integration.py
@@ -1,6 +1,7 @@
from __future__ import annotations
import json
+from types import MappingProxyType
from typing import Any
import pytest
@@ -1226,6 +1227,24 @@ def test_langgraph_store_round_trip_and_semantic_search():
assert store.list_namespaces(prefix=("users",)) == [("users", "ada")]
[email protected]("use_batch", [False, True])
+def test_langgraph_store_accepts_mapping_values(use_batch):
+ store = OpenVikingStore(client=InMemoryOpenVikingClient())
+ original = {"color": "azure", "nested": {"rank": 3}}
+ value = MappingProxyType(original)
+
+ if use_batch:
+ store.batch([PutOp(namespace=("users", "ada"), key="preferences", value=value)])
+ else:
+ store.put(("users", "ada"), "preferences", value)
+
+ item = store.get(("users", "ada"), "preferences")
+ assert item.value == original
+ assert isinstance(item.value, dict)
+ assert store.search(("users",), query="azure")[0].value == original
+ assert original == {"color": "azure", "nested": {"rank": 3}}
+
+
def test_langgraph_store_semantic_search_keeps_peer_id_out_of_retrieval():
client = InMemoryOpenVikingClient()
store = OpenVikingStore(client=client, actor_peer_id="peer-store")