Skip to content

Send compact JSON in chat tool payloads - #7938

Open
valkiara wants to merge 1 commit into
dotnet:mainfrom
valkiara:fix/compact-tool-json
Open

valkiara wants to merge 1 commit into
dotnet:mainfrom
valkiara:fix/compact-tool-json

Conversation

@valkiara

@valkiara valkiara commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Chat Completions sends tool arguments and structured tool results as JSON strings. The default serializer indents both strings, adding whitespace to the request.

Use compact JSON for those payloads while retaining the existing serializer settings. String tool results still pass through unchanged.

Fixes #7921.

Both regression tests failed on the indented payloads before the fix. Afterward, the .NET 11 adapter suite passed (398 passed, 163 live integration tests skipped). Both regression tests also passed with reflection-based JSON serialization disabled. The adapter built for all six target frameworks with zero warnings or errors.

Microsoft Reviewers: Open in CodeFlow

@valkiara
valkiara requested a review from a team as a code owner November 11, 2026 14:10
@github-actions github-actions Bot added the area-ai Microsoft.Extensions.AI libraries label Nov 11, 2026
@dotnet-comment-bot

Copy link
Copy Markdown
Collaborator

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Microsoft.Extensions.AI Line 89 87.81 🔻
Microsoft.Extensions.AI Branch 89 79.23 🔻
Microsoft.Extensions.AI.OpenAI Line 75 68.83 🔻
Microsoft.Extensions.AI.OpenAI Branch 75 60.34 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Line 75 4.46 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Branch 75 0.75 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Line 99 96.06 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Branch 99 92.28 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes Line 99 97.73 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes Branch 99 92.86 🔻
Microsoft.Extensions.Diagnostics.Testing Line 99 98.22 🔻
Microsoft.Extensions.Diagnostics.Testing Branch 99 93.66 🔻
Microsoft.Extensions.ServiceDiscovery Line 75 59.18 🔻
Microsoft.Extensions.ServiceDiscovery Branch 75 64.41 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Line 75 41.14 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Branch 75 45.1 🔻
Microsoft.Extensions.ServiceDiscovery.Dns Line 75 62.53 🔻
Microsoft.Extensions.ServiceDiscovery.Dns Branch 75 74.08 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Line 75 73.85 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Branch 75 60 🔻
Microsoft.Extensions.Telemetry Line 93 90.47 🔻
Microsoft.Extensions.Telemetry Branch 93 86.83 🔻
Microsoft.Extensions.VectorData.Abstractions Line 75 32.15 🔻
Microsoft.Extensions.VectorData.Abstractions Branch 75 26.31 🔻

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Extensions.AI.Evaluation.NLP 0 74
Microsoft.Extensions.Caching.Hybrid 81 83
Microsoft.Extensions.DataIngestion 75 77
Microsoft.Extensions.DataIngestion.Markdig 75 88
Microsoft.Extensions.DocumentExtraction 80 94
Microsoft.Extensions.DocumentExtraction.Abstractions 80 100
Microsoft.Extensions.Documents.Abstractions 80 98
Microsoft.Gen.MetadataExtractor 57 72
Microsoft.Gen.MetricsReports 67 69

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1675454&view=codecoverage-tab

@dfedoryshchev

Copy link
Copy Markdown
Contributor

You fixed Chat Completions, but the Responses client still sends the same payloads indented: OpenAIResponsesChatClient.ToOpenAIResponseItems serializes FunctionResultContent.Result with AIJsonUtilities.DefaultOptions (L1528) and FunctionCallContent.Arguments the same way (L1596), so a tool loop on GetResponsesClient().AsIChatClient() pays the whitespace from #7921 on every turn. The MCP call and approval arguments (L1606, L1618) and the realtime function result (OpenAIRealtimeClientSession.cs L639) go through DefaultOptions too.

Minor: _toolJsonOptions could live somewhere both clients share, so the two adapters don't drift again.

This branch has not been deployed

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

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAIChatClient sends tool results and arguments to the model as indented JSON

3 participants