Agno - Mem0
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
This integration of Mem0 with Agno enables persistent, multimodal memory for Agno-based agents - improving personalization, context awareness, and continuity across conversations.
Overview
- Store and retrieve memories from Mem0 within Agno agents
- Support for multimodal interactions (text and images)
- Semantic search for relevant past conversations
- Personalized responses based on user history
- One-line memory integration via
Mem0Tools
Prerequisites
Before setting up Mem0 with Agno, ensure you have:
- Installed the required packages:
pip install agno mem0ai python-dotenv
- Valid API keys:
- Mem0 API Key
- OpenAI API Key (for the agent model)
Quick Integration (Using Mem0Tools)
The simplest way to integrate Mem0 with Agno Agents is to use Mem0 as a tool using built-in Mem0Tools:
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.mem0 import Mem0Tools
agent = Agent(
name="Memory Agent",
model=OpenAIChat(id="gpt-5-mini"),
tools=[Mem0Tools()],
description="An assistant that remembers and personalizes using Mem0 memory."
)
This enables memory functionality out of the box:
- Persistent memory writing:
Mem0ToolsusesMemoryClient.add(...)to store messages from user-agent interactions, including optional metadata such as user ID or session. - Contextual memory search: Compatible queries use
MemoryClient.search(...)to retrieve relevant past messages, improving contextual understanding. - Multimodal support: Both text and image inputs are supported, allowing richer memory records.
Mem0Tools uses the MemoryClient under the hood and requires no additional setup. You can customize its behavior by modifying your tools list or extending it in code.
Full Manual Example
The following example demonstrates how to create an Agno agent with Mem0 memory integration, including support for image processing:
import base64
from pathlib import Path
from typing import Optional
from agno.agent import Agent
from agno.media import Image
from agno.models.openai import OpenAIChat
from mem0 import MemoryClient
# Initialize the Mem0 client
client = MemoryClient()
# Define the agent
agent = Agent(
name="Personal Agent",
model=OpenAIChat(id="gpt-5-mini"),
description="You are a helpful personal agent that helps me with day to day activities."
"You can process both text and images.",
markdown=True
)
def chat_user(
user_input: Optional[str] = None,
user_id: str = "alex",
image_path: Optional[str] = None
) -> str:
"""Handle user input with memory integration, supporting both text and images."""
if image_path:
# Convert image to base64
with open(image_path, "rb") as image_file:
base64_image = base64.b64encode(image_file.read()).decode("utf-8")
# Create message objects for text and image
messages = []
if user_input:
messages.append({
"role": "user",
"content": user_input
})
messages.append({
"role": "user",
"content": {
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{base64_image}"
}
}
})
# Store messages in memory
client.add(messages, user_id=user_id)
print("✅ Image and text stored in memory.")
if user_input:
# Search for relevant memories
memories = client.search(user_input, filters={"user_id": user_id})
memory_context = "\n".join(f"- {m['memory']}" for m in memories['results'])
# Construct the prompt
prompt = f"""
You are a helpful personal assistant who helps users with their day-to-day activities and keeps track of everything.
Your task is to:
1. Analyze the given image (if present) and extract meaningful details to answer the user's question.
2. Use your past memory of the user to personalize your answer.
3. Combine the image content and memory to generate a helpful, context-aware response.
Here is what I remember about the user:
{memory_context}
User question:
{user_input}
"""
# Get response from agent
if image_path:
response = agent.run(prompt, images=[Image(filepath=Path(image_path))])
else:
response = agent.run(prompt)
# Store the interaction in memory
interaction_message = [{"role": "user", "content": f"User: {user_input}\nAssistant: {response.content}"}]
client.add(interaction_message, user_id=user_id)
return response.content
return "No user input or image provided."
# Example Usage
if __name__ == "__main__":
response = chat_user(
"I like to travel and my favorite destination is London",
image_path="travel_items.jpeg",
user_id="alex"
)
print(response)
Key Features
1. Multimodal Memory Storage
The integration supports storing both text and image data:
- Text Storage: Conversation history is saved in a structured format
- Image Analysis: Agents can analyze images and store visual information
- Combined Context: Memory retrieval combines both text and visual data
2. Personalized Agent Responses
Improve your agent’s context awareness:
- Memory Retrieval: Semantic search finds relevant past interactions
- User Preferences: Personalize responses based on stored user information
- Continuity: Maintain conversation threads across multiple sessions
3. Flexible Configuration
Customize the integration to your needs:
- Use
Mem0Tools()for drop-in memory support - Use
MemoryClientdirectly for advanced control - User Identification: Organize memories by user ID
- Memory Search: Configure search relevance and result count
- Memory Formatting: Support for various OpenAI message formats