Summary
The current MapAGUI extension method only accepts a pre-created AIAgent instance, which doesn't support scenarios where the agent needs to be resolved dynamically at request time (e.g., multi-tenant applications, agent selection by ID/alias from a database).
Current API
public static IEndpointConventionBuilder MapAGUI(
this IEndpointRouteBuilder endpoints,
string pattern,
AIAgent aiAgent) // Pre-created instance
Problem
For dynamic agent resolution scenarios like:
POST /agents/{agentId}/stream - resolve agent by ID from database
- Multi-tenant applications where agent configuration varies per tenant
- Agent marketplaces where users select from multiple agents
We cannot use MapAGUI because the agent must be resolved at request time, not at startup.
Additionally, the types needed to implement this ourselves are internal:
RunAgentInput - cannot use for model binding
AGUIServerSentEventsResult - cannot return from custom endpoint
This forces consumers to reimplement AG-UI request/response handling.
Proposed Solution
Add factory delegate overload
public static IEndpointConventionBuilder MapAGUI(
this IEndpointRouteBuilder endpoints,
string pattern,
Func<HttpContext, CancellationToken, Task<AIAgent?>> agentFactory)
Usage:
endpoints.MapAGUI("/agents/{agentId}/stream", async (httpContext, ct) =>
{
var agentId = httpContext.GetRouteValue("agentId")?.ToString();
return await agentResolver.ResolveAsync(agentId, ct);
});
Environment
- Package:
Microsoft.Agents.AI.Hosting.AGUI.AspNetCore v1.0.0-preview.251219.1
- Framework: .NET 10
Summary
The current
MapAGUIextension method only accepts a pre-createdAIAgentinstance, which doesn't support scenarios where the agent needs to be resolved dynamically at request time (e.g., multi-tenant applications, agent selection by ID/alias from a database).Current API
Problem
For dynamic agent resolution scenarios like:
POST /agents/{agentId}/stream- resolve agent by ID from databaseWe cannot use
MapAGUIbecause the agent must be resolved at request time, not at startup.Additionally, the types needed to implement this ourselves are
internal:RunAgentInput- cannot use for model bindingAGUIServerSentEventsResult- cannot return from custom endpointThis forces consumers to reimplement AG-UI request/response handling.
Proposed Solution
Add factory delegate overload
Usage:
Environment
Microsoft.Agents.AI.Hosting.AGUI.AspNetCorev1.0.0-preview.251219.1