Python: fix(mem0): isolate entity retrieval and correct app_id payload#6242
Python: fix(mem0): isolate entity retrieval and correct app_id payload#6242VedantSonani wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR updates the Mem0 context provider to retrieve memories by querying entity “partitions” (user/agent) independently and merging results, avoiding strict AND-filter limitations, and aligns application ID usage with an app_id parameter.
Changes:
- Run parallel Mem0 searches for
user_idandagent_id, then merge/deduplicate results before injecting into the session context. - Refactor filter construction into a per-entity search-kwargs builder that supports OSS vs Platform client differences.
- Update memory creation call to pass
app_idinstead ofmetadata.application_id.
|
@microsoft-github-policy-service agree |
moonbox3
left a comment
There was a problem hiding this comment.
Please also have a look at the failing CI/CD items.
|
@moonbox3 Thanks for the feedback, I have pushed the updates addressing all the review feedback, including the app-only fallback, safe deduplication for ID-less memories, exception logging, and aligning the Pyright/unit test suite with the new architecture. |
Thank you. Please resolve any previous convo on this PR - either with a "fixed" or "defer" statement, as needed. |
|
Please check the failing unit tests, too: https://github.com/microsoft/agent-framework/actions/runs/26799745190/job/79003919904?pr=6242#step:5:125 |
|
Hey @moonbox3, I’ve refactored the module to resolve all the strict type safety constraints while keeping the dynamic partition matching intact.
|
|
Please check the failing CI/CD items. |
|
Hey @moonbox3,
The new CI pipeline run should be clean now. Let me know if it looks good on your end! |
e673d78 to
8f26d45
Compare
8f26d45 to
2926908
Compare
|
Hey @moonbox3,
Quick question on the Windows CI runner: |
|
FAILED: pyright in packages/mem0 |
|
@moonbox3 My bad! I had a Mypy-style |
Motivation and Context
This change is required because the current
Mem0ContextProviderfails to retrieve any stored memories during thebefore_runphase. It solves two critical bugs in how the provider interacts with the Mem0 API:metadatadictionary but searching for it using Mem0's native top-levelapp_idparameter, resulting in instant filtering failures.user_1ORagent_1). By passing bothuser_idandagent_idin a single bundled filters dictionary, the provider forced a strict logical AND intersection (user == X AND agent == Y). Since no single memory row contains both tags, the database always returned zero results.Fixes #6237
Description
Changes Implemented:
after_run(Ingestion Fix): Modified themem0_client.addpayload to passself.application_idto the nativeapp_idparameter instead of trapping it inside themetadatadictionary. This aligns the insertion schema with the retrieval schema.before_run(Retrieval Fix): Completely removed the bundled_build_filterslogic. Replaced it with a concurrent architecture usingasyncio.gatherto query the User partition and the Agent partition independently.id.build_search_kwargshelper function insidebefore_run. This safely generates the query dictionaries without shallow-copy side effects, and cleanly handles the differing payload requirements betweenAsyncMemory(OSS) andAsyncMemoryClient(Platform).Contribution Checklist