Use this file to discover all available pages before exploring further.
Mem0 Platform provides a smart, self-improving memory layer for Large Language Models (LLMs), enabling developers to create personalized AI experiences that evolve with each user interaction.At a high level, Mem0 Platform offers comprehensive memory management, self-improving memory capabilities, cross-platform consistency, and centralized memory control for AI applications. For more info, check out the Mem0 Platform Documentation.
🧠 Comprehensive Memory Management
Manage long-term, short-term, semantic, and episodic memories
🔄 Self-Improving Memory
Adaptive system that learns from user interactions
🌐 Cross-Platform Consistency
Unified user experience across various AI platforms
🎛️ Centralized Memory Control
Effortless storage, updating, and deletion of memories
This example demonstrates how to use Mem0 with AG2 to create a conversational AI system with memory capabilities.
import osfrom autogen import ConversableAgent, LLMConfigfrom mem0 import MemoryClient# Set up environment variablesos.environ["OPENAI_API_KEY"] = "your_openai_api_key"os.environ["MEM0_API_KEY"] = "your_mem0_api_key"# Initialize Agent and Memoryagent = ConversableAgent( "chatbot", llm_config=LLMConfig( api_type="openai", model="gpt-4", api_key=os.environ.get("OPENAI_API_KEY") ), code_execution_config=False, function_map=None, human_input_mode="NEVER",)memory = MemoryClient(api_key=os.environ.get("MEM0_API_KEY"))# Insert a conversation into memoryconversation = [ { "role": "assistant", "content": "Hi, I'm Best Buy's chatbot!\n\nThanks for being a My Best Buy TotalTM member.\n\nWhat can I help you with?" }, { "role": "user", "content": "Seeing horizontal lines on our tv. TV model: Sony - 77\" Class BRAVIA XR A80K OLED 4K UHD Smart Google TV" },]memory.add(messages=conversation, user_id="customer_service_bot")# Agent Inferencedata = "Which TV am I using?"relevant_memories = memory.search(data, user_id="customer_service_bot")flatten_relevant_memories = "\n".join([m["memory"] for m in relevant_memories])prompt = f"""Answer the user question considering the memories.Memories:{flatten_relevant_memories}\n\nQuestion: {data}"""reply = agent.generate_reply(messages=[{"content": prompt, "role": "user"}])print("Reply :", reply)# Multi Agent Conversationmanager = ConversableAgent( "manager", system_message="You are a manager who helps in resolving customer issues.", llm_config=LLMConfig( api_type="openai", model="gpt-4", temperature=0, api_key=os.environ.get("OPENAI_API_KEY") ), human_input_mode="NEVER")customer_bot = ConversableAgent( "customer_bot", system_message="You are a customer service bot who gathers information on issues customers are facing.", llm_config=LLMConfig( api_type="openai", model="gpt-4", temperature=0, api_key=os.environ.get("OPENAI_API_KEY") ), human_input_mode="NEVER")data = "What appointment is booked?"relevant_memories = memory.search(data, user_id="customer_service_bot")flatten_relevant_memories = "\n".join([m["memory"] for m in relevant_memories])prompt = f"""Context:{flatten_relevant_memories}\n\nQuestion: {data}"""result = manager.send(prompt, customer_bot, request_reply=True)
Access the complete code from this notebook: Mem0 with AG2This example showcases:
Setting up AG2 agents and Mem0 memory
Adding a conversation to Mem0 memory
Using Mem0 to retrieve relevant memories for agent inference
Implementing a multi-agent conversation with memory-augmented context