The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
community[patch]: chat message history mypy fixes #17048 (#20114)
Wu Enze32c61b3ece9c
diff --git a/libs/community/langchain_community/chat_message_histories/neo4j.py b/libs/community/langchain_community/chat_message_histories/neo4j.pyindex a613c99877..aeca69cdad 100644--- a/libs/community/langchain_community/chat_message_histories/neo4j.py+++ b/libs/community/langchain_community/chat_message_histories/neo4j.py@@ -76,7 +76,7 @@ class Neo4jChatMessageHistory(BaseChatMessageHistory):).summary@property- def messages(self) -> List[BaseMessage]: # type: ignore+ def messages(self) -> List[BaseMessage]:"""Retrieve the messages from Neo4j"""query = (f"MATCH (s:`{self._node_label}`)-[:LAST_MESSAGE]->(last_message) "@@ -92,6 +92,13 @@ class Neo4jChatMessageHistory(BaseChatMessageHistory):messages = messages_from_dict([el["result"] for el in records])return messages+ @messages.setter+ def messages(self, messages: List[BaseMessage]) -> None:+ raise NotImplementedError(+ "Direct assignment to 'messages' is not allowed."+ " Use the 'add_messages' instead."+ )+def add_message(self, message: BaseMessage) -> None:"""Append the message to the record in Neo4j"""query = (diff --git a/libs/community/langchain_community/chat_message_histories/redis.py b/libs/community/langchain_community/chat_message_histories/redis.pyindex 37226e2ab2..0dd4d19bab 100644--- a/libs/community/langchain_community/chat_message_histories/redis.py+++ b/libs/community/langchain_community/chat_message_histories/redis.py@@ -47,13 +47,20 @@ class RedisChatMessageHistory(BaseChatMessageHistory):return self.key_prefix + self.session_id@property- def messages(self) -> List[BaseMessage]: # type: ignore+ def messages(self) -> List[BaseMessage]:"""Retrieve the messages from Redis"""_items = self.redis_client.lrange(self.key, 0, -1)items = [json.loads(m.decode("utf-8")) for m in _items[::-1]]messages = messages_from_dict(items)return messages+ @messages.setter+ def messages(self, messages: List[BaseMessage]) -> None:+ raise NotImplementedError(+ "Direct assignment to 'messages' is not allowed."+ " Use the 'add_messages' instead."+ )+def add_message(self, message: BaseMessage) -> None:"""Append the message to the record in Redis"""self.redis_client.lpush(self.key, json.dumps(message_to_dict(message)))