-
Notifications
You must be signed in to change notification settings - Fork 589
.NET: Refactor A2A and AIAgent hosting extensions #1625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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
A2AHostAgentclass and replaces it with extension methods inMicrosoft.Agents.AI.Hosting.A2Apackage - Introduces new
MapA2A()overloads that acceptAIAgentinstances directly and returnITaskManager - Migrates agent registration from
IHostApplicationBuildertoIServiceCollectionpattern
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 |
PR includes several things:
A2AHostAgentfromMicrosoft.Agents.AI.A2Apackage. The idea is to useMicrosoft.Agents.AI.Hosting.A2Apackage instead for hosting theAIAgentvia A2A protocol.MapA2A(): currentA2AServersample uses instance ofAIAgentto 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) }MicrosoftAgentAIHostingA2AEndpointRouteBuilderExtensionswas also:IEndpointRouteBuilder, notWebApplicationBuilderMicrosoft.AspNetCore.Buildernamespace as per convention (as done in this PR as well: .NET: Improve fidelity of OpenAI Responses hosting #1550 (comment))ITaskManagerwhich allows further setup. Sample uses it then to configure well-known agent-card endpoint likeapp.MapWellKnownAgentCard(taskManager, "/");IServiceCollectionfor agent registration as well, so since I am refactoring here, I decided to include this change as well.Contribution Checklist