Skip to content

.NET: [Bug]: builder.AddWorkflow(“some-name”) triggers error System.InvalidOperationException: The workflow factory returned workflow with name '', but the expected name is 'some-name'. #5791

@hansmbakker

Description

@hansmbakker

Description

I created an Agent Service in .NET Aspire by creating an ASP.NET Core API project with OpenAI endpoints and by registering agents and a workflow exposed as agent.

I followed https://learn.microsoft.com/en-us/agent-framework/get-started/hosting?pivots=programming-language-csharp#core-hosting-library for the steps regarding the dependency injection registration.

I registered my workflow as an agent according to the examples on that page.

AgentWorkflowBuilder.CreateHandoffBuilderWith(agent) does not allow specifying a name, but apparently builder.AddWorkflow(name, delegate) checks for the configured name.

The Name property of Workflow is get-only (it can only be set during via init) and there is no setter.

Code Sample

builder.AddWorkflow("travel-booking-workflow", (sp, key) =>
         {
             var hotelAgent = sp.GetRequiredKeyedService<AIAgent>("HotelReservationAgent");
             var rideAgent = sp.GetRequiredKeyedService<AIAgent>("TransportationAgent");
             var travelAgent = sp.GetRequiredKeyedService<AIAgent>("TravelConciergeAgent");
#pragma warning disable MAAIW001 // This demo is specifically to show handoffs
             return AgentWorkflowBuilder
                .CreateHandoffBuilderWith(travelAgent)
                .WithHandoff(travelAgent, rideAgent, "Book a ride to the concert")
                .WithHandoff(travelAgent, hotelAgent, "Book a hotel room")
                .WithHandoffs(rideAgent, [travelAgent, hotelAgent])
                .WithHandoffs(hotelAgent, [travelAgent, rideAgent])
                .EnableReturnToPrevious()
                .Build();
#pragma warning restore MAAIW001
         }).AddAsAIAgent(agentName);

Error Messages / Stack Traces

> System.InvalidOperationException: The workflow factory returned workflow with name '', but the expected name is 'travel-booking-workflow'.

Package Versions

Microsoft.Agents.AI: 1.5.0

.NET Version

.NET 10.0

Additional Context

This issue was already posted before in several issues, and seems to have been ignored after #1885 was marked Closed without being fully fixed.

Metadata

Metadata

Assignees

Labels

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions