The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
Order messages in PostgresChatMessageHistory (#6830)
Matt Florence0f6737735d44
diff --git a/langchain/memory/chat_message_histories/postgres.py b/langchain/memory/chat_message_histories/postgres.pyindex 1b3ee7200b..3d06346d26 100644--- a/langchain/memory/chat_message_histories/postgres.py+++ b/langchain/memory/chat_message_histories/postgres.py@@ -49,7 +49,9 @@ class PostgresChatMessageHistory(BaseChatMessageHistory):@propertydef messages(self) -> List[BaseMessage]: # type: ignore"""Retrieve the messages from PostgreSQL"""- query = f"SELECT message FROM {self.table_name} WHERE session_id = %s;"+ query = (+ f"SELECT message FROM {self.table_name} WHERE session_id = %s ORDER BY id;"+ )self.cursor.execute(query, (self.session_id,))items = [record["message"] for record in self.cursor.fetchall()]messages = messages_from_dict(items)