Skip to content

Latest commit

 

History

History

10-A2ANet

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

A2A eShopLite Demo – Agent-to-Agent Orchestration with the Official Microsoft A2A .NET SDK

Overview

This project demonstrates a practical Agent2Agent (A2A) scenario using the eShopLite sample as a foundation. The implementation showcases how multiple autonomous agents (microservices) can collaborate to fulfill complex business requests through the official Microsoft A2A .NET SDK.


Key Features

  • A2A .NET SDK Integration: Leverages the A2A NuGet package for agent-to-agent communication.
  • Three Autonomous Agents: Inventory, Promotions, and Researcher agents, each with dedicated APIs and A2A message handlers.
  • Orchestration Service: The Products API orchestrates agent calls in parallel, aggregates results, and returns enriched product data.
  • Blazor Frontend: Store application with a search page supporting A2A search and enhanced results display.
  • Aspire Integration: Uses .NET Aspire for service orchestration and deployment.
  • Comprehensive Unit Tests: Validates A2A orchestration and agent interactions.

Architecture

High-Level Components

  1. Store (Frontend): Blazor web application providing the user interface.
  2. Products API: Main backend API that orchestrates agent communication using the A2A .NET SDK.
  3. Three Autonomous Agents:
    • Inventory Agent: Provides real-time stock levels.
    • Promotions Agent: Supplies active promotions and discounts.
    • Researcher Agent: Delivers product insights and reviews.

Architectural Diagram

┌────────────┐      ┌──────────────┐      ┌────────────────────┐
│  Store UI  │─────▶│ Products API │─────▶│  A2A Orchestration │
└────────────┘      └──────────────┘      └─────────┬──────────┘
                                                    │
        ┌───────────────────────────────┬───────────┴───────────────┐
        │                               │                           │
┌───────────────┐              ┌────────────────┐         ┌──────────────────┐
│ Inventory     │              │ Promotions     │         │ Researcher       │
│ Agent         │              │ Agent          │         │ Agent            │
└───────────────┘              └────────────────┘         └──────────────────┘

A2A Orchestration Flow

Sequence Diagram

User
 │
 │ 1. Search (A2A)
 ▼
Store (UI)
 │
 │ 2. /api/a2asearch/{search}
 ▼
Products API
 │
 │ 3. Find products
 │
 │ 4. For each product:
 │     ├─▶ InventoryAgent.HandleInventoryCheckAsync
 │     ├─▶ PromotionsAgent.HandlePromotionsAsync
 │     └─▶ ResearcherAgent.HandleInsightsAsync
 │
 │ 5. Aggregate responses
 ▼
Store (UI)
 │
 │ 6. Display enriched results

Implementation Details

  • A2A .NET SDK: GitHub | NuGet | Overview Blog
  • Agent Skills: Each agent defines its capabilities using AgentSkill.
  • Message Handling: Agents implement message handlers (e.g., HandleInventoryCheckAsync) to process A2A messages.
  • Parallel Calls: The Products API orchestrates parallel calls to all agents and aggregates their responses.
  • Service Registration: Agents and orchestration services are registered in the DI container.

Getting Started

Prerequisites

Configure Azure OpenAI secrets

This scenario reads its Azure OpenAI configuration from Aspire AppHost parameters. Set them as local secrets with the aspire secret command, targeting this scenario's AppHost project:

aspire secret set Parameters:AzureOpenAIEndpoint "https://<your-resource>.openai.azure.com/" --apphost ./src/eShopAppHost/eShopAppHost.csproj
aspire secret set Parameters:AzureOpenAIApiKey "<your-api-key>" --apphost ./src/eShopAppHost/eShopAppHost.csproj
aspire secret set Parameters:AzureOpenAIDeploymentName "gpt-4.1-mini" --apphost ./src/eShopAppHost/eShopAppHost.csproj
aspire secret set Parameters:AzureOpenAIEmbeddingsDeploymentName "text-embedding-3-small" --apphost ./src/eShopAppHost/eShopAppHost.csproj

Tip: run scripts\Set-AzureOpenAISecrets.ps1 from the repo root to set these four common Azure OpenAI values for every scenario at once (use -DryRun to preview).

Running Locally

  1. Navigate to the AppHost project:

    cd ./src/eShopAppHost/
  2. (Codespaces only) Trust HTTPS dev certs:

    dotnet dev-certs https --trust
  3. Run the solution:

    dotnet run
  4. Open the Store app in your browser, go to the Search page, select "A2A Search (Agent-to-Agent)", and search for products.

Deploying to Azure

  1. Login to Azure:

    azd auth login
  2. Provision and deploy resources:

    azd up
  3. Follow the prompts for environment name, subscription, and region.

  4. When deployment completes, visit the Store URI to use the app.


Data Model Example

{
  "response": "Found X products enriched with inventory, promotions, and insights data.",
  "products": [
    {
      "productId": "1",
      "name": "Product Name",
      "description": "Product Description",
      "price": 99.99,
      "imageUrl": "image.jpg",
      "stock": 42,
      "promotions": [
        { "title": "Special Offer", "discount": 15 }
      ],
      "insights": [
        { "review": "Great product!", "rating": 4.5 }
      ]
    }
  ]
}

References & Resources


This scenario is part of the eShopLite sample, demonstrating advanced agent orchestration patterns for .NET developers using the official A2A .NET SDK.