WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@KarthikeyaKollu
Copy link
Contributor

fixes #215 This commit fixes two critical issues that prevented memory injection from working with the Google GenAI SDK:

  1. _extract_user_query now handles Google GenAI's 'contents' parameter:

    • Supports string contents (simple query)
    • Supports list of strings
    • Supports structured contents format with parts/role
  2. inject_recalled_facts now properly injects context for Google GenAI:

    • If config.system_instruction is available, appends context there
    • Otherwise, prepends context to the first user message's content
    • If first message is not a user role, inserts a new context message
    • Properly normalizes contents format (string/list/structured)
    • Ensures kwargs['contents'] is properly updated

Also fixed a minor bug where kwargs['messages'] wasn't being assigned back in the else branch for non-Anthropic/Bedrock providers.

Includes comprehensive tests for all Google GenAI scenarios:

  • String contents
  • List of strings
  • Structured contents with parts/role
  • system_instruction config
  • Edge case: first message not user role

KarthikeyaKollu and others added 2 commits December 7, 2025 16:08
…#215)

This commit fixes two critical issues that prevented memory injection
from working with the Google GenAI SDK:

1. _extract_user_query now handles Google GenAI's 'contents' parameter:
   - Supports string contents (simple query)
   - Supports list of strings
   - Supports structured contents format with parts/role

2. inject_recalled_facts now properly injects context for Google GenAI:
   - If config.system_instruction is available, appends context there
   - Otherwise, prepends context to the first user message's content
   - If first message is not a user role, inserts a new context message
   - Properly normalizes contents format (string/list/structured)
   - Ensures kwargs['contents'] is properly updated

Also fixed a minor bug where kwargs['messages'] wasn't being assigned back
in the else branch for non-Anthropic/Bedrock providers.

Includes comprehensive tests for all Google GenAI scenarios:
- String contents
- List of strings
- Structured contents with parts/role
- system_instruction config
- Edge case: first message not user role
@devwdave
Copy link
Collaborator

@KarthikeyaKollu
Thank you for this contribution. We are merging this in and will include this in the 3.1.1 release scheduled for tomorrow.

@devwdave devwdave merged commit 549af2d into MemoriLabs:main Dec 11, 2025
6 checks passed
harshalmore31 added a commit to harshalmore31/memori that referenced this pull request Dec 12, 2025
fix: automatic memory injection for Google GenAI provider (MemoriLabs#215) (MemoriLabs#221)
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.

[Bug] Automatic memory injection fails for Google GenAI provider (contents vs messages mismatch)

2 participants