Skip to content

Conversation

@halllo
Copy link

@halllo halllo commented Nov 20, 2025

Motivation and Context

The current AGUI agent mapping binds one agent to an endpoint route. There is currently no way to bind an agent dynamically to an endpoint route with route parameters.

With this change we can select an AIAgent per-request based on route parameters or anything from HttpContext.

This also addresses #2179.

Description

Additionally to providing an AIAgent instance directly during route building, we can now also provide a Func<HttpContext, AIAgent> to determine the AIAgent per-request on-demand based on route parameters or anything from HttpContext.

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 AI review requested due to automatic review settings November 20, 2025 10:03
@github-actions github-actions bot changed the title dotnet: MapAGUI supports per-request agent selection .NET: dotnet: MapAGUI supports per-request agent selection Nov 20, 2025
Copilot finished reviewing on behalf of halllo November 20, 2025 10:07
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 support for per-request agent selection to the MapAGUI endpoint routing functionality. Previously, agents were statically bound to endpoints; now, agents can be dynamically selected based on route parameters or other HttpContext data using a selector function.

Key changes:

  • Added a new MapAGUI overload that accepts a Func<HttpContext, ValueTask<AIAgent>> selector
  • Refactored the existing MapAGUI method to delegate to the new overload
  • Added sample code demonstrating dynamic agent selection using route parameters

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/AGUIEndpointRouteBuilderExtensions.cs Added new MapAGUI overload with agent selector function and refactored existing overload to use it
dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests/AGUIEndpointRouteBuilderExtensionsTests.cs Added basic test to verify endpoint mapping with agent selector function
dotnet/samples/AGUIClientServer/AGUIServer/Program.cs Added example demonstrating per-request agent selection based on route parameter
dotnet/samples/AGUIClientServer/AGUIDojoServer/Program.cs Added example demonstrating per-request agent selection with multiple agent types based on route parameter

@halllo halllo force-pushed the AGUIOnDemandAgentSelection branch from b2e6f0b to 3c8403e Compare November 20, 2025 13:33
@halllo halllo force-pushed the AGUIOnDemandAgentSelection branch from 3c8403e to 7ec1c13 Compare November 20, 2025 13:34
@halllo
Copy link
Author

halllo commented Nov 20, 2025

@microsoft-github-policy-service agree

@halllo halllo changed the title .NET: dotnet: MapAGUI supports per-request agent selection .NET: MapAGUI supports per-request agent selection Nov 20, 2025
@scrodde
Copy link

scrodde commented Nov 23, 2025

Nice, need this as well!

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.

3 participants