Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

feat: add support for the Gemma-3 and Gemini Robotics models via the … - #10069

Closed
techstrom wants to merge 7 commits into
RooCodeInc:mainfrom
techstrom:gemma3
Closed

feat: add support for the Gemma-3 and Gemini Robotics models via the …#10069
techstrom wants to merge 7 commits into
RooCodeInc:mainfrom
techstrom:gemma3

Conversation

@techstrom

@techstrom techstrom commented Dec 13, 2025

Copy link
Copy Markdown

add support for the models: gemma-3-27b-it, gemma-3-12b-it, gemma-3-4b-it and gemini-robotics-er-1.5-preview.

Description

This PR introduces fixes for Gemma 3 model compatibility within the Gemini provider, specifically addressing API error handling and system instruction formatting.

Changes

Gemma 3 System Instruction Handling:
Implemented a check for Gemma 3 models (isGemma3).
Modified the request construction to prepend systemInstruction to the user message for Gemma 3 models, as they do not support the separate systemInstruction field.
Ensured systemInstruction is omitted from the configuration object when using Gemma 3 models to prevent API errors.
Error Handling Improvements:
Added specific error parsing for resource_exhausted (429) errors from the Gemini API.
Mapped these errors to a user-friendly message, including the limit, model name, and retry time.

Version

Validated with version: 3.36.6


Important

Adds support for Gemma 3 and Gemini Robotics models with specific handling for system instructions and improved error handling in the Gemini provider.

  • Behavior:
    • Adds support for gemma-3-27b-it, gemma-3-12b-it, gemma-3-4b-it, and gemini-robotics-er-1.5-preview models in gemini.ts.
    • For Gemma 3 models, prepends systemInstruction to user messages and omits it from the config to avoid API errors in GeminiHandler.
    • Improves error handling by parsing resource_exhausted (429) errors and mapping them to user-friendly messages in GeminiHandler.
  • Localization:
    • Adds resource_exhausted error message to common.json in both en and ja locales.

This description was created by Ellipsis for 181f829. You can customize this summary. It will automatically update as commits are pushed.

@techstrom
techstrom requested review from cte, jr and mrubens as code owners December 13, 2025 16:59
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. Enhancement New feature or request labels Dec 13, 2025
@ghost

ghost commented Dec 13, 2025

Copy link
Copy Markdown

Rooviewer Clock   See task on Roo Cloud

All issues have been resolved. The PR is ready for merge.

  • Duplicated code block in src/api/providers/gemini.ts: The Gemma 3 system instruction handling is duplicated three times (lines 165-229), causing a TypeScript compilation error due to const isGemma3 being declared multiple times
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 13, 2025
@techstrom

Copy link
Copy Markdown
Author

I’ve made the following improvements:

  • Fix TypeScript error: Resolved a TypeScript error (TS2488) in src/api/providers/gemini.ts. The code now safely handles potential undefined values when spreading firstMessage.parts for Gemma-3 models.
  • Update locales: Updated translation files for multiple languages (es, zh-CN, ko, id).

I’d appreciate it if you could review the changes again.

@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Dec 19, 2025
Comment thread src/api/providers/gemini.ts Outdated
Comment on lines +187 to +229
// Check if the model is a Gemma 3 model
const isGemma3 = model.includes("gemma-3")

// Prepend system instruction to the first user message if it's a Gemma 3 model,
// as they don't support the system instruction parameter.
if (isGemma3 && systemInstruction) {
if (contents.length > 0 && contents[0].role === "user") {
const firstMessage = contents[0]
// Create a new text part for the system instruction
const systemPart = { text: systemInstruction }
// Prepend it to the existing parts
firstMessage.parts = [systemPart, ...(firstMessage.parts || [])]
} else {
// If no messages or first message is not user (e.g. starts with model),
// prepend a new user message with the system instruction.
contents.unshift({
role: "user",
parts: [{ text: systemInstruction }],
})
}
}

// Check if the model is a Gemma 3 model
const isGemma3 = model.includes("gemma-3")

// Prepend system instruction to the first user message if it's a Gemma 3 model,
// as they don't support the system instruction parameter.
if (isGemma3 && systemInstruction) {
if (contents.length > 0 && contents[0].role === "user") {
const firstMessage = contents[0]
// Create a new text part for the system instruction
const systemPart = { text: systemInstruction }
// Prepend it to the existing parts
firstMessage.parts = [systemPart, ...(firstMessage.parts || [])]
} else {
// If no messages or first message is not user (e.g. starts with model),
// prepend a new user message with the system instruction.
contents.unshift({
role: "user",
parts: [{ text: systemInstruction }],
})
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The Gemma 3 system instruction handling code is duplicated three times (lines 165-185, 187-207, and 209-229). This will cause a TypeScript compilation error because const isGemma3 is declared three times in the same scope. Only the first block should be kept; the other two are exact duplicates that need to be removed.

Suggested change
// Check if the model is a Gemma 3 model
const isGemma3 = model.includes("gemma-3")
// Prepend system instruction to the first user message if it's a Gemma 3 model,
// as they don't support the system instruction parameter.
if (isGemma3 && systemInstruction) {
if (contents.length > 0 && contents[0].role === "user") {
const firstMessage = contents[0]
// Create a new text part for the system instruction
const systemPart = { text: systemInstruction }
// Prepend it to the existing parts
firstMessage.parts = [systemPart, ...(firstMessage.parts || [])]
} else {
// If no messages or first message is not user (e.g. starts with model),
// prepend a new user message with the system instruction.
contents.unshift({
role: "user",
parts: [{ text: systemInstruction }],
})
}
}
// Check if the model is a Gemma 3 model
const isGemma3 = model.includes("gemma-3")
// Prepend system instruction to the first user message if it's a Gemma 3 model,
// as they don't support the system instruction parameter.
if (isGemma3 && systemInstruction) {
if (contents.length > 0 && contents[0].role === "user") {
const firstMessage = contents[0]
// Create a new text part for the system instruction
const systemPart = { text: systemInstruction }
// Prepend it to the existing parts
firstMessage.parts = [systemPart, ...(firstMessage.parts || [])]
} else {
// If no messages or first message is not user (e.g. starts with model),
// prepend a new user message with the system instruction.
contents.unshift({
role: "user",
parts: [{ text: systemInstruction }],
})
}
}

Fix it with Roo Code or mention @roomote and request a fix.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Dec 19, 2025
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Dec 20, 2025
@dosubot dosubot Bot removed the size:XXL This PR changes 1000+ lines, ignoring generated files. label Dec 20, 2025
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Dec 20, 2025
@techstrom

Copy link
Copy Markdown
Author

Hi, just a gentle ping

I’ve rebased this PR to follow the latest release as of Dec 20 (v3.36.16), so it should be fully up to date with the current main branch.

No rush at all — I just wanted to check whether there’s anything you’d like me to adjust, or if this change is something you’d be interested in merging.

Thanks for your time!

Merge remote-tracking branch 'upstream/main' into gemma3
@hannesrudolph

Copy link
Copy Markdown
Contributor

Apologies for the delayed response.

Thanks for the contribution. We are not planning to add support for the Gemma 3 or Gemini Robotics models via this API at this time.

We have not seen enough demand to justify expanding the supported model set, and the PR goes beyond adding model identifiers by introducing model-specific request reshaping and error handling that makes the provider more complex and harder to maintain.

If there is broader demand, please open a feature request issue with the concrete use case, which models need to work, and why they require behavior that differs from the existing provider contract.

@github-project-automation github-project-automation Bot moved this from Triage to Done in Roo Code Roadmap Jan 7, 2026
@github-project-automation github-project-automation Bot moved this from New to Done in Roo Code Roadmap Jan 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Enhancement New feature or request Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants