Skip to content

fix: agent-framework drops profile search memories - #1616

Open
noQbot wants to merge 1 commit into
supermemoryai:mainfrom
VinvAI:fix-agent-framework-drops-search
Open

fix: agent-framework drops profile search memories#1616
noQbot wants to merge 1 commit into
supermemoryai:mainfrom
VinvAI:fix-agent-framework-drops-search

Conversation

@noQbot

@noQbot noQbot commented Aug 29, 2026

Copy link
Copy Markdown

What & why

In the Agent Framework integration, middleware.py and context_provider.py both pass list(response.search_results.results) into deduplicate_memories(), which routes each item through extract_memory_text():

def extract_memory_text(item):
    if isinstance(item, dict):
        memory = item.get("memory")
        ...
    if isinstance(item, str):
        ...
    return None   # <- SDK models land here

But the Supermemory SDK returns response.search_results.results as Pydantic model objects, not dicts or strings. A model matches neither branch, so extract_memory_text returns None and the memory is silently dropped — in query/full mode, no search memories get injected into the context. Unlike the Cartesia/Pipecat path this doesn't crash; it just quietly loses retrieved context, which is harder to notice.

Why existing tests didn't catch it: the current fixtures pass dicts ({"memory": "..."}), a shape production never sends. (The sibling openai-sdk-python package already model_dump()s the same results, confirming the model shape.)

The fix

Add a model branch to extract_memory_text — read "memory" from model_dump(by_alias=True), falling back to attribute access — while leaving the existing dict and str handling untouched:

if isinstance(item, str):
    ...
if isinstance(item, dict):
    memory = item.get("memory")
else:
    model_dump = getattr(item, "model_dump", None)
    if callable(model_dump):
        memory = model_dump(by_alias=True).get("memory")
    else:
        memory = getattr(item, "memory", None)

Tests

Added tests/test_search_result_models.py feeding dict-less model stand-ins through the dedup path — asserts models are extracted and deduped, the attribute fallback works for models without model_dump, and dict inputs still work.

Note: the repo's PR CI runs only TypeScript type-checks + Biome, not the Python suites, so these tests won't run in CI here — I verified them locally.

Compatibility

Backward compatible — dict and str inputs behave exactly as before. No API or behavior change for callers already passing dicts.

extract_memory_text() only handled dict and str, but middleware.py and
context_provider.py pass response.search_results.results into
deduplicate_memories, and the Supermemory SDK returns those as Pydantic model
objects. Models matched neither branch and returned None, so query/full mode
silently injected no search memories (no crash, just missing context).
Existing tests only passed dict fixtures, so they stayed green.

Extract "memory" from a model via model_dump(by_alias=True), falling back to
attribute access, while leaving dict and str handling unchanged. Add
regression tests feeding dict-less model stand-ins through the dedup path.

Co-Authored-By: Vinv-AI <309466812+Vinv-AI@users.noreply.github.com>
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.

1 participant