Skip to content

Feature: Add Structured Output and Code Execution Checkboxes for Gemini API Provider #7533

@VooDisss

Description

@VooDisss

Feature: Add "Structured Output" and "Code Execution" Checkboxes for Gemini API Provider

Problem Description

The Google Gemini API provider currently has checkboxes for "Enable Grounding with Google search" and "Enable URL context", but is missing two important capabilities that Gemini supports:

  1. Structured Output - Allows Gemini to return responses in predictable, machine-readable formats (JSON, etc.)
  2. Code Execution - Enables Gemini to execute code for mathematical calculations, data analysis, and other computational tasks

These features are supported by the Gemini API via the "tools" functionality but are not exposed in the Roo Code UI.

Current Implementation Analysis

Based on examination of the codebase, the existing Gemini checkboxes are implemented in:

UI Component: webview-ui/src/components/settings/providers/Gemini.tsx (lines 79-100)
I18N Strings: webview-ui/src/i18n/locales/en/settings.json (lines 343-352)

Current pattern:

<Checkbox
  data-testid="checkbox-grounding-search"
  checked={!!apiConfiguration.enableGrounding}
  onChange={(checked: boolean) => setApiConfigurationField("enableGrounding", checked)}>
  {t("settings:providers.geminiParameters.groundingSearch.title")}
</Checkbox>

Type Definitions: The ProviderSettings type needs to include the new boolean fields.

Proposed Solution

1. Add New Type Fields

Add to packages/types/src/providers.ts:

export interface ProviderSettings {
  // ... existing fields ...
  enableStructuredOutput?: boolean
  enableCodeExecution?: boolean
}

2. Add I18N Strings

Add to webview-ui/src/i18n/locales/en/settings.json:

"geminiParameters": {
  "urlContext": { /* existing */ },
  "groundingSearch": { /* existing */ },
  "structuredOutput": {
    "title": "Enable Structured Output",
    "description": "Allows Gemini to return responses in structured formats like JSON for predictable, machine-readable output."
  },
  "codeExecution": {
    "title": "Enable Code Execution",
    "description": "Enables Gemini to execute code for mathematical calculations, data analysis, and computational tasks."
  }
}

3. Update UI Component

Add to webview-ui/src/components/settings/providers/Gemini.tsx after line 98:

<Checkbox
  data-testid="checkbox-structured-output"
  checked={!!apiConfiguration.enableStructuredOutput}
  onChange={(checked: boolean) => setApiConfigurationField("enableStructuredOutput", checked)}>
  {t("settings:providers.geminiParameters.structuredOutput.title")}
</Checkbox>
<div className="text-sm text-vscode-descriptionForeground mb-3 mt-1.5">
  {t("settings:providers.geminiParameters.structuredOutput.description")}
</div>

<Checkbox
  data-testid="checkbox-code-execution"
  checked={!!apiConfiguration.enableCodeExecution}
  onChange={(checked: boolean) => setApiConfigurationField("enableCodeExecution", checked)}>
  {t("settings:providers.geminiParameters.codeExecution.title")}
</Checkbox>
<div className="text-sm text-vscode-descriptionForeground mb-3 mt-1.5">
  {t("settings:providers.geminiParameters.codeExecution.description")}
</div>

4. Add API Integration

The backend implementation would use Gemini's tools functionality similar to the existing URL context and grounding features.

Technical Context

According to Gemini API documentation from /doggy8088/gemini-api-cookbook, both features can be implemented using the "tools" mechanism:

  • Code Execution: Uses code execution tools that allow Gemini to run Python code
  • Structured Output: Uses response format specifications to ensure predictable output formats

Example from the cookbook:

# Setup model with tools
model = genai.GenerativeModel(
    'gemini-pro',
    tools=[code_execution_tool, structured_output_tool]
)

Benefits

  1. Enhanced Functionality: Users can leverage Gemini's full capabilities
  2. Consistent UX: Follows the existing pattern of other Gemini checkboxes
  3. Backward Compatibility: New checkboxes default to unchecked
  4. Implementation Ready: Uses established patterns from existing features

Implementation Steps

  1. Add new fields to ProviderSettings type
  2. Add i18n strings for all supported locales
  3. Update Gemini component with new checkboxes
  4. Add backend integration for tools functionality
  5. Update tests to cover new functionality

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue/PR - TriageNew issue. Needs quick review to confirm validity and assign labels.enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions