Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions python/packages/mem0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ See the [Mem0 basic example](https://github.com/microsoft/agent-framework/tree/m
- Teaching the agent user preferences
- Retrieving information using remembered context across new threads
- Persistent memory

## Telemetry

Mem0's telemetry (PostHog analytics) is **disabled by default** when using this package. If you want to enable telemetry, set the environment variable before importing:

```python
import os
os.environ["MEM0_TELEMETRY"] = "true"

from agent_framework.mem0 import Mem0Provider
```
6 changes: 6 additions & 0 deletions python/packages/mem0/agent_framework_mem0/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Copyright (c) Microsoft. All rights reserved.

import importlib.metadata
import os

# Disable Mem0 telemetry by default to prevent usage data from being sent to PostHog.
# Users can opt-in by setting MEM0_TELEMETRY=true before importing this package.
if os.environ.get("MEM0_TELEMETRY") is None:
os.environ["MEM0_TELEMETRY"] = "false"

from ._provider import Mem0Provider

Expand Down
8 changes: 7 additions & 1 deletion python/packages/mem0/agent_framework_mem0/_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ class MemorySearchResponse_v1_1(TypedDict):


class Mem0Provider(ContextProvider):
"""Mem0 Context Provider."""
"""Mem0 Context Provider.

Note:
Mem0's telemetry (PostHog analytics) is disabled by default when using this package.
To enable telemetry, set the environment variable ``MEM0_TELEMETRY=true`` before
importing this package.
"""

def __init__(
self,
Expand Down
43 changes: 43 additions & 0 deletions python/packages/mem0/tests/test_mem0_context_provider.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Copyright (c) Microsoft. All rights reserved.
# pyright: reportPrivateUsage=false

import importlib
import os
import sys
from unittest.mock import AsyncMock, patch

import pytest
Expand Down Expand Up @@ -592,3 +595,43 @@ def test_build_filters_returns_empty_dict_when_no_parameters(self, mock_mem0_cli

filters = provider._build_filters()
assert filters == {}


class TestMem0Telemetry:
"""Test telemetry configuration for Mem0."""

def test_mem0_telemetry_disabled_by_default(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""Test that MEM0_TELEMETRY is set to 'false' by default when importing the package."""
# Ensure MEM0_TELEMETRY is not set before importing the module under test
monkeypatch.delenv("MEM0_TELEMETRY", raising=False)

# Remove cached modules to force re-import and trigger module-level initialization
modules_to_remove = [key for key in sys.modules if key.startswith("agent_framework_mem0")]
for mod in modules_to_remove:
del sys.modules[mod]

# Import (and reload) the module so that it can set MEM0_TELEMETRY when unset
import agent_framework_mem0

importlib.reload(agent_framework_mem0)

# The environment variable should be set to "false" after importing
assert os.environ.get("MEM0_TELEMETRY") == "false"

def test_mem0_telemetry_respects_user_setting(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""Test that user-set MEM0_TELEMETRY value is not overwritten."""
# Remove cached modules to force re-import
modules_to_remove = [key for key in sys.modules if key.startswith("agent_framework_mem0")]
for mod in modules_to_remove:
del sys.modules[mod]

# Set user preference before import
monkeypatch.setenv("MEM0_TELEMETRY", "true")

# Re-import the module
import agent_framework_mem0

importlib.reload(agent_framework_mem0)

# User setting should be preserved
assert os.environ.get("MEM0_TELEMETRY") == "true"
Loading