Skip to content

Conversation

@DeagleGross
Copy link
Contributor

PR includes several things:

  1. gets rid of existing A2AHostAgent from Microsoft.Agents.AI.A2A package. The idea is to use Microsoft.Agents.AI.Hosting.A2A package instead for hosting the AIAgent via A2A protocol.
  2. introduces more granular API for MapA2A(): current A2AServer sample uses instance of AIAgent to register, so I added such API:
namespace Microsoft.AspNetCore.Builder;

public static class MicrosoftAgentAIHostingA2AEndpointRouteBuilderExtensions
{
+ public static ITaskManager MapA2A(this IEndpointRouteBuilder endpoints, AIAgent agent, string path)
+ public static ITaskManager MapA2A(this IEndpointRouteBuilder endpoints, AIAgent agent, string path, AgentCard agentCard)
}

MicrosoftAgentAIHostingA2AEndpointRouteBuilderExtensions was also:

  • changed to be an extension on top of IEndpointRouteBuilder, not WebApplicationBuilder
  • moved under Microsoft.AspNetCore.Builder namespace as per convention (as done in this PR as well: .NET: Improve fidelity of OpenAI Responses hosting #1550 (comment))
  • return type changed to ITaskManager which allows further setup. Sample uses it then to configure well-known agent-card endpoint like app.MapWellKnownAgentCard(taskManager, "/");
  1. .NET: Simplify Agent Registration & A2A Mapping (Library-Friendly Additive API Extensions) #1454 and .NET: library-first agent registration via IServiceCollection + IEndpointRouteBuilder A2A mapping (#1454) #1456 asked for change to IServiceCollection for agent registration as well, so since I am refactoring here, I decided to include this change as well.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@Copilot Copilot AI review requested due to automatic review settings October 22, 2025 10:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the A2A (Agent-to-Agent) hosting infrastructure to improve API design and align with ASP.NET Core conventions. The key changes consolidate hosting functionality into a dedicated package, introduce more flexible extension methods, and change the service registration approach to use IServiceCollection instead of IHostApplicationBuilder.

Key Changes:

  • Removes A2AHostAgent class and replaces it with extension methods in Microsoft.Agents.AI.Hosting.A2A package
  • Introduces new MapA2A() overloads that accept AIAgent instances directly and return ITaskManager
  • Migrates agent registration from IHostApplicationBuilder to IServiceCollection pattern

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
IHostedAgentBuilder.cs Changes property from IHostApplicationBuilder to IServiceCollection
HostedAgentBuilder.cs Adds constructor overload accepting IServiceCollection and delegates from IHostApplicationBuilder
HostApplicationBuilderAgentExtensions.cs Refactors to delegate all logic to new IServiceCollection extensions
AgentHostingServiceCollectionExtensions.cs New file containing all agent registration logic moved from HostApplicationBuilderAgentExtensions
WebApplicationExtensions.cs Deleted file - functionality moved to EndpointRouteBuilderExtensions.cs
EndpointRouteBuilderExtensions.cs New extension methods on IEndpointRouteBuilder with new overloads accepting AIAgent instances
A2AHostAgent.cs Deleted class - hosting logic replaced by extension methods
Program.cs (AgentWebChat.AgentHost) Removes unused namespace import
Program.cs (A2AServer) Updates to use new API pattern with MapA2A() returning ITaskManager
HostAgentFactory.cs Changes return type from A2AHostAgent to tuple (AIAgent, AgentCard)
A2AServer.csproj Adds project references for new hosting packages

@DeagleGross DeagleGross added this pull request to the merge queue Oct 23, 2025
Merged via the queue into main with commit 72c391b Oct 23, 2025
14 checks passed
@crickman crickman deleted the dmkorolev/a2ahost-removal branch October 23, 2025 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants