Skip to content

fix(python-sdks): handle pydantic search results in memory dedup helpers - #1438

Open
vivekvar-dl wants to merge 1 commit into
supermemoryai:mainfrom
vivekvar-dl:fix/python-sdk-pydantic-search-results
Open

fix(python-sdks): handle pydantic search results in memory dedup helpers#1438
vivekvar-dl wants to merge 1 commit into
supermemoryai:mainfrom
vivekvar-dl:fix/python-sdk-pydantic-search-results

Conversation

@vivekvar-dl

Copy link
Copy Markdown

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():

  • pipecat / cartesia: deduplicate_memories's unique_search calls r.get("memory", "")AttributeError on 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.
  • agent-framework: extract_memory_text handles only dict and str, so model items fall through to None and every search-result memory is silently dropped.

A version wrinkle makes this worse: on current supermemory (3.56.0) the profile endpoint types search_results.results as List[object], so items arrive as camelCase dicts — while typed models (e.g. search_memories_response.Result) expose snake_case attributes. The packages pin supermemory>=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:

  • pipecat + cartesia 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 in unique_search and format_memories_to_text. Plain-string items and camelCase dicts behave exactly as before; updated_at/updatedAt both resolve for the timestamp.
  • agent-framework utils.py: extract_memory_text gains an attribute-access fallback for non-dict, non-str items. Dict/str/None behavior is unchanged.

Tests

  • New tests/test_utils.py in 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 from test_empty_profile.py into a shared tests/conftest.py so both test modules reuse them.
  • Three new cases in agent-framework's existing 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 (supermemory 3.56.0): search_memories_response.Result now dedups and formats correctly in all three packages, and camelCase dict inputs are unchanged.

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
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.

Python SDK packages crash or silently drop memories: dedup helpers treat pydantic search results as dicts (pipecat, cartesia, agent-framework)

1 participant