feat(providers/google): Add codeExecution and reasoning support in v5#6365
Closed
feat(providers/google): Add codeExecution and reasoning support in v5#6365
v5#6365Conversation
… for reasoning and codeExecution
…t examples to support new return types
…or reasoning and codeExecution
Closed
4 tasks
v5
…xecution simultaneously with the google.generative-ai provider
…lt in generate and stream fix(examples/ai-core): Fix stream-text google codeExecution with searchGrounding example to provide web sources
|
Great PR, can't wait for it to land! any ETA for it to be merged? |
Contributor
Author
Realistically, at this point, the PR needs to be rewritten. Reasoning is already fully supported in the I will likely rewrite and resubmit this PR at some point |
4 tasks
Contributor
Author
|
Closing in lieu of #7590 |
4 tasks
lgrammel
pushed a commit
that referenced
this pull request
Jul 30, 2025
## Background This change was necessary to add support for the Code Execution feature available in Google's Gemini models. This allows the model to generate and execute Python code to perform calculations and solve problems, enhancing its capabilities. ## Summary - Added `codeExecution` tool: - A new tool, `google.tools.codeExecution()`, is now available. This enables models that support it to run Python code. ## Verification I manually verified the changes by setting up the new examples for Google Vertex AI. I ran both the `generate-text/google-vertex-code-execution.ts` and `stream-text/google-vertex-code-execution.ts` examples against the `gemini-2.5-pro model`. In both cases, the model successfully used the code execution tool to first calculate the 20th Fibonacci number and then find the nearest palindrome. The console output correctly displayed the tool calls and their corresponding results, followed by the final generated text, confirming that the end-to-end flow is working as expected. <img width="924" height="1013" alt="image" src="https://github.com/user-attachments/assets/d70eea58-1fce-4bcf-873e-3b7f5981ac6c" /> ## Related Issues Closes #3205 Closes #6354 Closes #6365
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Vertex now supports extraction of thinking tokens in certain Gemini models.
When the configuration is passed via
providerOptions, the sdk:include_thoughtsto the providerThe google and google-vertex providers would silently drop user defined tools when used in combination with
useSearchGrounding. UsinguseSearchGroundingin combination with user defined tools is not supported. This change throws an error if that happens.In addition, this change also adds support for the Code Execution feature in both the Google Generative AI and Vertex providers.
Summary
includeThoughtsswitch to thethinkingConfigfor vertex models.useSearchGroundinganduseCodeExecutionon the Google Generative AI and thus Vertex providerscodeExecutiontool, and extract theexecutableCodeas a file part, and thecodeExecutionResultas a text part.Verification
I added and thoroughly tested examples for both providers for both reasoning and code execution. These examples exist for both
stream-textandgenerate-text.I have thoroughly tested the reasoning configurations and verified that we can retrieve reasoning tokens for the Vertex provider.
In addition, I discovered that for the
google.generative-aiprovider, you can pass BOTHuseSearchGroundinganduseCodeExecution, but NOT in thegoogle.vertexprovider. (See eb4bfc9)Tasks
pnpm changesetin the project root)pnpm prettier-fixin the project root)Future Work
Consider how to best handle the
codeExecutionResultpart. Currently, I just add it as atextpart, but maybe that should be a special case. I don't know. To do this, I did change it slightly to incorporate both the outcome and the outputText, as shown herePerhaps that's not the desired effect.
Related Issues
Fixes #6302
Fixes #6219
Closes #6354
Related #6359
Related #6261
Related #6428