Skip to content

.NET: Require thread for background responses#2498

Merged
SergeyMenshykh merged 5 commits into
microsoft:mainfrom
SergeyMenshykh:require-thread-for-background-responses
Nov 27, 2025
Merged

.NET: Require thread for background responses#2498
SergeyMenshykh merged 5 commits into
microsoft:mainfrom
SergeyMenshykh:require-thread-for-background-responses

Conversation

@SergeyMenshykh

Copy link
Copy Markdown
Contributor

This PR prevents the usage of background responses if no agent thread is provided to A2AAgent.Run{Streaming}Async calls. This change aligns the A2A agent's behavior with that of the ChatClientAgent, where the absence of a thread with background responses could cause inconsistency issues.

@SergeyMenshykh SergeyMenshykh self-assigned this Nov 27, 2025
Copilot AI review requested due to automatic review settings November 27, 2025 10:50
@SergeyMenshykh SergeyMenshykh added .NET Usage: [Issues, PRs], Target: .Net a2a Usage: [Issues, PRs], Target: A2A labels Nov 27, 2025

Copilot AI 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 PR adds validation to prevent background responses without a thread in A2AAgent, aligning its behavior with ChatClientAgent to ensure consistent user experience.

Key Changes

  • Extracted thread validation logic into a new GetA2AThread helper method that validates both the background response requirement and thread type compatibility
  • Added comprehensive unit tests covering both RunAsync and RunStreamingAsync methods for the new validation scenarios

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.A2A/A2AAgent.cs Refactored thread validation by introducing GetA2AThread method that enforces thread requirement when AllowBackgroundResponses is enabled and validates thread type compatibility
dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs Added four new test methods covering both sync and streaming scenarios for background responses without thread and invalid thread type, plus a helper class for testing invalid thread types

Comment thread dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs Outdated
Comment thread dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs Outdated
Comment thread dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs Outdated
Comment thread dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs Outdated
Comment thread dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs
@SergeyMenshykh SergeyMenshykh added this pull request to the merge queue Nov 27, 2025
arisng pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
* require thread for backgraund responses

* address pr review feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a2a Usage: [Issues, PRs], Target: A2A .NET Usage: [Issues, PRs], Target: .Net

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants