Skip to content

Comments

feat(providers/google): Add codeExecution and reasoning support in v5#6365

Closed
Und3rf10w wants to merge 14 commits intovercel:v5from
Und3rf10w:feat/googleCodeExecutionv5
Closed

feat(providers/google): Add codeExecution and reasoning support in v5#6365
Und3rf10w wants to merge 14 commits intovercel:v5from
Und3rf10w:feat/googleCodeExecutionv5

Conversation

@Und3rf10w
Copy link
Contributor

@Und3rf10w Und3rf10w commented May 16, 2025

Background

Vertex now supports extraction of thinking tokens in certain Gemini models.

When the configuration is passed via providerOptions, the sdk:

  1. Did not extract reasoning tokens
  2. Did not pass include_thoughts to the provider

The google and google-vertex providers would silently drop user defined tools when used in combination with useSearchGrounding. Using useSearchGrounding in 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

  • Added extraction logic to google-generative-ai package to parse reasoning tokens.
  • Added a includeThoughts switch to the thinkingConfig for vertex models.

  • Throw an error when tools are used in conjunction with useSearchGrounding and useCodeExecution on the Google Generative AI and thus Vertex providers
  • Added logic to call the google defined codeExecution tool, and extract the executableCode as a file part, and the codeExecutionResult as 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-text and generate-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-ai provider, you can pass BOTH useSearchGrounding and useCodeExecution, but NOT in the google.vertex provider. (See eb4bfc9)

Tasks

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)

Future Work

Consider how to best handle the codeExecutionResult part. Currently, I just add it as a text part, 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 here

const formattedText = `Execution Result (Outcome: ${part.codeExecutionResult.outcome}):\n${outputText}`;

Perhaps that's not the desired effect.

Related Issues

Fixes #6302
Fixes #6219
Closes #6354
Related #6359
Related #6261
Related #6428

@Und3rf10w Und3rf10w changed the title feat(providers/google): Add codeExecution and reasoning support feat(providers/google): Add codeExecution and reasoning support in v5 May 16, 2025
@tjazsilovsek
Copy link

Great PR, can't wait for it to land! any ETA for it to be merged?

@Und3rf10w
Copy link
Contributor Author

Und3rf10w commented Jul 28, 2025

Great PR, can't wait for it to land! any ETA for it to be merged?

Realistically, at this point, the PR needs to be rewritten. Reasoning is already fully supported in the v5 branch, but the added concept of provider defined tools has changed things. In theory, it shouldn't be that difficult to redo, especially now that we can more easily and accurately handle the results of the codeExecutionResult and handle that as a provider defined tool output or something.

I will likely rewrite and resubmit this PR at some point this week tonight, apparently... with that in mind.

@Und3rf10w
Copy link
Contributor Author

Closing in lieu of #7590

@Und3rf10w Und3rf10w closed this Jul 28, 2025
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
@Und3rf10w Und3rf10w deleted the feat/googleCodeExecutionv5 branch August 12, 2025 15:03
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.

3 participants