Skip to content

.NET: OpenAI Responses: suppress 'model' parameter if it is used for agent - #2003

Closed
Reuben Bond (ReubenBond) wants to merge 4 commits into
microsoft:mainfrom
ReubenBond:fix/oai-devui-model
Closed

.NET: OpenAI Responses: suppress 'model' parameter if it is used for agent#2003
Reuben Bond (ReubenBond) wants to merge 4 commits into
microsoft:mainfrom
ReubenBond:fix/oai-devui-model

Conversation

@ReubenBond

Copy link
Copy Markdown
Member

Motivation and Context

The DevUI currently flows the entity id in the 'model' field, but this field has should otherwise be flowed into the implementation. When the 'model' field is used for the entity id, we should instead suppress it from flowing further down the call chain as the model field, since consumers cannot distinguish a model parameter from an entity id.

This PR implements the above logic and enhances request validation.

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.

CopilotAI review requested due to automatic review settings November 7, 2025 14:51
@markwallace-microsoftMark Wallace (markwallace-microsoft) added the .NET Usage: [Issues, PRs], Target: .Net label Nov 7, 2025
@github-actionsgithub-actionsBot changed the title OpenAI Responses: suppress 'model' parameter if it is used for agent.NET: OpenAI Responses: suppress 'model' parameter if it is used for agentNov 7, 2025

CopilotAI 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.

Pull Request Overview

This pull request refactors error handling for the OpenAI Responses API by introducing a validation layer that executes before response creation. The main goal is to return proper HTTP status codes (BadRequest instead of NotFound) for validation errors and to centralize validation logic.

  • Introduces a new ValidateRequestAsync method in IResponseExecutor and IResponsesService for early request validation
  • Refactors error handling in ResponsesHttpHandler to use validation results and response status codes instead of exception-based error handling
  • Updates agent resolution logic in HostedAgentResponseExecutor to support the new validation pattern

Reviewed Changes

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

Show a summary per file
FileDescription
OpenAIResponsesAgentResolutionIntegrationTests.csUpdates test expectation from NotFound to BadRequest for non-existent agent scenarios
ResponsesHttpHandler.csAdds pre-validation step and replaces exception-based error handling with status-based error handling
InMemoryResponsesService.csImplements ValidateRequestAsync method and removes inline validation from execution methods
IResponsesService.csAdds ValidateRequestAsync method signature to interface
IResponseExecutor.csAdds ValidateRequestAsync method signature and necessary using statement
HostedAgentResponseExecutor.csImplements ValidateRequestAsync and refactors agent resolution logic in ExecuteAsync
AgentRunResponseExtensions.csRemoves default value assignment for ServiceTier
AIAgentResponseExecutor.csAdds no-op implementation of ValidateRequestAsync
08_WriterCriticWorkflow/Program.csRemoves explicit type parameter from StreamAsync call
07_MixedWorkflowAgentsAndExecutors/Program.csRemoves explicit type parameter from StreamAsync call

this._logger.LogError(ex, "Failed to resolve agent with name '{AgentName}'", agentName);
throw new InvalidOperationException($"Agent '{agentName}' not found. Ensure the agent is registered with AddAIAgent().", ex);
}
return request.Agent?.Name ?? request.Model;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you remind me why DevUI doesn't just always send it in an agent property rather than using model for that?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

DevUI uses the official OpenAI SDK, which doesn't have the 'agent' property. I want to introduce a change there to use the 'metadata' dictionary instead of 'model', but I want to un-block Jeff Handley (@jeffhandley) etc asap

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

DevUI uses the official OpenAI SDK, which doesn't have the 'agent' property

But it does now have JSON Patch support, so you can get/set whatever properties you want to a request.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Do all of the OpenAI SDKs support setting arbitrary properties in requests & responses?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I have an alternate PR here that uses metadata.entity_id instead: #1984

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

Labels

.NETUsage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@ReubenBond@stephentoub@DeagleGross@markwallace-microsoft