Skip to content

Conversation

@XInTheDark
Copy link

@XInTheDark XInTheDark commented Dec 15, 2025

Problem

  • OpenAI Chat Completions requests that include built-in tools like {"type":"web_search"} were dropped when translating to the Responses API (Codex), resulting in upstream receiving tools:[] and no web search.

Fix

  • Pass through non-function tool entries unchanged during OpenAI Chat Completions -> Codex (Responses) translation.
  • Preserve tool_choice for built-in tools (and flatten function tool_choice to Responses shape).
  • Also preserve built-in tools when converting OpenAI Responses -> OpenAI Chat Completions.

Tests

  • go test ./test -run BuiltinTools

- Pass through non-function tool definitions like web_search

- Translate tool_choice for built-in tools and function tools

- Add regression tests for built-in tool passthrough
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @XInTheDark, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where built-in tools, such as "web_search", were inadvertently dropped during the translation process between OpenAI Chat Completions and the Responses API (Codex). The changes ensure that these tools and their associated "tool_choice" configurations are consistently maintained across both translation directions, thereby preventing data loss and enabling the full functionality of built-in tools within the API ecosystem.

Highlights

  • Preservation of Built-in Tools (OpenAI Chat Completions to Codex): Modified the translation logic to ensure that non-function built-in tools (e.g., "web_search") are passed through unchanged when converting requests from OpenAI Chat Completions to the Responses API (Codex).
  • Preservation of tool_choice for Built-in Tools: Implemented logic to correctly map and preserve "tool_choice" configurations for built-in tools during the OpenAI Chat Completions to Codex translation, while also flattening function "tool_choice" to the Responses API shape.
  • Preservation of Built-in Tools (OpenAI Responses to OpenAI Chat Completions): Updated the translation from OpenAI Responses back to OpenAI Chat Completions to ensure that built-in tools are also preserved in this direction.
  • New Test Coverage: Added dedicated tests to validate that built-in tools are correctly preserved across both translation directions (OpenAI to Codex and OpenAI Responses to OpenAI Chat Completions).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses an issue where built-in tools like web_search were being dropped during API translation. The changes correctly preserve these tools when converting from OpenAI Chat Completions to the Codex/Responses API, and also in the reverse direction. The implementation looks correct and new tests have been added to verify the fix.

My review includes a couple of suggestions for improvement. I've pointed out some code duplication in the tool name shortening logic that could be refactored for better maintainability. I've also suggested enhancing the new tests to cover more complex scenarios, such as requests with a mix of built-in and function tools, to make them more robust and prevent potential regressions.

Comment on lines +325 to +332
name := tc.Get("function.name").String()
if name != "" {
if short, ok := originalToolNameMap[name]; ok {
name = short
} else {
name = shortenNameIfNeeded(name)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This logic for shortening a tool name appears to be duplicated in a few places in this file (e.g., for handling tool_calls around line 208 and tools around line 292). To improve maintainability and reduce code duplication, consider extracting this into a helper function. This would also ensure consistent handling of tool name shortening across different parts of the request translation.

@@ -0,0 +1,54 @@
package test
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The added tests are a great start for verifying the new functionality. To make them more robust and prevent future regressions, consider expanding them to cover scenarios with mixed tool types. For both TestOpenAIToCodex_PreservesBuiltinTools and TestOpenAIResponsesToOpenAI_PreservesBuiltinTools, adding a test case with both a built-in tool (e.g., web_search) and a function tool would ensure that the changes don't interfere with existing functionality. Using a table-driven test structure could help organize these cases cleanly.

@luispater
Copy link
Collaborator

Please attach the failed request payload for our verification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants