Skip to content

fix(openai-sdk-python): don't fail get_profile for users with no memories - #1759

Open
Atharvsinh-codez wants to merge 1 commit into
supermemoryai:mainfrom
Atharvsinh-codez:fix/openai-python-null-profile
Open

Atharvsinh-codez wants to merge 1 commit into
supermemoryai:mainfrom
Atharvsinh-codez:fix/openai-python-null-profile

Conversation

@Atharvsinh-codez

Copy link
Copy Markdown

What was wrong

For a user who has no stored memories yet, the API returns a null profile (this is the same case as #1027, which was fixed for the pipecat package). SupermemoryTools.get_profile passed that straight to _model_to_dict, which raises TypeError for None. The broad except then turned it into a failed tool call:

{'success': False, 'error': 'Profile fetch failed: Unsupported SDK response type: NoneType'}

So the model sees a failing getProfile call for every new user, instead of an empty profile.

Repro

tools = SupermemoryTools("key", {"container_tags": ["new-user"]})
tools.client.profile = AsyncMock(return_value=SimpleNamespace(profile=None, search_results=None))
await tools.get_profile()

On main this returns the error above. With this change it returns success=True and profile={"static": [], "dynamic": []}.

The fix

When response.profile is None, return an empty profile. This matches what the cartesia and pipecat packages already do. search_results was already handled for None, so it is unchanged.

I only changed get_profile. I didn't touch document_list, since I haven't seen the API return a null pagination.

Tests

Added test_get_profile_handles_user_with_no_memories in tests/test_tools.py. It fails on main and passes with the fix. The full tests/ run gives 32 passed, 11 skipped (the skipped ones need a real API key), and black --check is clean.

…ries

The API returns a null profile for a user who has no stored memories yet
(the same case as supermemoryai#1027 for the pipecat package). get_profile passed it
straight to _model_to_dict, which raises TypeError for None, so the tool
came back as success=False with "Profile fetch failed: Unsupported SDK
response type: NoneType" for every new user.

Return an empty profile ({"static": [], "dynamic": []}) in that case,
like the cartesia and pipecat packages already do.

Added a test for the null-profile response.

This branch has not been deployed

No deployments
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