You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Create an instance of the AIAgent for an existing A2A agent specified by the agent card.
17
+
AIAgentagent=agentCard.GetAIAgent();
18
+
19
+
AgentThreadthread=agent.GetNewThread();
20
+
21
+
// Start the initial run with a long-running task.
22
+
AgentRunResponseresponse=awaitagent.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);
This sample demonstrates how to poll for long-running task completion using continuation tokens with an A2A AI agent, following the background responses pattern.
4
+
5
+
The sample:
6
+
7
+
- Connects to an A2A agent server specified in the `A2A_AGENT_HOST` environment variable
8
+
- Sends a request to the agent that may take time to complete
9
+
- Polls the agent at regular intervals using continuation tokens until a final response is received
10
+
- Displays the final result
11
+
12
+
This pattern is useful when an AI model cannot complete a complex task in a single response and needs multiple rounds of processing.
13
+
14
+
# Prerequisites
15
+
16
+
Before you begin, ensure you have the following prerequisites:
17
+
18
+
- .NET 10.0 SDK or later
19
+
- An A2A agent server running and accessible via HTTP
20
+
21
+
Set the following environment variable:
22
+
23
+
```powershell
24
+
$env:A2A_AGENT_HOST="http://localhost:5000" # Replace with your A2A agent server host
Copy file name to clipboardExpand all lines: dotnet/samples/GettingStarted/A2A/README.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@ See the README.md for each sample for the prerequisites for that sample.
14
14
|Sample|Description|
15
15
|---|---|
16
16
|[A2A Agent As Function Tools](./A2AAgent_AsFunctionTools/)|This sample demonstrates how to represent an A2A agent as a set of function tools, where each function tool corresponds to a skill of the A2A agent, and register these function tools with another AI agent so it can leverage the A2A agent's skills.|
17
+
|[A2A Agent Polling For Task Completion](./A2AAgent_PollingForTaskCompletion/)|This sample demonstrates how to poll for long-running task completion using continuation tokens with an A2A agent.|
thrownewNotSupportedException($"Only Message and AgentTask responses are supported from A2A agents. Received: {a2aResponse.GetType().FullName??"null"}");
@@ -126,43 +142,67 @@ public override async IAsyncEnumerable<AgentRunResponseUpdate> RunStreamingAsync
126
142
{
127
143
_=Throw.IfNull(messages);
128
144
129
-
vara2aMessage=messages.ToA2AMessage();
130
-
131
145
thread??=this.GetNewThread();
132
146
if(threadis not A2AAgentThreadtypedThread)
133
147
{
134
148
thrownewInvalidOperationException("The provided thread is not compatible with the agent. Only threads created by the agent can be used.");
135
149
}
136
150
137
-
// Linking the message to the existing conversation, if any.
0 commit comments