Files
agent-framework/dotnet/samples/AgentWebChat/AgentWebChat.Web/AgentDiscoveryClient.cs
T
Reuben Bond e7441ee29e .NET: Add agent hosting package and update sample (#296)
* Add agent hosting package and update sample

* Review feedback and cleanup

* Include the narrator

* wip

* wip

* Remove workaround for empty state writes.

* Handle changes to AgentThread.

* One more.

* Fix.

---------

Co-authored-by: Aditya Mandaleeka <adityam@microsoft.com>
2025-08-06 21:26:36 +00:00

29 lines
1.0 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Text.Json;
using Microsoft.Extensions.AI.Agents.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; }
}
}