mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
6222a2cd18
* Rename MEAI.Hosting to MAAI.Hosting. * dotnet format.
41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Text.Json.Serialization;
|
|
using Microsoft.Agents.AI.Hosting;
|
|
|
|
namespace AgentWebChat.AgentHost;
|
|
|
|
internal static class ActorFrameworkWebApplicationExtensions
|
|
{
|
|
public static void MapAgentDiscovery(this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string path)
|
|
{
|
|
var routeGroup = endpoints.MapGroup(path);
|
|
routeGroup.MapGet("/", async (
|
|
AgentCatalog agentCatalog,
|
|
CancellationToken cancellationToken) =>
|
|
{
|
|
var results = new List<AgentDiscoveryCard>();
|
|
await foreach (var result in agentCatalog.GetAgentsAsync(cancellationToken).ConfigureAwait(false))
|
|
{
|
|
results.Add(new AgentDiscoveryCard
|
|
{
|
|
Name = result.Name!,
|
|
Description = result.Description,
|
|
});
|
|
}
|
|
|
|
return Results.Ok(results);
|
|
})
|
|
.WithName("GetAgents");
|
|
}
|
|
|
|
internal sealed class AgentDiscoveryCard
|
|
{
|
|
public required string Name { get; set; }
|
|
|
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
|
public string? Description { get; set; }
|
|
}
|
|
}
|