fix(python-sdks): stop mishandling SDK model objects in memory dedup and formatting#1268
Open
abhay-codes07 wants to merge 1 commit into
Open
Conversation
…format The pipecat, cartesia, and agent-framework packages all pass search results from the Supermemory SDK (pydantic models, attribute access, snake_case fields) into dedup/format helpers written for plain dicts. The consequences differed by package but all killed the feature's primary path: - pipecat: deduplicate_memories called r.get() on a Result model -> AttributeError -> the outer handler logs "Error processing frame" and forwards the frame unchanged, so memories are never injected for any user whose profile lookup returns search results - cartesia: identical crash, swallowed by _enrich_event_with_memories' generic except -> memory_context silently comes back empty and the previous memory block is stripped from the system prompt - agent-framework: extract_memory_text only handled dict/str, so model objects fell through to `return None` and every search-result memory was silently dropped from the injected context (The OpenAI package shares the same helper shape but works because it fetches profile data over raw aiohttp and receives dicts — that asymmetry is what hid this.) pipecat/cartesia gain an extract_search_result_fields helper that reads memory/updatedAt off dicts (camelCase keys) or SDK models (snake_case attributes, datetime-tolerant), used by both deduplicate_memories and format_memories_to_text; the formatter also no longer prints raw object reprs for non-dict items. agent-framework's extract_memory_text gains a model-object branch. Verified against the real SDK: built a supermemory.types.search_memories_response.Result from an API-shaped payload and ran it through dedup -> extract -> format (crashed with AttributeError before, renders "- [1 Jan] User prefers async" after). Test suites: pipecat 7 passed, cartesia 7 passed, agent-framework 56 passed (agent-framework-core pinned to 1.0.0rc3 — newer releases have dropped BaseContextProvider, which breaks the package import independently of this change).
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
What
The pipecat, cartesia, and agent-framework packages all feed search results from the
supermemorySDK — pydantic models with attribute access and snake_case fields — into dedup/format helpers written for plain dicts. The failure mode differs per package, but in each one the core feature is broken on its primary path:deduplicate_memoriescallsr.get("memory", "")on aResultmodel →AttributeError→ caught by the generic frame handler, frame forwarded unchanged. Memories are never injected for any user whose profile lookup returns search results; it only "works" for brand-new users with empty results.memory_contextsilently comes backNoneand the process method then strips the previous memory block from the system prompt. Persistent recall is dead for users with stored memories.extract_memory_texthandles onlydict/str, so model objects fall through toreturn Noneand every search-result memory is silently dropped (no crash, just data loss).The OpenAI package shares the same helper shape but works, because it fetches profile data over raw
aiohttpand receives dicts — that asymmetry is what hid this.Fix
extract_search_result_fieldshelper readsmemory/updatedAtoff dicts (camelCase keys) or SDK models (snake_case attributes, tolerant ofdatetimevalues), and bothdeduplicate_memoriesandformat_memories_to_textgo through it. The formatter also stops printing raw object reprs for non-dict, non-str items.extract_memory_textgains a model-object branch (getattr(item, "memory", None)), keeping the existing trim/empty filtering.Dict-shaped inputs behave exactly as before in all three packages.
Testing
supermemory.types.search_memories_response.Resultfrom an API-shaped payload and ran it through dedup → extract → format. Before:AttributeError: 'Result' object has no attribute 'get'. After: renders- [1 Jan] User prefers async.tests/test_search_result_objects.pyin pipecat and cartesia (dedup without crashing, priority vs profile entries, no-repr formatting, dict compatibility, datetimeupdated_at, missing fields), plus two model-object cases in agent-framework'stests/test_utils.py.agent-framework-core==1.0.0rc3— as noted in Python SDK packages crash or silently drop memories: dedup helpers treat pydantic search results as dicts (pipecat, cartesia, agent-framework) #1266, newer releases droppedBaseContextProviderand break the package import independently of this change).cc @MaheshtheDev