Skip to content

fix(mem0): improve Mem0 service reliability and add get_memories() method#4156

Merged
markbackman merged 5 commits intomainfrom
mb/mem0-improvements
Mar 26, 2026
Merged

fix(mem0): improve Mem0 service reliability and add get_memories() method#4156
markbackman merged 5 commits intomainfrom
mb/mem0-improvements

Conversation

@markbackman
Copy link
Copy Markdown
Contributor

@markbackman markbackman commented Mar 26, 2026

Summary

  • Fixed Mem0MemoryService blocking the event loop — all Mem0 API calls (add, search, get_all) now run in background threads via asyncio.to_thread(), and message storage is fire-and-forget via create_task()
  • Fixed memory storage failing with 400 errors when context contained system/developer role messages — these are now filtered to only user/assistant roles before calling the Mem0 API
  • Added Mem0MemoryService.get_memories() convenience method for retrieving all stored memories outside the pipeline (e.g. for personalized greetings at connection time)
  • Memory messages are now inserted at the configured position in the context instead of always being appended
  • Bumped mem0ai dependency from ~=0.1.94 to >=1.0.8,<2
  • Updated the 37-mem0.py example to use get_memories() and simplified the greeting logic

Breaking Changes

  • mem0ai dependency updated from ~=0.1.94 to >=1.0.8,<2. Users of the mem0 extra will need to update their mem0ai package.

Testing

  • uv run ruff check src/pipecat/services/mem0/memory.py examples/foundational/37-mem0.py
  • Manual: run examples/foundational/37-mem0.py and verify personalized greeting includes memory content

Fixes #1741

Move blocking Mem0 API calls off the event loop using asyncio.to_thread().
Store messages as a fire-and-forget background task via create_task() since
the result is not needed. Insert memory messages at the configured position
in the context instead of always appending.

Closes #1741
Mem0 API only accepts user and assistant roles. Filter out system,
developer, and other roles before calling add() to avoid 400 errors.
Expose a public method for retrieving all stored memories outside the
pipeline, avoiding the need for callers to reimplement client branching,
OR filter construction, and asyncio.to_thread wrapping. Simplify the
example get_initial_greeting() to use it.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

❌ Patch coverage is 3.12500% with 31 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pipecat/services/mem0/memory.py 3.12% 31 Missing ⚠️
Files with missing lines Coverage Δ
src/pipecat/services/mem0/memory.py 10.76% <3.12%> (-1.05%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@filipi87 filipi87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. 👍

@markbackman markbackman merged commit 7eec03c into main Mar 26, 2026
10 checks passed
@markbackman markbackman deleted the mb/mem0-improvements branch March 26, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mem0 self._store_messages blocks the conversation flow

3 participants