Skip to content

Conversation

@MD-V
Copy link

@MD-V MD-V commented Nov 21, 2025

Modified the OpenAI clients in AgentChatWebExample to send the needed metadata.

Motivation and Context

Fixes #2376

Description

I've added RawRepresentationFactory as suggested with now supplies the correct metadata for HostedAgentResponseExecutor.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings November 21, 2025 14:55
Copilot finished reviewing on behalf of MD-V November 21, 2025 14:56
@MD-V
Copy link
Author

MD-V commented Nov 21, 2025

@microsoft-github-policy-service agree

Copy link
Contributor

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 fixes an issue where OpenAI ChatClients were not sending the required entity_id metadata in the AgentChatWebExample. The fix adds RawRepresentationFactory to the ChatOptions to supply the correct metadata for HostedAgentResponseExecutor.

Key Changes

  • Added RawRepresentationFactory to ChatOptions in both OpenAI client implementations to include entity_id metadata
  • Added using OpenAI.Responses; namespace in OpenAIChatCompletionsAgentClient.cs

Reviewed changes

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

File Description
dotnet/samples/AgentWebChat/AgentWebChat.Web/OpenAIResponsesAgentClient.cs Added RawRepresentationFactory to create ResponseCreationOptions with entity_id metadata
dotnet/samples/AgentWebChat/AgentWebChat.Web/OpenAIChatCompletionsAgentClient.cs Added using statement for OpenAI.Responses, introduced chatOptions variable with RawRepresentationFactory to create ChatCompletionOptions with entity_id metadata

};

var openAiClient = new OpenAIResponseClient(model: agentName, credential: new ApiKeyCredential("dummy-key"), options: options).AsIChatClient();
var chatOptions = new ChatOptions()
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

According to the C# Sample Code Guidelines, prefer defining variables using explicit types rather than var to help users understand the types involved. Change var chatOptions to ChatOptions chatOptions.

Copilot generated this review using guidance from repository custom instructions.
await foreach (var update in openAiClient.GetStreamingResponseAsync(messages, cancellationToken: cancellationToken))

var chatOptions = new ChatOptions()
{
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

According to the C# Sample Code Guidelines, prefer defining variables using explicit types rather than var to help users understand the types involved. Change var chatOptions to ChatOptions chatOptions.

Copilot generated this review using guidance from repository custom instructions.
Transport = new HttpClientPipelineTransport(httpClient)
};

var openAiClient = new OpenAIResponseClient(model: agentName, credential: new ApiKeyCredential("dummy-key"), options: options).AsIChatClient();

Choose a reason for hiding this comment

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

This also has a problem, because you will have to pass a LLM model in the model name and not the agent name.

This is quite strange that you will have to pass the model and the agent whereas the agent also defines which model to use.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET : Unable to supply metadata to OpenAI ChatClients

3 participants