Files
Mark Pollack 60356fb5ba Refactor Chat Memory Advisors to reduce code duplication and add extensive tests
Core Architecture Changes:
1. New Abstract Class: AbstractConversationHistoryAdvisor
   - Created a new abstract class that extends AbstractChatMemoryAdvisor<ChatMemory>
   - Provides common functionality for managing conversation history
   - Implements methods for retrieving messages and applying them to requests
   - Simplifies the implementation of concrete advisors

2. Refactored AbstractChatMemoryAdvisor
   - Removed the defaultChatMemoryRetrieveSize parameter from constructors
   - Enhanced the builder pattern with generic type parameters for better type safety
   - Added abstract before(ChatClientRequest, String) method for subclasses to implement
   - Improved logging for conversation ID handling

3. Refactored MessageChatMemoryAdvisor
   - Now extends AbstractConversationHistoryAdvisor instead of directly extending AbstractChatMemoryAdvisor
   - Simplified implementation by leveraging parent class methods
   - Fixed handling of multiple user messages in a single prompt
   - Updated the builder to properly extend AbstractChatMemoryAdvisor.AbstractBuilder<ChatMemory, Builder>

4. Refactored PromptChatMemoryAdvisor
   - Now extends AbstractConversationHistoryAdvisor instead of directly extending AbstractChatMemoryAdvisor
   - Fixed handling of multiple user messages by using getUserMessages() instead of getUserMessage()
   - Enhanced logging for better debugging
   - Updated the builder to properly extend AbstractChatMemoryAdvisor.AbstractBuilder<ChatMemory, Builder>

Test Changes:
1. New Test Classes
   - Added MessageChatMemoryAdvisorIT for integration testing of MessageChatMemoryAdvisor
   - Added PromptChatMemoryAdvisorIT for integration testing of PromptChatMemoryAdvisor
   - Both extend from AbstractChatMemoryAdvisorIT to share common test logic

2. Test Coverage
   - Added tests for handling multiple user messages in a single prompt
   - Added tests for custom conversation IDs
   - Added tests for maintaining separate conversations
   - Added tests for reactive mode operation

Key Improvements:
1. Code Duplication Reduction: Moved common functionality to the parent class
2. Bug Fix: Fixed a bug in PromptChatMemoryAdvisor where it was only storing the last user message
3. Enhanced Type Safety: Improved the builder pattern with proper generic type parameters
4. Better Logging: Added detailed logging for better debugging and traceability
5. Simplified API: Removed unnecessary parameters from constructors
6. Improved Test Coverage: Added comprehensive tests for various scenarios

Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-05-11 06:32:27 -04:00
..