Repository navigation
Migrate to the Google GenAI SDK - #1260
Conversation
📝 WalkthroughWalkthroughMigrates the Gemini agent from the deprecated Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
llm_agents/gemini_agent/src/gemini_agent.ts (1)
164-203: Streaming path loses earlier chunks due to incremental delta behavior.
The@google/genaiSDK'ssendMessageStreamyields incremental deltas (each chunk contains only newly generated text since the previous chunk), not cumulative responses. The current code overwritesfinalResponseon each iteration, keeping only the final chunk and losing all earlier content. This results in incomplete text and tool calls in the final conversion.Accumulate text/function calls across chunks before converting, or verify if the SDK provides a final aggregated response object accessible after streaming completes.
🛠️ Potential fix (adjust to match actual SDK API)
const result = await chat.sendMessageStream({ message: lastMessage.content }); let finalResponse: GenerateContentResponse | undefined; + let fullText = ""; for await (const chunk of result) { llmMetaDataFirstTokenTime(llmMetaData); - const chunkText = chunk.text; + const chunkText = chunk.text ?? ""; + fullText += chunkText; // TODO: Fix to handle all the function calls finalResponse = chunk;
🤖 Fix all issues with AI agents
In `@llm_agents/gemini_agent/package.json`:
- Line 30: Package.json lists an invalid `@google/genai` version (^1.37.0); update
the dependency entry for "@google/genai" to "^1.34.0", run package manager to
regenerate the lockfile (npm/yarn/pnpm install) and commit the updated lockfile,
and verify the package.json "engines" field permits Node.js 20+ so `@google/genai`
can install and run correctly.
♻️ Duplicate comments (1)
llm_agents/gemini_agent/lib/gemini_agent.js (1)
119-155: Duplicate: streaming final-response aggregation issue.
Same concern as inllm_agents/gemini_agent/src/gemini_agent.ts; fix in source and recompile this file.
| "homepage": "https://github.com/receptron/graphai/blob/main/llm_agents/gemini_agent/README.md", | ||
| "dependencies": { | ||
| "@google/generative-ai": "^0.24.1", | ||
| "@google/genai": "^1.37.0", |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
@google/genai npm latest version Node.js requirements
💡 Result:
As of January 17, 2026:
- Latest
@google/genainpm version: 1.34.0. [1] - Node.js requirement: Node.js 20 or later. [2]
References:
[1] Package info (registry/analysis): @google/genai — latest 1.34.0.
[2] Google Gen AI JS SDK docs — Prerequisites: Node.js version 20 or later.
🏁 Script executed:
# Find package.json files and check Node.js engine requirements
find . -name "package.json" -type f | head -20 | xargs grep -l "engines" 2>/dev/null
# Check the main gemini_agent package.json for engines field
cat llm_agents/gemini_agent/package.json | jq '.engines' 2>/dev/null || grep -A 2 '"engines"' llm_agents/gemini_agent/package.json
# Check for lockfiles
ls -la llm_agents/gemini_agent/package-lock.json llm_agents/gemini_agent/yarn.lock 2>/dev/null || echo "No lockfiles found in gemini_agent"Repository: receptron/graphai
Length of output: 178
Version 1.37.0 does not exist—update to latest @google/genai 1.34.0.
The specified version ^1.37.0 is invalid; the latest available release is 1.34.0. Update the dependency to ^1.34.0 and ensure the lockfile is regenerated. Also verify that your Node.js engine constraint supports Node.js 20 or later, as required by @google/genai.
🤖 Prompt for AI Agents
In `@llm_agents/gemini_agent/package.json` at line 30, Package.json lists an
invalid `@google/genai` version (^1.37.0); update the dependency entry for
"@google/genai" to "^1.34.0", run package manager to regenerate the lockfile
(npm/yarn/pnpm install) and commit the updated lockfile, and verify the
package.json "engines" field permits Node.js 20+ so `@google/genai` can install
and run correctly.
There was a problem hiding this comment.
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
`@google/genai` npm latest version January 2026
💡 Result:
The latest @google/genai npm version (as of January 17, 2026) is 1.34.0. [1][2]
Sources:
- Package listing (Socket):
@google/genai— 1.34.0 (latest). [1] - Official Google Gen AI SDK docs / install instructions. [2]
@masap, you're absolutely right—I apologize for the incorrect review comment. Version 1.37.0 is indeed available and was just released. My search results were outdated and didn't reflect the latest npm registry data. Thank you for the correction and for providing the link!
The dependency version ^1.37.0 is correct as specified in the PR.
🐰💭
/)_/)
(o.o)
/>📦 learns to check npm directly!
|
@masap There are merge conflicts in yarn.lock that need to be resolved before we can merge. Could you please resolve them? |
Resolves receptron#1259. According to official document [1], Google recommend us to migrate to new SDK. [1] https://ai.google.dev/gemini-api/docs/migrate Signed-off-by: Masashi Honma <[email protected]>
Sure, fixed. |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
llm_agents/gemini_agent/src/gemini_agent.ts (2)
164-204: Use GenAI's aggregated final response instead of the last streaming chunk.The
sendMessageStreamAPI returns both a stream of chunks and aresponsePromise that resolves to the final aggregated GenerateContentResponse. The current implementation discards this aggregated response and instead uses the last chunk, which may not be complete or correctly formatted forconvertOpenAIChatCompletion. Awaitresult.responseand pass that toconvertOpenAIChatCompletionrather than the last chunk.
112-154: Fix tools structure and add missing toolConfig for function-calling.The code wraps tools in
{ functionDeclarations: ... }, but the@google/genaiSDK expectstoolsto be a direct array of FunctionDeclaration objects. Additionally, atoolConfigwithfunctionCallingConfig(mode, allowedFunctionNames) must be passed to ai.chats.create() for function-calling to work. Update:const chat = ai.chats.create({ model: model || "gemini-2.5-flash", config: generationConfig, tools: functions, // Direct array, not wrapped toolConfig: { functionCallingConfig: { mode: FunctionCallingConfigMode.AUTO, // or other mode }, }, history: messagesCopy.map(...) });The response_format structure (responseMimeType + responseSchema) is valid and correctly positioned in generationConfig; consider uncommenting and implementing it to allow JSON schema validation.
🧹 Nitpick comments (2)
llm_agents/gemini_agent/lib/gemini_agent.js (2)
119-155: Use aggregated response fromresult.responseinstead of last stream chunk.
The@google/genaiSDK exposesresult.responseas an aggregated final response promise. Prefer passing this toconvertOpenAIChatCompletion()instead of the last chunk from the stream iteration. Additionally, the TODO flags incomplete function-call handling—ensure the aggregated response captures all tool calls.
70-110: Generation config and tools structure are correct; track the response_format TODO.The
generationConfigfield names (temperature, maxOutputTokens, safetySettings) and thetools: [{ functionDeclarations }]structure match the official Google Generative AI JavaScript SDK specifications.The response_format TODO is still valid—
responseMimeTypeandresponseSchemaare supported GenerationConfig fields. If implementing structured output, note that the commented code referencesmodelParams.generationConfig, which should be justgenerationConfigas shown in the rest of the code.
|
@masap Thanks for the quick fix! |
Resolves #1259.
According to official document [1], Google recommend us to migrate to new SDK.
[1] https://ai.google.dev/gemini-api/docs/migrate
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.