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
{{ message }}
Repository navigation
Commit 08851e6
Browse filesBrowse the repository at this point in the historyBrowse files
authored
.NET: Add gRPC protocol selection to the A2A sample (#9563)
Copy file name to clipboardExpand all lines: dotnet/samples/02-agents/A2A/A2AAgent_ProtocolSelection/README.md
+67-3Lines changed: 67 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,15 @@
2
2
3
3
This sample demonstrates how to select the A2A protocol binding when creating an `AIAgent` from an A2A agent card.
4
4
5
-
A2A agents can expose multiple interfaces with different protocol bindings (e.g., HTTP+JSON, JSON-RPC). By default, `AsAIAgent()` prefers HTTP+JSON with JSON-RPC as a fallback. This sample shows how to use `A2AClientOptions.PreferredBindings` to explicitly control which protocol binding is used.
5
+
A2A agents can expose multiple interfaces with different protocol bindings (e.g., HTTP+JSON, JSON-RPC, gRPC). By default, `AsAIAgent()` selects the first HTTP+JSON or JSON-RPC interface listed in the agent card. This sample shows how to use `A2AClientOptions.PreferredBindings` to explicitly control which protocol binding is used.
6
+
7
+
The sample uses only the selected binding; it does not fall back to another protocol.
6
8
7
9
The sample:
8
10
9
11
- Connects to an A2A agent server specified in the `A2A_AGENT_HOST` environment variable
10
-
- Configures `A2AClientOptions` to prefer the HTTP+JSON protocol binding
12
+
- Selects the binding using `A2A_PROTOCOL_BINDING`, defaulting to HTTP+JSON
13
+
- Explicitly registers the gRPC client factory when gRPC is selected
11
14
- Creates an `AIAgent` from the resolved agent card using the specified binding
12
15
- Sends a message to the agent and displays the response
13
16
@@ -16,12 +19,73 @@ The sample:
16
19
Before you begin, ensure you have the following prerequisites:
17
20
18
21
- .NET 10.0 SDK or later
19
-
- An A2A agent server running and accessible via HTTP
22
+
- An A2A agent server running and accessible via HTTP, with support for the selected binding
20
23
21
24
**Note**: These samples need to be run against a valid A2A server. If no A2A server is available, they can be run against the echo-agent that can be spun up locally by following the guidelines at: https://github.com/a2aproject/a2a-dotnet/blob/main/samples/AgentServer/README.md
22
25
26
+
The linked echo-agent does not expose gRPC. To select `GRPC`, use a server whose agent card lists a `GRPC` interface.
27
+
23
28
Set the following environment variable:
24
29
25
30
```powershell
26
31
$env:A2A_AGENT_HOST="http://localhost:5000" # Replace with your A2A agent server host
27
32
```
33
+
34
+
Optionally select a binding:
35
+
36
+
```powershell
37
+
$env:A2A_PROTOCOL_BINDING="GRPC" # Or "HTTP+JSON" (default) or "JSONRPC"
38
+
dotnet run
39
+
```
40
+
41
+
## gRPC client setup
42
+
43
+
The sample already references `Microsoft.Agents.AI.A2A` and the SDK's `A2A.Grpc` package.
44
+
The existing `A2AAgent` works with `A2AGrpcClient`; no additional framework package is needed.
45
+
The base `Microsoft.Agents.AI.A2A` package does not bring in gRPC dependencies.
Copy file name to clipboardExpand all lines: dotnet/samples/02-agents/A2A/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ See the README.md for each sample for the prerequisites for that sample.
17
17
|[A2A Agent Skills](./A2AAgent_Skills/)|This sample demonstrates how to expose each skill advertised by an A2A agent as a separate function tool.|
18
18
|[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.|
19
19
|[A2A Agent Stream Reconnection](./A2AAgent_StreamReconnection/)|This sample demonstrates how to reconnect to an A2A agent's streaming response using continuation tokens, allowing recovery from stream interruptions.|
20
-
|[A2A Agent Protocol Selection](./A2AAgent_ProtocolSelection/)|This sample demonstrates how to select the A2A protocol binding (HTTP+JSON vs JSON-RPC) when creating an AIAgent from an A2A agent card using A2AClientOptions.|
20
+
|[A2A Agent Protocol Selection](./A2AAgent_ProtocolSelection/)|This sample demonstrates how to select HTTP+JSON, JSON-RPC, or gRPC when creating an AIAgent from an A2A agent card using A2AClientOptions.|
0 commit comments