Skip to content

Fix duplicate tools from OpenAI extra body#14167

Open
hogeheer499-commits wants to merge 1 commit into
microsoft:mainfrom
hogeheer499-commits:fix-openai-extra-body-tools-14156
Open

Fix duplicate tools from OpenAI extra body#14167
hogeheer499-commits wants to merge 1 commit into
microsoft:mainfrom
hogeheer499-commits:fix-openai-extra-body-tools-14156

Conversation

@hogeheer499-commits

@hogeheer499-commits hogeheer499-commits commented Jul 19, 2026

Copy link
Copy Markdown

Motivation and Context

Fixes #14156.

OpenAIPromptExecutionSettings.ExtraBody can be used for tool types that the installed OpenAI .NET SDK does not model yet, such as web_search. Today that produces a second top-level tools property beside the SDK-owned one, and the API rejects the request.

Description

Top-level tools and $.tools values from ExtraBody are now applied through the SDK's ChatCompletionOptions.Tools collection. Unknown tool shapes keep their JSON fields, while existing typed function tools and last-write-wins replacement continue to work.

The regression coverage includes both key forms, an unmodeled web-search tool, a modeled function tool, replacement, and duplicate-property detection. The complete OpenAI connector test project passes (498 tests, 1 existing skip), as does the repository formatting check.

Contribution Checklist

@hogeheer499-commits
hogeheer499-commits force-pushed the fix-openai-extra-body-tools-14156 branch from 4f47c60 to 393ea22 Compare July 21, 2026 18:08
@hogeheer499-commits
hogeheer499-commits marked this pull request as ready for review July 21, 2026 20:56
@hogeheer499-commits
hogeheer499-commits requested a review from a team as a code owner July 21, 2026 20:56
Copilot AI review requested due to automatic review settings July 21, 2026 20:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the OpenAI .NET connector’s handling of OpenAIPromptExecutionSettings.ExtraBody so that when users specify tools via ExtraBody, the value is applied through the SDK-owned ChatCompletionOptions.Tools collection instead of being emitted as an additional top-level JSON property (which can result in duplicate tools fields and request rejection).

Changes:

  • Intercepts ExtraBody keys tools / $.tools and translates them into ChatCompletionOptions.Tools entries (including support for unmodeled tool shapes via per-tool JSON patching).
  • Adds a regression test ensuring only one tools property is present in the outgoing request body for both key forms.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
dotnet/src/Connectors/Connectors.OpenAI/Settings/OpenAIPromptExecutionSettings.cs Adds specialized handling to map ExtraBody tools into ChatCompletionOptions.Tools to avoid duplicate tools JSON properties.
dotnet/src/Connectors/Connectors.OpenAI.UnitTests/Services/OpenAIChatCompletionExtraBodyTests.cs Adds coverage to verify tools is not duplicated when supplied via ExtraBody using either tools or $.tools.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +679 to +682
if (value is null || (key != "tools" && key != "$.tools"))
{
return false;
}
Comment on lines +698 to +699
tool.Patch.Remove(System.Text.Encoding.UTF8.GetBytes("$.function"));
foreach (JsonProperty property in toolElement.EnumerateObject())
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.

OpenAIPromptExecutionSettings.ExtraBody duplicates tools JSON property when setting nested object for web search tool

2 participants