Mem0 provides a smart memory layer for AI applications, enabling personalized interactions by remembering user preferences, conversation history, and context across sessions.

Why Track Mem0 with AgentOps?

When building memory-powered AI applications, you need visibility into:

  • Memory Operations: Track when memories are created, updated, or retrieved
  • Search Performance: Monitor how effectively your AI finds relevant memories
  • Memory Usage Patterns: Understand what information is being stored and accessed
  • Error Tracking: Identify issues with memory storage or retrieval
  • Cost Analysis: Track API calls to both Mem0 and your LLM provider

AgentOps automatically instruments Mem0 to provide complete observability of your memory operations.

Installation

pip install agentops mem0ai python-dotenv

Environment Configuration

Load environment variables and set up API keys. The MEM0_API_KEY is only required if you’re using the cloud-based MemoryClient.

export AGENTOPS_API_KEY="your_agentops_api_key_here"
export OPENAI_API_KEY="your_openai_api_key_here"

Tracking Memory Operations

import agentops
from mem0 import Memory

# Start a trace to group related operations
agentops.start_trace("user_preference_learning",tags=["mem0_memory_example"])

try:
    # Initialize Memory - AgentOps tracks the configuration
    memory = Memory.from_config({
        "llm": {
            "provider": "openai",
            "config": {
                "model": "gpt-4o-mini",
                "temperature": 0.1
            }
        }
    })

    # Add memories - AgentOps tracks each operation
    memory.add(
        "I prefer morning meetings and dark roast coffee",
        user_id="user_123",
        metadata={"category": "preferences"}
    )

    # Search memories - AgentOps tracks search queries and results
    results = memory.search(
        "What are the user's meeting preferences?",
        user_id="user_123"
    )

    # End trace - AgentOps aggregates all operations
    agentops.end_trace(end_state="success")
    
except Exception as e:
    agentops.end_trace(end_state="error")

What You’ll See in AgentOps

When using Mem0 with AgentOps, your dashboard will show:

  1. Memory Operation Timeline: Visual flow of all memory operations
  2. Search Analytics: Query patterns and retrieval effectiveness
  3. Memory Growth: Track how user memories accumulate over time
  4. Performance Metrics: Latency for adds, searches, and retrievals
  5. Error Tracking: Failed operations with full error context
  6. Cost Attribution: Token usage for memory extraction and searches

Examples