Skip to content

Conversation

@jst4upiyush
Copy link

feat(hosting,a2a): library-first agent registration + A2A route builder helpers (#1454)

Adds additive, dependency-light APIs:

  • IServiceCollection.AddAIAgent overloads (name + instructions + optional chat client / key / description)
  • Forwarding IHostApplicationBuilder overloads (compat only)
  • IEndpointRouteBuilder.MapA2A overloads (agentName + path, optional AgentCard or preconfigured TaskManager) — no WebApplication requirement

Why:

  • Library-first scenarios often only depend on IServiceCollection
  • Reduce boilerplate (common case no longer needs factory delegate)
  • Enable modular A2A mapping inside grouped endpoints

Backward compatibility:

  • No removals or behavior changes; existing factory APIs preserved
  • Potential future deprecation path for host builder variants

Testing:

  • Full solution builds (Release) & existing unit/integration tests pass locally

Example:

// Library or startup
services.AddAIAgent("support-bot", "You are a helpful assistant.");

services.AddAIAgent(
    name: "pricing",
    instructions: "Answer pricing questions precisely.",
    description: "Handles SKU + tier pricing queries.",
    chatClientServiceKey: "gpt-4o");

// In endpoint config
var a2aGroup = app.MapGroup("/a2a");
a2aGroup.MapA2A("support-bot", "/support");
a2aGroup.MapA2A("pricing", "/pricing", new AgentCard { Name = "Pricing", Description = "Pricing specialist" });

Checklist:

  • Add IServiceCollection overloads
  • Forward host builder overloads
  • Add A2A route builder mapping
  • Preserve factory-based APIs
  • Build + tests pass

…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
Copilot AI review requested due to automatic review settings October 14, 2025 15:06
@github-actions github-actions bot changed the title library-first agent registration via IServiceCollection + IEndpointRouteBuilder A2A mapping (#1454) .NET: library-first agent registration via IServiceCollection + IEndpointRouteBuilder A2A mapping (#1454) Oct 14, 2025
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 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.AddAIAgent overloads for direct service collection configuration
  • Updates IHostApplicationBuilder methods to forward to the new service collection extensions
  • Changes A2A mapping from WebApplication to IEndpointRouteBuilder for 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.

@jst4upiyush
Copy link
Author

@microsoft-github-policy-service agree company="ClrSlate"

Copy link
Contributor

@DeagleGross DeagleGross left a 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
Copy link
Contributor

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

Copy link
Contributor

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

builder.AddKeyedChatClient("chat-model");

builder.AddAIAgent(
builder.Services.AddAIAgent(
Copy link
Contributor

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

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.

4 participants