fix(python-sdks): handle pydantic search results in memory dedup helpers - #1438
Open
vivekvar-dl wants to merge 1 commit into
Open
fix(python-sdks): handle pydantic search results in memory dedup helpers#1438vivekvar-dl wants to merge 1 commit into
vivekvar-dl wants to merge 1 commit into
Conversation
The pipecat, cartesia, and agent-framework packages passed search results into dedup/format helpers written for plain dicts, but typed SDK results are pydantic models (snake_case attributes, no dict interface). pipecat and cartesia crashed with AttributeError — swallowed upstream, so no memories were ever injected for users with search results — while agent-framework silently dropped every search-result memory. Extract memory fields through a tolerant accessor that accepts both the camelCase dicts returned by the profile endpoint and SDK result models, so the helpers work regardless of installed SDK version. The pipecat/cartesia dependency stubs move from test_empty_profile.py into a shared tests/conftest.py so the new utils tests can reuse them. Fixes supermemoryai#1266
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.
Fixes #1266
Problem
The three SDK-based Python packages pass search results into dedup/format helpers written for plain dicts, but typed SDK results are pydantic models — attribute access, snake_case fields, no
.get():deduplicate_memories'sunique_searchcallsr.get("memory", "")→AttributeErroron a model. The exception is swallowed upstream (generic frame/event handlers), so no memories are injected for any user whose lookup returns search results — it only appears to work for brand-new users.extract_memory_texthandles onlydictandstr, so model items fall through toNoneand every search-result memory is silently dropped.A version wrinkle makes this worse: on current
supermemory(3.56.0) the profile endpoint typessearch_results.resultsasList[object], so items arrive as camelCase dicts — while typed models (e.g.search_memories_response.Result) expose snake_case attributes. The packages pinsupermemory>=3.16.0, so both shapes occur in the wild and the helpers must accept both.Fix
Implements the shared field-extraction approach described in the issue:
utils.py(kept byte-identical, matching the existing duplication between the two packages): a private_get_result_field(result, *keys)reads a field from either shape — dict lookup with camelCase/snake_case keys, or attribute access. Used inunique_searchandformat_memories_to_text. Plain-string items and camelCase dicts behave exactly as before;updated_at/updatedAtboth resolve for the timestamp.utils.py:extract_memory_textgains an attribute-access fallback for non-dict, non-str items. Dict/str/None behavior is unchanged.Tests
tests/test_utils.pyin pipecat and cartesia (unittest style, matching the existing suite): model items survive dedup, dedup against profile strings, camelCase dicts unchanged, timestamp formatting for both shapes, plain strings verbatim. The dependency stubs moved fromtest_empty_profile.pyinto a sharedtests/conftest.pyso both test modules reuse them.TestDeduplicateMemories(pytest style): model items extracted, deduped against static, empty/None memory filtered.All three suites pass locally (Python 3.12): pipecat 9/9, cartesia 9/9, agent-framework 57/57 (with
agent-framework-core==1.0.0rc3— the current stable releases break the package's import, tracked separately per the issue's closing note).Also verified the issue's exact reproduction against the real SDK (
supermemory3.56.0):search_memories_response.Resultnow dedups and formats correctly in all three packages, and camelCase dict inputs are unchanged.