Skip to content

Honor raw content representations in Responses system and developer messages - #7787

Open
Laurianti wants to merge 1 commit into
dotnet:mainfrom
Laurianti:fix-responses-system-raw-parts
Open

Laurianti wants to merge 1 commit into
dotnet:mainfrom
Laurianti:fix-responses-system-raw-parts

Conversation

@Laurianti

@Laurianti Laurianti commented Sep 27, 2026 •

Copy link
Copy Markdown

Why

OpenAIResponsesChatClient rebuilds a system or developer message from ChatMessage.Text, so a ResponseContentPart or ResponseItem set as RawRepresentation on its contents never reaches the request. User messages already send both as is, and OpenAIChatClient does the same for system and developer messages.

ResponseContentPart part = ResponseContentPart.CreateInputTextPart("cached instructions");
ChatMessage system = new(ChatRole.System, [new TextContent("cached instructions") { RawRepresentation = part }]);

// Before: a system message item rebuilt from "cached instructions", without `part`.
// Now: a system message item whose content is `part`.

This is how a caller sets a provider field that Microsoft.Extensions.AI does not model on a system prompt, such as the prompt cache breakpoint in #7679.

Change

When any content of a system or developer message carries a raw ResponseItem or ResponseContentPart, the message is converted as a user message is: raw items are yielded as they are, raw parts and text become the parts of the message item, and parts between yielded items are grouped into their own item to keep the order. Contents that are neither raw nor text are left out, as before.

A system or developer message without raw contents is converted exactly as before.

Fixes #7679

Microsoft Reviewers: Open in CodeFlow

@Laurianti
Laurianti requested a review from a team as a code owner September 27, 2026 13:41
Copilot AI lite review requested due to automatic review settings September 27, 2026 13:41
@github-actions github-actions Bot added the area-ai Microsoft.Extensions.AI libraries label Sep 27, 2026

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.

Copilot review overview

🟢 Approval recommended

No unresolved blocking issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Updates Responses message conversion to preserve raw ResponseItem and ResponseContentPart representations in system and developer messages.

Changes:

  • Added raw-representation-aware conversion and ordering.
  • Added tests for system/developer messages and mixed content.
File Description
test/​Libraries/​Microsoft.Extensions.AI.OpenAI.Tests/​OpenAIConversionTests.cs Verifies raw parts, items, and ordering.
src/​Libraries/​Microsoft.Extensions.AI.OpenAI/​OpenAIResponsesChatClient.cs Preserves raw instruction content during conversion.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@dotnet-comment-bot

Copy link
Copy Markdown
Collaborator

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Microsoft.Extensions.Diagnostics.Testing Line 99 98.65 🔻
Microsoft.Extensions.Telemetry Line 93 92.64 🔻
Microsoft.Extensions.AI.OpenAI Line 75 68.59 🔻
Microsoft.Extensions.AI.OpenAI Branch 75 58.22 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Line 75 4.46 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Branch 75 0 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Line 99 96.03 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Branch 99 92.76 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes Line 99 97.73 🔻
Microsoft.Extensions.ServiceDiscovery.Dns Line 75 69.93 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Line 75 42.11 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Branch 75 42.86 🔻
Microsoft.Extensions.ServiceDiscovery Line 75 67.21 🔻
Microsoft.Extensions.ServiceDiscovery Branch 75 71.43 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Line 75 73.85 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Branch 75 70 🔻
Microsoft.Extensions.VectorData.Abstractions Line 75 37.39 🔻
Microsoft.Extensions.VectorData.Abstractions Branch 75 22.73 🔻

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

Project Expected Actual
Microsoft.Extensions.Http.Diagnostics 94 95
Microsoft.Gen.BuildMetadata 97 100
Microsoft.Gen.MetadataExtractor 57 73
Microsoft.Gen.MetricsReports 67 69
Microsoft.Extensions.AI.Abstractions 82 86
Microsoft.Extensions.AI.Evaluation.NLP 0 78
Microsoft.Extensions.Caching.Hybrid 82 84
Microsoft.Extensions.DataIngestion 75 89
Microsoft.Extensions.DataIngestion.Markdig 75 90
Microsoft.Extensions.Http.Resilience 97 100

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

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.

OpenAIResponsesChatClient drops content-level RawRepresentation for System and Developer messages

4 participants