Skip to content

.NET: Agent and Workflow discovery should use DI more natively #2149

@BrennanConroy

Description

@BrennanConroy

Today there is AgentCatalog and WorkflowCatalog which seem like they exist purely to get Agents and Workflows out of DI. However, the catalogs are only added to if you call builder.AddAIAgent(...), builder.Services.AddAIAgent(...), or builder.AddWorkflow(...). If you add an Agent or Workflow to DI yourself, e.g. builder.Services.AddTransient<Workflow>(...), then the Workflow or Agent isn't added to the catalog. So DevUI will fail to find AIAgents and Workflows that are added manually.

I wonder if these types should be deleted and consuming code should just use DI more natively.

For example,

private static async Task<IResult> ListEntitiesAsync(
AgentCatalog? agentCatalog,
WorkflowCatalog? workflowCatalog,
CancellationToken cancellationToken)

could be changed to

private static async Task<IResult> ListEntitiesAsync(
    IEnumerable<AIAgent> agents,
    IEnumerable<Workflow> workflows,
    IServiceProvider serviceProvider,
    CancellationToken cancellationToken)
{
    var keyedAgents = serviceProvider.GetKeyedServices<AIAgent>(KeyedService.AnyKey);
    var keyedWorkflows = serviceProvider.GetKeyedServices<Workflow>(KeyedService.AnyKey);
}

This would remove a seemingly unnecessary type from DI as well as improve DevUI's detection logic.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions