Skip to content

Conversation

HillPhelmuth
Copy link

@HillPhelmuth HillPhelmuth commented Sep 20, 2025

Motivation and Context

Fix #13154

Description

Introduce an optional AuthorRole? role parameter to the ToResponseContentPart methods in KernelContentExtensions . Update the ToResponseItem method in ChatContentMessageExtensions to utilize this role for determining the correct content part type (Input or Output). Modify tests in ChatContentMessageExtensionsTests to ensure accurate validation of content part types based on the author role.

Contribution Checklist

Introduce an optional `AuthorRole? role` parameter to the `ToResponseContentPart` methods in `KernelContentExtensions` . Update the `ToResponseItem` method in `ChatContentMessageExtensions` to utilize this role for determining the correct content part type (Input or Output). Modify tests in `ChatContentMessageExtensionsTests` to ensure accurate validation of content part types based on the author role.
@HillPhelmuth HillPhelmuth requested review from Copilot and removed request for Copilot September 20, 2025 01:28
@HillPhelmuth HillPhelmuth requested a review from a team as a code owner September 20, 2025 01:28
@moonbox3 moonbox3 added the .NET Issue or Pull requests regarding .NET code label Sep 20, 2025
@github-actions github-actions bot changed the title Add optional role parameter to 'ResponseContentPart' conversion methods .Net: Add optional role parameter to 'ResponseContentPart' conversion methods Sep 20, 2025
@HillPhelmuth
Copy link
Author

HillPhelmuth commented Sep 20, 2025

@microsoft-github-policy-service agree

@wim-gdwi
Copy link

@HillPhelmuth do you have any clue when the merge will be completed, and/or do you have a workaround for this issue perhaps? I'm currently completely blocked by this issue since I need to use the responses API but can never build up a reasonable conversation...

@HillPhelmuth
Copy link
Author

@HillPhelmuth do you have any clue when the merge will be completed, and/or do you have a workaround for this issue perhaps? I'm currently completely blocked by this issue since I need to use the responses API but can never build up a reasonable conversation...

I have no idea when, or even if, it will be merged. It seems that development on this project has slowed down quite a bit over the last month or two, so I don't have a good sense of when this issue and associated PR will be on the SK team's radar. Hopefully the pace picks back up after .NET 10 is released.

There's a fairly straightforward work-around though. The OpenAI Responses api is designed to be stateful, so you can pass the responseId and it will use the stored history. Example is in ManageConversationStateWithResponseIdAsync() (important note: this example uses the agent thread instead of stored history, but it will work by setting StoreEnabled = true instead when instantiating your OpenAIResponseAgent). This way you don't have to send the broken assistant messages when invoking the agent. This also has the benefit of being OpenAI's recommended approach.

@wim-gdwi
Copy link

The problem with your workaround is that it only works from "scratch". if you reload an agent with previous history, or with history coming from another agent to start with (which is the case in our multi agentic framework using SK), then the trick of enabling the store doesn't really work. Hope the SK guys come wit ha solution really soon or I'm going to have to implement OpenAI directly for response API... which kind of defeats the purpose of SK all together

@Copilot Copilot AI review requested due to automatic review settings October 14, 2025 00:21
Copy link
Contributor

@Copilot Copilot AI left a comment

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 addresses issue #13154 by adding role-aware content part conversion to properly differentiate between input and output text content parts based on the author role. The changes ensure that text content from assistant messages is converted to OutputText parts while other roles create InputText parts.

  • Added optional AuthorRole? role parameter to ToResponseContentPart methods in KernelContentExtensions
  • Updated text content conversion logic to create OutputText parts for assistant role and InputText parts for others
  • Modified tests to validate correct content part types based on author role

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
KernelContentExtensions.cs Added role parameter and logic to create appropriate text content part types
ChatContentMessageExtensions.cs Updated to pass author role when converting message items to response content parts
ChatContentMessageExtensionsTests.cs Enhanced test validation to check for correct content part types based on role

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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

Labels

.NET Issue or Pull requests regarding .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Net: Bug: OpenAIResponseAgent Throws 400 Error When Assistant Message Is Included in Chat History

4 participants