Skip to content

.NET: Add Reasoning to ChatClientAgent ChatOptions merging#5463

Open
MaciejWarchalowski wants to merge 2 commits intomicrosoft:mainfrom
MaciejWarchalowski:issues-5460
Open

.NET: Add Reasoning to ChatClientAgent ChatOptions merging#5463
MaciejWarchalowski wants to merge 2 commits intomicrosoft:mainfrom
MaciejWarchalowski:issues-5460

Conversation

@MaciejWarchalowski
Copy link
Copy Markdown

Motivation and Context

ChatClientAgent merges per-request ChatOptions with the agent's default ChatOptions so that caller-supplied values take priority and agent defaults fill in the gaps. The Reasoning property (ReasoningOptions) was the only scalar option missing from this merge logic, meaning it could never be set via the agent's default options — it was silently dropped on every request.

This change adds Reasoning to the merge so it follows the same "request wins, agent default as fallback" pattern as every other ChatOptions property.

Fixes #5460.

Description

ChatClientAgent.cs — one-line fix in the options-merging block:

requestChatOptions.Reasoning ??= this._agentOptions.ChatOptions.Reasoning;

This is placed alongside the other nullable-assign merges (ModelId, PresencePenalty, ResponseFormat, Seed, Temperature, TopP, …) so that:

  • If the caller supplies Reasoning in their ChatOptions, it is used as-is.
  • If the caller omits Reasoning but the agent has a default configured, the agent default is applied.
  • If neither has Reasoning set, the value remains null (unchanged behaviour).

ChatClientAgent_ChatOptionsMergingTests.cs — three new [Fact] tests covering all three cases above:

Test Scenario
ChatOptionsMergingUsesRequestReasoningOverAgentReasoningAsync Request reasoning wins over agent reasoning
ChatOptionsMergingFallsBackToAgentReasoningWhenRequestHasNoneAsync Agent reasoning used when request has none
ChatOptionsMergingUsesRequestReasoningWhenAgentHasNoneAsync Request reasoning used when agent has none

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 April 24, 2026 04:54
@moonbox3 moonbox3 added the .NET label Apr 24, 2026
Copy link
Copy Markdown
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 ChatClientAgent’s per-request ChatOptions merge behavior so the agent-level default ChatOptions.Reasoning is no longer silently dropped when callers provide their own ChatOptions, aligning Reasoning with the existing “request wins, agent fills unset values” merge pattern.

Changes:

  • Add ChatOptions.Reasoning to the ChatClientAgent ChatOptions merge block via ??=.
  • Add unit tests covering request-overrides-agent, agent-fallback, and request-when-agent-null scenarios for Reasoning.

Reviewed changes

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

File Description
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs Adds Reasoning to the existing per-request vs agent-default ChatOptions merge logic.
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatOptionsMergingTests.cs Adds three new tests validating Reasoning merge precedence and fallback behavior.

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: [Bug]: ChatClientAgent chat options merging omits Reasoning property

3 participants