-
Notifications
You must be signed in to change notification settings - Fork 829
.NET: Add support for background responses to A2A agent #2381
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
Merged
SergeyMenshykh
merged 17 commits into
microsoft:main
from
SergeyMenshykh:a2a-support-background-responses
Nov 24, 2025
+1,358
−55
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d151b9b
add support for baackground responses to a2a agent
SergeyMenshykh 5e11c46
fix line endings
SergeyMenshykh ae35d67
Merge branch 'main' into a2a-support-background-responses
SergeyMenshykh 2ca601c
address pr review comments
SergeyMenshykh ef8e2d8
Merge branch 'a2a-support-background-responses' of https://github.com…
SergeyMenshykh d745349
address pr review comments
SergeyMenshykh 4d0ba12
Merge branch 'main' into a2a-support-background-responses
SergeyMenshykh a55b006
update sample to net10.0
SergeyMenshykh 84c5188
Merge branch 'main' into a2a-support-background-responses
SergeyMenshykh f4cff99
Update dotnet/samples/GettingStarted/A2A/A2AAgent_PollingForTaskCompl…
SergeyMenshykh 5365991
Update dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2AAgentTaskExte…
SergeyMenshykh 8377a3b
Update dotnet/samples/GettingStarted/A2A/A2AAgent_PollingForTaskCompl…
SergeyMenshykh 2547473
address pr review feedback
SergeyMenshykh 0242933
Merge branch 'a2a-support-background-responses' of https://github.com…
SergeyMenshykh ed6dca1
Merge branch 'main' into a2a-support-background-responses
SergeyMenshykh d477996
add clarification regarding background responses
SergeyMenshykh dd7789e
Merge branch 'a2a-support-background-responses' of https://github.com…
SergeyMenshykh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ingStarted/A2A/A2AAgent_PollingForTaskCompletion/A2AAgent_PollingForTaskCompletion.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
|
|
||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="A2A" /> | ||
| <PackageReference Include="Azure.AI.OpenAI" /> | ||
| <PackageReference Include="Azure.Identity" /> | ||
| <PackageReference Include="Microsoft.Extensions.Hosting" /> | ||
| <PackageReference Include="System.Net.ServerSentEvents" /> | ||
| <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\..\src\Microsoft.Agents.AI.A2A\Microsoft.Agents.AI.A2A.csproj" /> | ||
| <ProjectReference Include="..\..\..\..\src\Microsoft.Agents.AI.OpenAI\Microsoft.Agents.AI.OpenAI.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
35 changes: 35 additions & 0 deletions
35
dotnet/samples/GettingStarted/A2A/A2AAgent_PollingForTaskCompletion/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| // This sample demonstrates how to poll for long-running task completion using continuation tokens with an A2A AI agent. | ||
|
|
||
| using A2A; | ||
| using Microsoft.Agents.AI; | ||
|
|
||
| var a2aAgentHost = Environment.GetEnvironmentVariable("A2A_AGENT_HOST") ?? throw new InvalidOperationException("A2A_AGENT_HOST is not set."); | ||
|
|
||
| // Initialize an A2ACardResolver to get an A2A agent card. | ||
| A2ACardResolver agentCardResolver = new(new Uri(a2aAgentHost)); | ||
|
|
||
| // Get the agent card | ||
| AgentCard agentCard = await agentCardResolver.GetAgentCardAsync(); | ||
|
|
||
| // Create an instance of the AIAgent for an existing A2A agent specified by the agent card. | ||
| AIAgent agent = agentCard.GetAIAgent(); | ||
|
|
||
| AgentThread thread = agent.GetNewThread(); | ||
|
|
||
| // Start the initial run with a long-running task. | ||
| AgentRunResponse response = await agent.RunAsync("Conduct a comprehensive analysis of quantum computing applications in cryptography, including recent breakthroughs, implementation challenges, and future roadmap. Please include diagrams and visual representations to illustrate complex concepts.", thread); | ||
|
|
||
| // Poll until the response is complete. | ||
| while (response.ContinuationToken is { } token) | ||
| { | ||
| // Wait before polling again. | ||
| await Task.Delay(TimeSpan.FromSeconds(2)); | ||
|
|
||
| // Continue with the token. | ||
| response = await agent.RunAsync(thread, options: new AgentRunOptions { ContinuationToken = token }); | ||
| } | ||
|
|
||
| // Display the result | ||
| Console.WriteLine(response); |
25 changes: 25 additions & 0 deletions
25
dotnet/samples/GettingStarted/A2A/A2AAgent_PollingForTaskCompletion/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Polling for A2A Agent Task Completion | ||
|
|
||
| This sample demonstrates how to poll for long-running task completion using continuation tokens with an A2A AI agent, following the background responses pattern. | ||
|
|
||
| The sample: | ||
|
|
||
| - Connects to an A2A agent server specified in the `A2A_AGENT_HOST` environment variable | ||
| - Sends a request to the agent that may take time to complete | ||
| - Polls the agent at regular intervals using continuation tokens until a final response is received | ||
| - Displays the final result | ||
|
|
||
| This pattern is useful when an AI model cannot complete a complex task in a single response and needs multiple rounds of processing. | ||
|
|
||
| # Prerequisites | ||
|
|
||
| Before you begin, ensure you have the following prerequisites: | ||
|
|
||
| - .NET 10.0 SDK or later | ||
| - An A2A agent server running and accessible via HTTP | ||
|
|
||
| Set the following environment variable: | ||
|
|
||
| ```powershell | ||
| $env:A2A_AGENT_HOST="http://localhost:5000" # Replace with your A2A agent server host | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.