Skip to content

Commit e635a9d

Browse files
cmd-errswaroopvarma1
authored andcommitted
feat: integrate mem0 in pipecat pipeline
- Extend Mem0MemoryService to ImprovedMem0MemoryService class - Add non-blocking async message storage to prevent pipeline delays - Add incremental message tracking to reduce redundant API calls - Extract configuration constants and helper methods for maintainability - Improve user identification with email → name → session_id fallback - Add comprehensive error handling without breaking conversation flow
1 parent 4b79dd1 commit e635a9d

6 files changed

Lines changed: 486 additions & 5 deletions

File tree

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,7 @@ LANGFUSE_PUBLIC_KEY=''
108108
LANGFUSE_BASEURL=https://us.cloud.langfuse.com
109109
AUTOMATIC_LANGFUSE_PROMPT_NAME=AUTOMATIC_VOICE_LANGFUSE_PROMPT
110110
AUTOMATIC_LANGFUSE_SYSTEM_PROMPT_LABEL=automatic_system_langfuse_prompt
111+
112+
# Mem0 Configuration
113+
MEM0_API_KEY=""
114+
MEM0_ENABLED=false

app/agents/voice/automatic/__init__.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from pipecat.transports.services.daily import DailyParams, DailyTransport
2121
from pipecat.processors.frameworks.rtvi import RTVIConfig, RTVIProcessor
2222
from pipecat.services.google.rtvi import GoogleRTVIObserver
23+
from app.services.mem0.memory import ImprovedMem0MemoryService
2324

2425
from app.core import config
2526
from app.agents.voice.automatic.utils.session_context import create_session_context, set_current_session_id
@@ -263,10 +264,23 @@ async def on_function_calls_started(service, function_calls):
263264
ptt_vad_filter = PTTVADFilter("PTTVADFilter")
264265
pipeline_components.append(ptt_vad_filter) # Filter VAD frames after STT
265266

266-
# Add remaining components
267267
pipeline_components.extend([
268268
rtvi,
269-
context_aggregator.user(),
269+
context_aggregator.user()
270+
])
271+
272+
if config.MEM0_ENABLED:
273+
logger.info("Initializing Mem0 memory service")
274+
memory_params = ImprovedMem0MemoryService.InputParams()
275+
memory = ImprovedMem0MemoryService(
276+
api_key=config.MEM0_API_KEY,
277+
user_id=args.user_email or args.user_name or args.session_id, # Fallback: email → name → session_id
278+
params= memory_params,
279+
)
280+
pipeline_components.append(memory)
281+
282+
# Add remaining components
283+
pipeline_components.extend([
270284
llm,
271285
tool_call_processor,
272286
tts,

app/core/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ def get_required_env(var_name: str) -> str:
6666
VAD_START_SECS = float(os.environ.get("VAD_START_SECS", 0.30))
6767
VAD_STOP_SECS = float(os.environ.get("VAD_STOP_SECS", 1.00))
6868

69+
# Mem0 Configuration
70+
MEM0_API_KEY = os.getenv("MEM0_API_KEY", "")
71+
MEM0_ENABLED = os.getenv("MEM0_ENABLED", "false").lower() == "true"
72+
MEM0_MAX_FAILURES = int(os.getenv("MEM0_MAX_FAILURES", "3"))
73+
MEM0_RETRY_INTERVAL = int(os.getenv("MEM0_RETRY_INTERVAL", "300"))
74+
MEM0_SESSION_TIMEOUT = int(os.getenv("MEM0_SESSION_TIMEOUT", "3600"))
75+
MEM0_MIN_MESSAGE_LENGTH = int(os.getenv("MEM0_MIN_MESSAGE_LENGTH", "10"))
76+
6977
# Tracing
7078
ENABLE_TRACING = os.environ.get("ENABLE_TRACING", "false").lower() == "true"
7179
OPEN_OBSERVE_BASE_URL = os.environ.get("OPEN_OBSERVE_BASE_URL", "https://periscope.breeze.in")

app/services/mem0/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
Improved Mem0 integration for Pipecat with non-blocking storage.
3+
"""
4+
5+
from .memory import ImprovedMem0MemoryService
6+
7+
__all__ = ["ImprovedMem0MemoryService"]

0 commit comments

Comments
 (0)