* update a2a agent to the latest a2a sdk (#5257) * Move A2A samples from 04-hosting to 02-agents (#5267) Move the A2A sample projects (A2AAgent_AsFunctionTools and A2AAgent_PollingForTaskCompletion) from samples/04-hosting/A2A/ to samples/02-agents/A2A/ to better align with the sample directory structure. Update solution file and samples README accordingly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * .NET: Fix stream reconnection for A2AAgent (#5275) * Add SSE stream reconnection support to A2AAgent Implement automatic reconnection for SSE streams that disconnect mid-task, using the Last-Event-ID header to resume from where the stream left off. Changes: - Add InvokeStreamingWithReconnectAsync method to A2AAgent with configurable max retries and delay between attempts - Add new log messages for reconnection events - Add A2AAgent_StreamReconnection sample demonstrating the feature - Update existing polling sample to use simplified SendMessageAsync API - Add unit tests for stream reconnection logic Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * address comments * Address PR review feedback - Dispose SSE enumerator before GetTaskAsync fallback to release HTTP connection - Wrap StreamWriter in using blocks with leaveOpen:true and explicit UTF-8 encoding - Print update.Text instead of update object in stream reconnection sample Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * .NET: Use IA2AClientFactory to create A2AClient (#5277) * Refactor A2A extensions to use IA2AClientFactory and add ProtocolSelection sample - Update A2AAgentCardExtensions to accept IA2AClientFactory instead of A2AClientOptions - Update A2ACardResolverExtensions to accept IA2AClientFactory - Update A2AClientExtensions to accept IA2AClientFactory - Update A2AAgent to use IA2AClientFactory for client creation - Add A2AAgent_ProtocolSelection sample demonstrating protocol selection - Add comprehensive unit tests for all changes - Update README files with new sample reference Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Reorder params: options before loggerFactory in A2A extensions Move A2AClientOptions parameter before ILoggerFactory in AsAIAgent and GetAIAgentAsync extension methods to follow the repo convention of keeping LoggerFactory and CancellationToken as the last parameters. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * .NET: Migrate A2A hosting to A2A SDK v1 (#5363) * .NET: Migrate A2A hosting to A2A SDK v1 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * remove unused agent card --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * .NET: Split A2A endpoint mapping into protocol-specific methods (#5413) * .NET: Refactor A2A hosting registration into A2AServerServiceCollectionExtensions - Rename A2AHostingOptions to A2AServerRegistrationOptions - Move server registration logic from A2AEndpointRouteBuilderExtensions and AIAgentExtensions into new A2AServerServiceCollectionExtensions - Remove A2AProtocolBinding and AIAgentExtensions (consolidated) - Update samples and tests to use the new registration API Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * address copilot comments --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Remove unnecessary using directive in AgentWebChat.AgentHost Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * restore AsyncEnumerable package version * address copilot initial feedback * address automated code review and formatting issues * fix formatting issues * Add DI wiring verification tests for AddA2AServer Add three tests to A2AServerServiceCollectionExtensionsTests that verify custom keyed services are actually wired through to the A2AServer, not just that the server resolves non-null: - Custom IAgentHandler: verifies the keyed handler is invoked when processing a SendMessageRequest instead of the default A2AAgentHandler. - Custom AgentSessionStore (no handler): verifies the keyed session store's GetSessionAsync is called during request processing when no custom handler is registered. - Default stores end-to-end: verifies the InMemoryAgentSessionStore and InMemoryTaskStore defaults successfully process a request. Uses a new CreateAgentMockForRequests helper that includes SerializeSessionCoreAsync setup needed by InMemoryAgentSessionStore. All tests call A2AServer.SendMessageAsync directly (no HTTP layer needed) and use CancellationToken timeouts to guard against hangs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A2A Client and Server samples
Warning
The A2A protocol is still under development and changing fast. We will try to keep these samples updated as the protocol evolves.
These samples are built with official A2A C# SDK and demonstrates:
- Creating an A2A Server which makes an agent available via the A2A protocol.
- Creating an A2A Client with a command line interface which invokes agents using the A2A protocol.
The demonstration has two components:
A2AServer- You will run three instances of the server to correspond to three A2A servers each providing a single Agent i.e., the Invoice, Policy and Logistics agents.A2AClient- This represents a client application which will connect to the remote A2A servers using the A2A protocol so that it can use those agents when answering questions you will ask.
Configuring Environment Variables
The samples can be configured to use chat completion agents or Azure AI agents.
Configuring for use with Chat Completion Agents
Provide your OpenAI API key via an environment variable
$env:OPENAI_API_KEY="<Your OpenAI API Key>"
Use the following commands to run each A2A server:
Execute the following command to build the sample:
cd A2AServer
dotnet build
dotnet run --urls "http://localhost:5000;https://localhost:5010" --agentType "invoice" --no-build
dotnet run --urls "http://localhost:5001;https://localhost:5011" --agentType "policy" --no-build
dotnet run --urls "http://localhost:5002;https://localhost:5012" --agentType "logistics" --no-build
Configuring for use with Azure AI Agents
You must create the agents in a Microsoft Foundry project and then provide the project endpoint and agent IDs. The instructions for each agent are as follows:
- Invoice Agent
You specialize in handling queries related to invoices. - Policy Agent
You specialize in handling queries related to policies and customer communications. Always reply with exactly this text: Policy: Short Shipment Dispute Handling Policy V2.1 Summary: "For short shipments reported by customers, first verify internal shipment records (SAP) and physical logistics scan data (BigQuery). If discrepancy is confirmed and logistics data shows fewer items packed than invoiced, issue a credit for the missing items. Document the resolution in SAP CRM and notify the customer via email within 2 business days, referencing the original invoice and the credit memo number. Use the 'Formal Credit Notification' email template." - Logistics Agent
You specialize in handling queries related to logistics. Always reply with exactly: Shipment number: SHPMT-SAP-001 Item: TSHIRT-RED-L Quantity: 900"
$env:AZURE_AI_PROJECT_ENDPOINT="https://ai-foundry-your-project.services.ai.azure.com/api/projects/ai-proj-ga-your-project" # Replace with your Foundry Project endpoint
Use the following commands to run each A2A server
dotnet run --urls "http://localhost:5000;https://localhost:5010" --agentName "<Invoice Agent Name>" --agentType "invoice" --no-build
dotnet run --urls "http://localhost:5001;https://localhost:5011" --agentName "<Policy Agent Name>" --agentType "policy" --no-build
dotnet run --urls "http://localhost:5002;https://localhost:5012" --agentName "<Logistics Agent Name>" --agentType "logistics" --no-build
Testing the Agents using the Rest Client
This sample contains a .http file which can be used to test the agent.
- In Visual Studio open ./A2AServer/A2AServer.http
- There are two sent requests for each agent, e.g., for the invoice agent:
- Query agent card for the invoice agent
GET {{hostInvoice}}/.well-known/agent-card.json - Send a message to the invoice agent
POST {{hostInvoice}} Content-Type: application/json { "id": "1", "jsonrpc": "2.0", "method": "message/send", "params": { "id": "12345", "message": { "kind": "message", "role": "user", "messageId": "msg_1", "parts": [ { "kind": "text", "text": "Show me all invoices for Contoso?" } ] } } }
- Query agent card for the invoice agent
Sample output from the request to display the agent card:
Sample output from the request to send a message to the agent via A2A protocol:
Testing the Agents using the A2A Inspector
The A2A Inspector is a web-based tool designed to help developers inspect, debug, and validate servers that implement the Google A2A (Agent2Agent) protocol. It provides a user-friendly interface to interact with an A2A agent, view communication, and ensure specification compliance.
For more information go here.
Running the inspector with Docker is the easiest way to get started.
- Navigate to the A2A Inspector in your browser: http://127.0.0.1:8080/
- Enter the URL of the Agent you are running e.g., http://host.docker.internal:5000
- Connect to the agent and the agent card will be displayed and validated.
- Type a message and send it to the agent using A2A protocol.
- The response will be validated automatically and then displayed in the UI.
- You can select the response to view the raw json.
Agent card after connecting to an agent using the A2A protocol:
Sample response after sending a message to the agent via A2A protocol:
Raw JSON response from an A2A agent:
Configuring Agents for the A2A Client
The A2A client will connect to remote agents using the A2A protocol.
By default the client will connect to the invoice, policy and logistics agents provided by the sample A2A Server.
These are available at the following URL's:
- Invoice Agent: http://localhost:5000/
- Policy Agent: http://localhost:5001/
- Logistics Agent: http://localhost:5002/
If you want to change which agents are using then set the agents url as a space delimited string as follows:
$env:A2A_AGENT_URLS="http://localhost:5000/;http://localhost:5001/;http://localhost:5002/"
Run the Sample
To run the sample, follow these steps:
- Run the A2A server's using the commands shown earlier
- Run the A2A client:
cd A2AClient dotnet run - Enter your request e.g. "Customer is disputing transaction TICKET-XYZ987 as they claim the received fewer t-shirts than ordered."
- The host client agent will call the remote agents, these calls will be displayed as console output. The final answer will use information from the remote agents. The sample below includes all three agents but in your case you may only see the policy and invoice agent.
Sample output from the A2A client:
A2AClient> dotnet run
info: HostClientAgent[0]
Initializing Agent Framework agent with model: gpt-5.4-mini
User (:q or quit to exit): Customer is disputing transaction TICKET-XYZ987 as they claim the received fewer t-shirts than ordered.
Agent:
Agent:
Agent: The transaction details for **TICKET-XYZ987** are as follows:
- **Invoice ID:** INV789
- **Company Name:** Contoso
- **Invoice Date:** September 4, 2025
- **Products:**
- **T-Shirts:** 150 units at $10.00 each
- **Hats:** 200 units at $15.00 each
- **Glasses:** 300 units at $5.00 each
To proceed with the dispute regarding the quantity of t-shirts delivered, please specify the exact quantity issue � how many t-shirts were actually received compared to the ordered amount.
### Customer Service Policy for Handling Disputes
**Short Shipment Dispute Handling Policy V2.1**
- **Summary:** For short shipments reported by customers, first verify internal shipment records and physical logistics scan data. If a discrepancy is confirmed and the logistics data shows fewer items were packed than invoiced, a credit for the missing items will be issued.
- **Follow-up Actions:** Document the resolution in the SAP CRM and notify the customer via email within 2 business days, referencing the original invoice and the credit memo number, using the 'Formal Credit Notification' email template.
Please provide me with the information regarding the specific quantity issue so I can assist you further.