fix: agent-framework drops profile search memories - #1616
Open
noQbot wants to merge 1 commit into
Open
Conversation
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>
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.
What & why
In the Agent Framework integration,
middleware.pyandcontext_provider.pyboth passlist(response.search_results.results)intodeduplicate_memories(), which routes each item throughextract_memory_text():But the Supermemory SDK returns
response.search_results.resultsas Pydantic model objects, not dicts or strings. A model matches neither branch, soextract_memory_textreturnsNoneand the memory is silently dropped — inquery/fullmode, 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 siblingopenai-sdk-pythonpackage alreadymodel_dump()s the same results, confirming the model shape.)The fix
Add a model branch to
extract_memory_text— read"memory"frommodel_dump(by_alias=True), falling back to attribute access — while leaving the existingdictandstrhandling untouched:Tests
Added
tests/test_search_result_models.pyfeeding dict-less model stand-ins through the dedup path — asserts models are extracted and deduped, the attribute fallback works for models withoutmodel_dump, and dict inputs still work.Compatibility
Backward compatible — dict and str inputs behave exactly as before. No API or behavior change for callers already passing dicts.