Fix duplicate tools from OpenAI extra body#14167
Open
hogeheer499-commits wants to merge 1 commit into
Open
Conversation
hogeheer499-commits
force-pushed
the
fix-openai-extra-body-tools-14156
branch
from
July 21, 2026 18:08
4f47c60 to
393ea22
Compare
hogeheer499-commits
marked this pull request as ready for review
July 21, 2026 20:56
Contributor
There was a problem hiding this comment.
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/$.toolsand translates them intoChatCompletionOptions.Toolsentries (including support for unmodeled tool shapes via per-tool JSON patching). - Adds a regression test ensuring only one
toolsproperty 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()) |
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.
Motivation and Context
Fixes #14156.
OpenAIPromptExecutionSettings.ExtraBodycan be used for tool types that the installed OpenAI .NET SDK does not model yet, such asweb_search. Today that produces a second top-leveltoolsproperty beside the SDK-owned one, and the API rejects the request.Description
Top-level
toolsand$.toolsvalues fromExtraBodyare now applied through the SDK'sChatCompletionOptions.Toolscollection. 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