-
Notifications
You must be signed in to change notification settings - Fork 891
.NET: [Breaking] Change AgentRunOptions.AllowBackgroundResponses from bool? to bool #2819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: SergeyMenshykh <[email protected]>
There was a problem hiding this 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 changes the AgentRunOptions.AllowBackgroundResponses property from bool? to bool, eliminating the ambiguous null state and requiring explicit opt-in for background responses functionality.
Key Changes:
- Property type changed from nullable to non-nullable boolean with
falseas the default - Updated condition logic to check for explicit
truevalue instead of null checking
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRunOptions.cs |
Changed AllowBackgroundResponses property type from bool? to bool |
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs |
Updated condition from is not null to == true to check if background responses are enabled |
| { | ||
| // If any of the background response properties are set in the run options, we should apply both to the chat options. | ||
| if (agentRunOptions?.AllowBackgroundResponses is not null || agentRunOptions?.ContinuationToken is not null) | ||
| if (agentRunOptions?.AllowBackgroundResponses == true || agentRunOptions?.ContinuationToken is not null) |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition logic doesn't properly handle the case where AllowBackgroundResponses is explicitly set to false in AgentRunOptions.
With the change from bool? to bool, there's no way to distinguish between "not set" (default false) and "explicitly set to false". The current condition agentRunOptions?.AllowBackgroundResponses == true only enters the block when the value is true, meaning that an explicit false value won't be propagated to chatOptions unless ContinuationToken is also set.
This creates an inconsistency: if a user wants to override a true value from ChatOptions by setting AllowBackgroundResponses = false in AgentRunOptions, it will only work if they also provide a ContinuationToken. Without the ContinuationToken, the override won't take effect.
The test RunAsyncPrioritizesBackgroundResponsesPropertiesFromAgentRunOptionsOverOnesFromChatOptionsAsync validates that false should override true, but it only passes because it also sets ContinuationToken.
Consider either: (1) Always apply background response properties when agentRunOptions is not null, or (2) Revert to bool? to maintain the ability to distinguish "not set" from "explicitly false", or (3) Add a separate flag to indicate whether the property was explicitly set.
|
This change breaks the override functionality that allows providing the property via chat options and being able to override it via agent run options if the property is provided in the run options. This change makes it impossible because whatever is specified in the chat options will always be overridden by the value from the agent run options. So, for this scenario, having a third state (null) for the property is beneficial. |
Motivation and Context
Nullable types typically signal "not set, use implementation default." For background responses, this semantic is undesirable -consumers must explicitly opt-in to handle asynchronous operations.
Contributes to: #2542
Description
Changed
AgentRunOptions.AllowBackgroundResponsesfrombool?tobool. Default value is nowfalse, requiring explicit opt-in.Core Changes:
AgentRunOptions.cs: Property type changed frombool?toboolChatClientAgent.cs: Updated null-check logic fromis not nullto== trueContribution Checklist
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.