Skip to content

fix: forward tools parameter to Gemini API in GoogleLLM (#4380)#4386

Merged
whysosaket merged 1 commit intomem0ai:mainfrom
DhilipBinny:fix/google-llm-tools-support
Mar 18, 2026
Merged

fix: forward tools parameter to Gemini API in GoogleLLM (#4380)#4386
whysosaket merged 1 commit intomem0ai:mainfrom
DhilipBinny:fix/google-llm-tools-support

Conversation

@DhilipBinny
Copy link
Copy Markdown
Contributor

Description

GoogleLLM.generateResponse() received the tools parameter but never passed it to the Gemini API. This caused graph memory operations to silently fail — zero entities
extracted, Neo4j stays empty, no error thrown. Users think everything is working because vector store writes succeed.

Root cause

The generateContent call in google.ts ignored the tools parameter entirely. When Gemini doesn't receive function declarations, it returns plain text instead of function call
responses, so toolCalls is always undefined.

Fix

  • Convert OpenAI-style tools ({type: "function", function: {name, description, parameters}}) to Gemini's functionDeclarations format
  • Pass them via config.tools to generateContent
  • Parse completion.functionCalls into the standard toolCalls response format ({name, arguments})
  • Consistent with how OpenAI, Ollama, Azure, Mistral, and Langchain LLMs handle tools in this codebase

Changes

  • mem0-ts/src/oss/src/llms/google.ts — tool conversion + response parsing
  • mem0-ts/src/oss/tests/google-llm.test.ts — 5 new tests

Fixes #4380

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit Test

5 tests covering:

  • Text response without tools (backward compat)
  • Tools forwarded as functionDeclarations to Gemini
  • Text fallback when tools provided but model returns text
  • Markdown code fence stripping preserved
  • Multiple function calls in single response

Run with: cd mem0-ts && npx jest src/oss/tests/google-llm.test.ts

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

Maintainer Checklist

GoogleLLM.generateResponse() received the tools parameter but never
passed it to the Gemini API, causing graph memory operations to
silently fail — zero entities extracted, no error thrown. Convert
OpenAI-style tools to Gemini functionDeclarations format and parse
functionCall responses into the standard toolCalls format.

Fixes mem0ai#4380
Copy link
Copy Markdown
Contributor

@kartik-mem0 kartik-mem0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for your contribution @DhilipBinny

the pr lgtm!

@whysosaket whysosaket merged commit 4ffe1ea into mem0ai:main Mar 18, 2026
4 of 5 checks passed
jamebobob pushed a commit to jamebobob/mem0-vigil-recall that referenced this pull request Mar 29, 2026
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.

GoogleLLM.generateResponse ignores tools parameter — graph memory silently produces no entities with Google/Gemini provider

3 participants