Skip to content

Comments

feat(providers/google): Add codeExecution provider tool support#7608

Merged
lgrammel merged 5 commits intovercel:mainfrom
Und3rf10w:und3rf10w/v5-google-add-code-execution-support
Jul 30, 2025
Merged

feat(providers/google): Add codeExecution provider tool support#7608
lgrammel merged 5 commits intovercel:mainfrom
Und3rf10w:und3rf10w/v5-google-add-code-execution-support

Conversation

@Und3rf10w
Copy link
Contributor

@Und3rf10w Und3rf10w commented Jul 28, 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.

image

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

Related Issues

Closes #3205
Closes #6354
Closes #6365

Comment on lines 232 to 238
toolCallId: (
[...content]
.reverse()
.find(
c => c.type === 'tool-call' && c.toolName === 'code_execution',
) as any
)?.toolCallId,
Copy link
Collaborator

Choose a reason for hiding this comment

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

it might be easier to keep the last code execution tool call id in a variable

if ('executableCode' in part && part.executableCode?.code) {
content.push({
type: 'tool-call',
toolCallId: this.config.generateId(), // Generate a unique ID
Copy link
Collaborator

Choose a reason for hiding this comment

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

store id in variable

'codeExecutionResult' in part &&
part.codeExecutionResult
) {
const toolCallId = pendingCodeExecutionToolCallIds.shift();
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above, keep id variable. what benefit does the shift logic have here (in practice)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case I was thinking of parallel calls, but I suppose I could just track the one

@Und3rf10w Und3rf10w requested a review from lgrammel July 29, 2025 16:36
@lgrammel lgrammel merged commit 78e7fa9 into vercel:main Jul 30, 2025
8 of 9 checks passed
@lgrammel
Copy link
Collaborator

Great work @Und3rf10w thank you!!

@Und3rf10w Und3rf10w deleted the und3rf10w/v5-google-add-code-execution-support 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.

support google genai code execution tool

3 participants