Skip to content

Support Gemini code execution in GoogleGenAiChatModel#6530

Open
subhashpolisetti wants to merge 1 commit into
spring-projects:mainfrom
subhashpolisetti:google-genai-code-execution
Open

Support Gemini code execution in GoogleGenAiChatModel#6530
subhashpolisetti wants to merge 1 commit into
spring-projects:mainfrom
subhashpolisetti:google-genai-code-execution

Conversation

@subhashpolisetti

Copy link
Copy Markdown
Contributor

This adds support for Gemini's built-in code execution tool to GoogleGenAiChatModel, mirroring the existing googleSearchRetrieval option.

When codeExecution(true) is set, the request includes the Gemini code execution tool, allowing the model to generate and run Python code server-side and use the result in its response. The generated code and execution result returned by the model are surfaced on the response message metadata via executableCode, executableCodeLanguage, codeExecutionResult, and codeExecutionOutcome.

The capability is supported on both the Gemini Developer API and Vertex AI, and uses types already provided by the Google Java SDK (com.google.genai), so no new dependency is added.

Testing

Added 8 unit tests and 1 integration test:

  • Request building: the code execution tool is added when enabled, and absent by default.
  • Options: builder, default value, equals/hashCode, and mutate round-trip for the new option.
  • Response handling: the generated code and execution result parts are surfaced into the message metadata, and absent when not present.
  • Integration: an end-to-end test gated on the GOOGLE_API_KEY environment variable, verified against the live Gemini API.

./mvnw -pl models/spring-ai-google-genai clean test passes (191 tests, Checkstyle and formatting clean).

Documentation

Reference documentation is updated with the new option, the response metadata keys, and notes on the multi-part response shape.

Closes #6471

Add a `codeExecution` option to `GoogleGenAiChatOptions` that enables
Gemini's built-in code execution tool, mirroring the existing
`googleSearchRetrieval` option. The generated code and execution result
are surfaced on the response message metadata.

Closes spring-projects#6471

Signed-off-by: subhash polisetti <subhashr161347@gmail.com>
@subhashpolisetti subhashpolisetti force-pushed the google-genai-code-execution branch from 94246f6 to 8955358 Compare July 5, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support the Gemini code execution tool in GoogleGenAiChatModel

2 participants