-
Notifications
You must be signed in to change notification settings - Fork 682
.NET: library-first agent registration via IServiceCollection + IEndpointRouteBuilder A2A mapping (#1454) #1456
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
base: main
Are you sure you want to change the base?
Conversation
…tRouteBuilder A2A mapping Introduce library-friendly additive APIs: AddAIAgent(...) overloads on IServiceCollection (name + instructions + optional chat client / key / description) Forwarding IHostApplicationBuilder overloads (kept for compatibility) New IEndpointRouteBuilder.MapA2A(...) overloads (agentName + path, optional AgentCard or preconfigured TaskManager) – no WebApplication requirement No breaking changes; existing factory-based APIs preserved
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 adds library-first, dependency-light APIs for AI agent registration and A2A endpoint mapping. The changes enable service collection-based agent registration without requiring a full host application builder and allow A2A endpoint mapping on any IEndpointRouteBuilder.
- Adds
IServiceCollection.AddAIAgentoverloads for direct service collection configuration - Updates
IHostApplicationBuildermethods to forward to the new service collection extensions - Changes A2A mapping from
WebApplicationtoIEndpointRouteBuilderfor more flexible routing scenarios
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| HostApplicationBuilderAgentExtensions.cs | Refactored to delegate to new service collection extensions and removed duplicate validation logic |
| AgentHostingServiceCollectionExtensions.cs | Added new service collection extension methods for agent registration with various overloads |
| EndpointRouteBuilderExtensions.cs | Changed A2A mapping from WebApplication to IEndpointRouteBuilder and updated class name |
| Program.cs | Updated sample to use new service collection-based registration API |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
dotnet/src/Microsoft.Agents.AI.Hosting/HostApplicationBuilderAgentExtensions.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting/HostApplicationBuilderAgentExtensions.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting/HostApplicationBuilderAgentExtensions.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting/HostApplicationBuilderAgentExtensions.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting/HostApplicationBuilderAgentExtensions.cs
Show resolved
Hide resolved
|
@microsoft-github-policy-service agree company="ClrSlate" |
DeagleGross
left a comment
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.
Thanks for the PR!
| /// <summary> | ||
| /// Provides extension methods for configuring AI agents in a service collection. | ||
| /// </summary> | ||
| public static class AgentHostingServiceCollectionExtensions |
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.
I would call it just ServiceCollectionExtensions because of the convention
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.
And we should add tests similar to
Line 11 in 731e3a7
| public class HostApplicationBuilderAgentExtensionsTests |
| builder.AddKeyedChatClient("chat-model"); | ||
|
|
||
| builder.AddAIAgent( | ||
| builder.Services.AddAIAgent( |
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.
this (and other AddAIAgent) should not change here
feat(hosting,a2a): library-first agent registration + A2A route builder helpers (#1454)
Adds additive, dependency-light APIs:
IServiceCollection.AddAIAgentoverloads (name + instructions + optional chat client / key / description)IHostApplicationBuilderoverloads (compat only)IEndpointRouteBuilder.MapA2Aoverloads (agentName + path, optionalAgentCardor preconfiguredTaskManager) — noWebApplicationrequirementWhy:
IServiceCollectionBackward compatibility:
Testing:
Example:
Checklist: