Files
agent-framework/dotnet/samples/AgentWebChat/AgentWebChat.Web/AgentDiscoveryClient.cs
T
Aditya Mandaleeka 6222a2cd18 .NET: Change Hosting namespaces to Microsoft.Agents.AI.Hosting (#953)
* Rename MEAI.Hosting to MAAI.Hosting.

* dotnet format.
2025-09-26 22:32:53 +00:00

29 lines
1019 B
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Text.Json;
using Microsoft.Agents.AI.Hosting;
namespace AgentWebChat.Web;
public class AgentDiscoveryClient(HttpClient httpClient, ILogger<AgentDiscoveryClient> logger)
{
public async Task<List<AgentDiscoveryCard>> GetAgentsAsync(CancellationToken cancellationToken = default)
{
var response = await httpClient.GetAsync(new Uri("/agents", UriKind.Relative), cancellationToken);
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync(cancellationToken);
var agents = JsonSerializer.Deserialize<List<AgentDiscoveryCard>>(json, AgentHostingJsonUtilities.DefaultOptions) ?? [];
logger.LogInformation("Retrieved {AgentCount} agents from the API", agents.Count);
_ = new HttpActorClient(null!);
return agents;
}
public class AgentDiscoveryCard
{
public string? Name { get; set; }
public string? Description { get; set; }
}
}