diff --git a/features/steps/memory_service_coverage_steps.py b/features/steps/memory_service_coverage_steps.py index 0ffcf079f..5e8143aff 100644 --- a/features/steps/memory_service_coverage_steps.py +++ b/features/steps/memory_service_coverage_steps.py @@ -342,7 +342,10 @@ def step_validate_sql_constructor(context: Any) -> None: assert context.sql_history_calls _, kwargs = context.sql_history_calls[0] assert kwargs["session_id"] == "sql-session" - assert kwargs["connection_string"] == context.connection_string + actual_connection = kwargs.get("connection") or kwargs.get("connection_string") + assert actual_connection == context.connection_string, ( + f"Expected {context.connection_string}, got {actual_connection}" + ) assert kwargs.get("table_name") == "message_history" diff --git a/src/cleveragents/application/services/memory_service.py b/src/cleveragents/application/services/memory_service.py index dd85c8e1f..460fdd96e 100644 --- a/src/cleveragents/application/services/memory_service.py +++ b/src/cleveragents/application/services/memory_service.py @@ -485,15 +485,26 @@ class MemoryService: # Initialize message history history: BaseChatMessageHistory if connection_string: - # Use SQL persistence if connection string provided - history = cast( - BaseChatMessageHistory, - SQLChatMessageHistory( - session_id=session_id, - connection_string=connection_string, - table_name="message_history", - ), - ) + # Use SQL persistence if connection string provided. + # langchain-community >= 0.3 renamed connection_string to connection. + try: + history = cast( + BaseChatMessageHistory, + SQLChatMessageHistory( + session_id=session_id, + connection=connection_string, + table_name="message_history", + ), + ) + except TypeError: + history = cast( + BaseChatMessageHistory, + SQLChatMessageHistory( + session_id=session_id, + connection_string=connection_string, + table_name="message_history", + ), + ) else: # Use in-memory storage as fallback history = InMemoryChatMessageHistory()