Skip to content

The agent engineering platform.

langchain[patch]: chat histories to handle optional community dependence (#21194)

Eugene Yurtsevb5c3a04e4bcc
diff --git a/libs/langchain/langchain/memory/chat_message_histories/__init__.py b/libs/langchain/langchain/memory/chat_message_histories/__init__.py
index 04d87b4786..91910137f6 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/__init__.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/__init__.py
@@ -1,32 +1,69 @@
-import warnings
-from typing import Any
+from typing import TYPE_CHECKING, Any
-from langchain_core._api import LangChainDeprecationWarning
+from langchain._api import create_importer
-from langchain._api.interactive_env import is_interactive_env
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import (
+ AstraDBChatMessageHistory,
+ CassandraChatMessageHistory,
+ ChatMessageHistory,
+ CosmosDBChatMessageHistory,
+ DynamoDBChatMessageHistory,
+ ElasticsearchChatMessageHistory,
+ FileChatMessageHistory,
+ FirestoreChatMessageHistory,
+ MomentoChatMessageHistory,
+ MongoDBChatMessageHistory,
+ Neo4jChatMessageHistory,
+ PostgresChatMessageHistory,
+ RedisChatMessageHistory,
+ RocksetChatMessageHistory,
+ SingleStoreDBChatMessageHistory,
+ SQLChatMessageHistory,
+ StreamlitChatMessageHistory,
+ UpstashRedisChatMessageHistory,
+ XataChatMessageHistory,
+ ZepChatMessageHistory,
+ )
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "AstraDBChatMessageHistory": "langchain_community.chat_message_histories",
+ "CassandraChatMessageHistory": "langchain_community.chat_message_histories",
+ "ChatMessageHistory": "langchain_community.chat_message_histories",
+ "CosmosDBChatMessageHistory": "langchain_community.chat_message_histories",
+ "DynamoDBChatMessageHistory": "langchain_community.chat_message_histories",
+ "ElasticsearchChatMessageHistory": "langchain_community.chat_message_histories",
+ "FileChatMessageHistory": "langchain_community.chat_message_histories",
+ "FirestoreChatMessageHistory": "langchain_community.chat_message_histories",
+ "MomentoChatMessageHistory": "langchain_community.chat_message_histories",
+ "MongoDBChatMessageHistory": "langchain_community.chat_message_histories",
+ "Neo4jChatMessageHistory": "langchain_community.chat_message_histories",
+ "PostgresChatMessageHistory": "langchain_community.chat_message_histories",
+ "RedisChatMessageHistory": "langchain_community.chat_message_histories",
+ "RocksetChatMessageHistory": "langchain_community.chat_message_histories",
+ "SQLChatMessageHistory": "langchain_community.chat_message_histories",
+ "SingleStoreDBChatMessageHistory": "langchain_community.chat_message_histories",
+ "StreamlitChatMessageHistory": "langchain_community.chat_message_histories",
+ "UpstashRedisChatMessageHistory": "langchain_community.chat_message_histories",
+ "XataChatMessageHistory": "langchain_community.chat_message_histories",
+ "ZepChatMessageHistory": "langchain_community.chat_message_histories",
+}
-def __getattr__(name: str) -> Any:
- from langchain_community import chat_message_histories
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
- # If not in interactive env, raise warning.
- if not is_interactive_env():
- warnings.warn(
- "Importing chat message histories from langchain is deprecated. Importing "
- "from langchain will no longer be supported as of langchain==0.2.0. "
- "Please import from langchain-community instead:\n\n"
- f"`from langchain_community.chat_message_histories import {name}`.\n\n"
- "To install langchain-community run `pip install -U langchain-community`.",
- category=LangChainDeprecationWarning,
- )
- return getattr(chat_message_histories, name)
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
__all__ = [
"AstraDBChatMessageHistory",
- "ChatMessageHistory",
"CassandraChatMessageHistory",
+ "ChatMessageHistory",
"CosmosDBChatMessageHistory",
"DynamoDBChatMessageHistory",
"ElasticsearchChatMessageHistory",
@@ -34,14 +71,14 @@ __all__ = [
"FirestoreChatMessageHistory",
"MomentoChatMessageHistory",
"MongoDBChatMessageHistory",
+ "Neo4jChatMessageHistory",
"PostgresChatMessageHistory",
"RedisChatMessageHistory",
"RocksetChatMessageHistory",
+ "SingleStoreDBChatMessageHistory",
"SQLChatMessageHistory",
"StreamlitChatMessageHistory",
- "SingleStoreDBChatMessageHistory",
+ "UpstashRedisChatMessageHistory",
"XataChatMessageHistory",
"ZepChatMessageHistory",
- "UpstashRedisChatMessageHistory",
- "Neo4jChatMessageHistory",
]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/astradb.py b/libs/langchain/langchain/memory/chat_message_histories/astradb.py
index d10d90e640..3895f0633c 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/astradb.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/astradb.py
@@ -1,5 +1,25 @@
-from langchain_community.chat_message_histories.astradb import (
- AstraDBChatMessageHistory,
-)
+from typing import TYPE_CHECKING, Any
-__all__ = ["AstraDBChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import AstraDBChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "AstraDBChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "AstraDBChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/cassandra.py b/libs/langchain/langchain/memory/chat_message_histories/cassandra.py
index 24c2bf7a2f..e0c61cd234 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/cassandra.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/cassandra.py
@@ -1,5 +1,25 @@
-from langchain_community.chat_message_histories.cassandra import (
- CassandraChatMessageHistory,
-)
+from typing import TYPE_CHECKING, Any
-__all__ = ["CassandraChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import CassandraChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "CassandraChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "CassandraChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/cosmos_db.py b/libs/langchain/langchain/memory/chat_message_histories/cosmos_db.py
index 7d2c4cbeb3..6e9c8bf2f7 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/cosmos_db.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/cosmos_db.py
@@ -1,5 +1,25 @@
-from langchain_community.chat_message_histories.cosmos_db import (
- CosmosDBChatMessageHistory,
-)
+from typing import TYPE_CHECKING, Any
-__all__ = ["CosmosDBChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import CosmosDBChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "CosmosDBChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "CosmosDBChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/dynamodb.py b/libs/langchain/langchain/memory/chat_message_histories/dynamodb.py
index 376e61ca62..e0c5df1a4d 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/dynamodb.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/dynamodb.py
@@ -1,5 +1,25 @@
-from langchain_community.chat_message_histories.dynamodb import (
- DynamoDBChatMessageHistory,
-)
+from typing import TYPE_CHECKING, Any
-__all__ = ["DynamoDBChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import DynamoDBChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "DynamoDBChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "DynamoDBChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/elasticsearch.py b/libs/langchain/langchain/memory/chat_message_histories/elasticsearch.py
index b89553a73d..8845e67a58 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/elasticsearch.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/elasticsearch.py
@@ -1,5 +1,27 @@
-from langchain_community.chat_message_histories.elasticsearch import (
- ElasticsearchChatMessageHistory,
-)
+from typing import TYPE_CHECKING, Any
-__all__ = ["ElasticsearchChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import (
+ ElasticsearchChatMessageHistory,
+ )
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "ElasticsearchChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "ElasticsearchChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/file.py b/libs/langchain/langchain/memory/chat_message_histories/file.py
index aeb1a3b75d..2f9a0a9e68 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/file.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/file.py
@@ -1,3 +1,25 @@
-from langchain_community.chat_message_histories.file import FileChatMessageHistory
+from typing import TYPE_CHECKING, Any
-__all__ = ["FileChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import FileChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "FileChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "FileChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/firestore.py b/libs/langchain/langchain/memory/chat_message_histories/firestore.py
index 52ff603408..0d81d24d55 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/firestore.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/firestore.py
@@ -1,5 +1,25 @@
-from langchain_community.chat_message_histories.firestore import (
- FirestoreChatMessageHistory,
-)
+from typing import TYPE_CHECKING, Any
-__all__ = ["FirestoreChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import FirestoreChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "FirestoreChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "FirestoreChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/in_memory.py b/libs/langchain/langchain/memory/chat_message_histories/in_memory.py
index d00d6de695..78bc4cc0bb 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/in_memory.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/in_memory.py
@@ -1,3 +1,21 @@
-from langchain_community.chat_message_histories.in_memory import ChatMessageHistory
+from typing import TYPE_CHECKING, Any
+
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories.in_memory import ChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {"ChatMessageHistory": "langchain_community.chat_message_histories"}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
__all__ = ["ChatMessageHistory"]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/momento.py b/libs/langchain/langchain/memory/chat_message_histories/momento.py
index 3d7bfce96b..65d7cce303 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/momento.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/momento.py
@@ -1,5 +1,25 @@
-from langchain_community.chat_message_histories.momento import (
- MomentoChatMessageHistory,
-)
+from typing import TYPE_CHECKING, Any
-__all__ = ["MomentoChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import MomentoChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "MomentoChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "MomentoChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/mongodb.py b/libs/langchain/langchain/memory/chat_message_histories/mongodb.py
index da7461dea2..f0f7db2c46 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/mongodb.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/mongodb.py
@@ -1,5 +1,25 @@
-from langchain_community.chat_message_histories.mongodb import (
- MongoDBChatMessageHistory,
-)
+from typing import TYPE_CHECKING, Any
-__all__ = ["MongoDBChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import MongoDBChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "MongoDBChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "MongoDBChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/neo4j.py b/libs/langchain/langchain/memory/chat_message_histories/neo4j.py
index 52a202ba8c..ac60cd7c34 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/neo4j.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/neo4j.py
@@ -1,3 +1,25 @@
-from langchain_community.chat_message_histories.neo4j import Neo4jChatMessageHistory
+from typing import TYPE_CHECKING, Any
-__all__ = ["Neo4jChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import Neo4jChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "Neo4jChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "Neo4jChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/postgres.py b/libs/langchain/langchain/memory/chat_message_histories/postgres.py
index 9e0a921ca2..eb05b7dba4 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/postgres.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/postgres.py
@@ -1,5 +1,25 @@
-from langchain_community.chat_message_histories.postgres import (
- PostgresChatMessageHistory,
-)
+from typing import TYPE_CHECKING, Any
-__all__ = ["PostgresChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import PostgresChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "PostgresChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "PostgresChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/redis.py b/libs/langchain/langchain/memory/chat_message_histories/redis.py
index 0a81d2563b..a6dc08e260 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/redis.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/redis.py
@@ -1,3 +1,25 @@
-from langchain_community.chat_message_histories.redis import RedisChatMessageHistory
+from typing import TYPE_CHECKING, Any
-__all__ = ["RedisChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import RedisChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "RedisChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "RedisChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/rocksetdb.py b/libs/langchain/langchain/memory/chat_message_histories/rocksetdb.py
index f27ee6e66e..64116d5b12 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/rocksetdb.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/rocksetdb.py
@@ -1,5 +1,25 @@
-from langchain_community.chat_message_histories.rocksetdb import (
- RocksetChatMessageHistory,
-)
+from typing import TYPE_CHECKING, Any
-__all__ = ["RocksetChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import RocksetChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "RocksetChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "RocksetChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/singlestoredb.py b/libs/langchain/langchain/memory/chat_message_histories/singlestoredb.py
index 41756f6660..dc6b795243 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/singlestoredb.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/singlestoredb.py
@@ -1,5 +1,27 @@
-from langchain_community.chat_message_histories.singlestoredb import (
- SingleStoreDBChatMessageHistory,
-)
+from typing import TYPE_CHECKING, Any
-__all__ = ["SingleStoreDBChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import (
+ SingleStoreDBChatMessageHistory,
+ )
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "SingleStoreDBChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "SingleStoreDBChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/sql.py b/libs/langchain/langchain/memory/chat_message_histories/sql.py
index f739eab042..5ff23ce24f 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/sql.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/sql.py
@@ -1,8 +1,30 @@
-from langchain_community.chat_message_histories.sql import (
- BaseMessageConverter,
- DefaultMessageConverter,
- SQLChatMessageHistory,
-)
+from typing import TYPE_CHECKING, Any
+
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import SQLChatMessageHistory
+ from langchain_community.chat_message_histories.sql import (
+ BaseMessageConverter,
+ DefaultMessageConverter,
+ )
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "BaseMessageConverter": "langchain_community.chat_message_histories.sql",
+ "DefaultMessageConverter": "langchain_community.chat_message_histories.sql",
+ "SQLChatMessageHistory": "langchain_community.chat_message_histories",
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
__all__ = [
"BaseMessageConverter",
diff --git a/libs/langchain/langchain/memory/chat_message_histories/streamlit.py b/libs/langchain/langchain/memory/chat_message_histories/streamlit.py
index 82fd8de7b4..b1a7482404 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/streamlit.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/streamlit.py
@@ -1,5 +1,25 @@
-from langchain_community.chat_message_histories.streamlit import (
- StreamlitChatMessageHistory,
-)
+from typing import TYPE_CHECKING, Any
-__all__ = ["StreamlitChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import StreamlitChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "StreamlitChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "StreamlitChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/upstash_redis.py b/libs/langchain/langchain/memory/chat_message_histories/upstash_redis.py
index d038fa46f5..af4599f7bd 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/upstash_redis.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/upstash_redis.py
@@ -1,5 +1,27 @@
-from langchain_community.chat_message_histories.upstash_redis import (
- UpstashRedisChatMessageHistory,
-)
+from typing import TYPE_CHECKING, Any
-__all__ = ["UpstashRedisChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import (
+ UpstashRedisChatMessageHistory,
+ )
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "UpstashRedisChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "UpstashRedisChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/xata.py b/libs/langchain/langchain/memory/chat_message_histories/xata.py
index bc4490214f..43cfe67266 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/xata.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/xata.py
@@ -1,3 +1,25 @@
-from langchain_community.chat_message_histories.xata import XataChatMessageHistory
+from typing import TYPE_CHECKING, Any
-__all__ = ["XataChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import XataChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "XataChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "XataChatMessageHistory",
+]
diff --git a/libs/langchain/langchain/memory/chat_message_histories/zep.py b/libs/langchain/langchain/memory/chat_message_histories/zep.py
index ef357b9a5a..9b63e0fc22 100644
--- a/libs/langchain/langchain/memory/chat_message_histories/zep.py
+++ b/libs/langchain/langchain/memory/chat_message_histories/zep.py
@@ -1,3 +1,25 @@
-from langchain_community.chat_message_histories.zep import ZepChatMessageHistory
+from typing import TYPE_CHECKING, Any
-__all__ = ["ZepChatMessageHistory"]
+from langchain._api import create_importer
+
+if TYPE_CHECKING:
+ from langchain_community.chat_message_histories import ZepChatMessageHistory
+
+# Create a way to dynamically look up deprecated imports.
+# Used to consolidate logic for raising deprecation warnings and
+# handling optional imports.
+DEPRECATED_LOOKUP = {
+ "ZepChatMessageHistory": "langchain_community.chat_message_histories"
+}
+
+_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
+
+
+def __getattr__(name: str) -> Any:
+ """Look up attributes dynamically."""
+ return _import_attribute(name)
+
+
+__all__ = [
+ "ZepChatMessageHistory",
+]