Melodi Memory is an AI-powered feature that automatically generates and stores intelligent summaries of user conversations, enabling your AI agents to maintain context and continuity across multiple sessions with the same user.Why use Memory?
Persistent Context: Remember key details about users between conversations
Personalized Experiences: Provide more relevant and contextual responses based on conversation history
Reduced Repetition: Avoid asking users to re-explain their background or preferences
Enhanced User Experience: Create more natural, human-like interactions that build on previous conversations
Memory works by analyzing completed conversations and extracting the most important information into concise, actionable summaries that can be retrieved when users return for future interactions.
{ "userExternalId": "user-123", "threadId": 456, "threadExternalId": "support-session-789", "summary": "User is implementing OAuth authentication for their e-commerce platform. They're using Node.js with Express and need help with session management. Previous discussion covered JWT token security and they decided to use refresh tokens for better security.", "createdAt": "2024-01-15T10:30:45.123Z"}
import requestsfrom melodi import MelodiClientdef get_user_context(user_external_id): """Retrieve user memory to provide context for new conversations""" memory_response = requests.get( f"https://app.melodi.fyi/api/external/memory?userExternalId={user_external_id}", headers={"Authorization": f"Bearer {MELODI_API_KEY}"} ) if memory_response.status_code == 200: memory_data = memory_response.json() return f"Previous conversation context: {memory_data['summary']}" return "No previous conversation history available."def create_personalized_prompt(user_input, user_external_id): """Create an AI prompt that includes user memory for context""" context = get_user_context(user_external_id) prompt = f""" {context} Current user message: {user_input} Please provide a helpful response that takes into account the user's previous conversation history. """ return prompt