fix(mem0): improve Mem0 service reliability and add get_memories() method#4156
Merged
markbackman merged 5 commits intomainfrom Mar 26, 2026
Merged
fix(mem0): improve Mem0 service reliability and add get_memories() method#4156markbackman merged 5 commits intomainfrom
markbackman merged 5 commits intomainfrom
Conversation
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 Report❌ Patch coverage is
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
kompfner
approved these changes
Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mem0MemoryServiceblocking the event loop — all Mem0 API calls (add,search,get_all) now run in background threads viaasyncio.to_thread(), and message storage is fire-and-forget viacreate_task()Mem0MemoryService.get_memories()convenience method for retrieving all stored memories outside the pipeline (e.g. for personalized greetings at connection time)positionin the context instead of always being appendedmem0aidependency from~=0.1.94to>=1.0.8,<237-mem0.pyexample to useget_memories()and simplified the greeting logicBreaking Changes
mem0aidependency updated from~=0.1.94to>=1.0.8,<2. Users of themem0extra will need to update their mem0ai package.Testing
uv run ruff check src/pipecat/services/mem0/memory.py examples/foundational/37-mem0.pyexamples/foundational/37-mem0.pyand verify personalized greeting includes memory contentFixes #1741