Adds helper functions to retrieve historical chat memory context (`_chat_memory_context`) and merge enriched messages. Updates both the main chat endpoint and regeneration logic to utilize this context, ensuring conversation continuity and reliable source deduplication.