diff --git a/libs/core/langchain_core/chat_history.py b/libs/core/langchain_core/chat_history.py index da14d07065..ffbba96983 100644 --- a/libs/core/langchain_core/chat_history.py +++ b/libs/core/langchain_core/chat_history.py @@ -26,7 +26,6 @@ from langchain_core.messages import ( get_buffer_string, ) from langchain_core.pydantic_v1 import BaseModel, Field -from langchain_core.runnables import run_in_executor class BaseChatMessageHistory(ABC): @@ -102,6 +101,8 @@ class BaseChatMessageHistory(ABC): In general, fetching messages may involve IO to the underlying persistence layer. """ + from langchain_core.runnables.config import run_in_executor + return await run_in_executor(None, lambda: self.messages) def add_user_message(self, message: Union[HumanMessage, str]) -> None: @@ -172,6 +173,8 @@ class BaseChatMessageHistory(ABC): Args: messages: A list of BaseMessage objects to store. """ + from langchain_core.runnables.config import run_in_executor + await run_in_executor(None, self.add_messages, messages) @abstractmethod @@ -180,6 +183,8 @@ class BaseChatMessageHistory(ABC): async def aclear(self) -> None: """Remove all messages from the store""" + from langchain_core.runnables.config import run_in_executor + await run_in_executor(None, self.clear) def __str__(self) -> str: diff --git a/libs/core/langchain_core/runnables/__init__.py b/libs/core/langchain_core/runnables/__init__.py index 9c4362c9c8..518d5c38c9 100644 --- a/libs/core/langchain_core/runnables/__init__.py +++ b/libs/core/langchain_core/runnables/__init__.py @@ -36,6 +36,7 @@ from langchain_core.runnables.config import ( run_in_executor, ) from langchain_core.runnables.fallbacks import RunnableWithFallbacks +from langchain_core.runnables.history import RunnableWithMessageHistory from langchain_core.runnables.passthrough import ( RunnableAssign, RunnablePassthrough, @@ -78,6 +79,7 @@ __all__ = [ "RunnablePick", "RunnableSequence", "RunnableWithFallbacks", + "RunnableWithMessageHistory", "get_config_list", "aadd", "add", diff --git a/libs/core/tests/unit_tests/runnables/test_imports.py b/libs/core/tests/unit_tests/runnables/test_imports.py index 48098aa6db..12b1a80d1b 100644 --- a/libs/core/tests/unit_tests/runnables/test_imports.py +++ b/libs/core/tests/unit_tests/runnables/test_imports.py @@ -26,6 +26,7 @@ EXPECTED_ALL = [ "RunnablePick", "RunnableSequence", "RunnableWithFallbacks", + "RunnableWithMessageHistory", "get_config_list", "aadd", "add",