-
Couldn't load subscription status.
- Fork 622
.NET: IHostedAgentBuilder overloads for workflows; simplify workflow extensions
#1731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR simplifies workflow extension methods and adds overloads for hosting extensions to accept IHostedAgentBuilder parameters. The changes eliminate the AddConcurrentWorkflow and AddSequentialWorkflow convenience methods in favor of explicit workflow configuration, while enabling callers to pass agent builders directly to mapping methods instead of repeating agent names.
Key changes:
- Removed
AddConcurrentWorkflowandAddSequentialWorkflowextension methods - Added
IHostedAgentBuilderoverloads toMapA2A,MapOpenAIChatCompletions, andMapOpenAIResponses - Updated sample code to use explicit workflow configuration and new builder-based mapping methods
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| HostApplicationBuilderWorkflowExtensionsTests.cs | Removed unit tests for deleted AddConcurrentWorkflow and AddSequentialWorkflow methods |
| HostApplicationBuilderWorkflowExtensions.cs | Deleted AddConcurrentWorkflow and AddSequentialWorkflow methods and removed unused System.Collections.Generic import |
| EndpointRouteBuilderExtensions.Responses.cs | Added IHostedAgentBuilder overloads for MapOpenAIResponses method |
| EndpointRouteBuilderExtensions.ChatCompletions.cs | Added IHostedAgentBuilder overload for MapOpenAIChatCompletions and changed return type to IEndpointConventionBuilder |
| EndpointRouteBuilderExtensions.cs | Added four new MapA2A overloads accepting IHostedAgentBuilder |
| Program.cs | Updated sample to use explicit workflow configuration and new builder-based mapping methods |
| var scienceSequentialWorkflow = builder.AddWorkflow("science-sequential-workflow", (sp, key) => | ||
| { | ||
| List<IHostedAgentBuilder> usedAgents = [chemistryAgent, mathsAgent, literatureAgent]; | ||
| var agents = usedAgents.Select(ab => sp.GetRequiredKeyedService<AIAgent>(ab.Name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to use GetRequiredKeyedService? It can't just use the AIAgent returned from AddAIAgent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AddAIAgent returns IHostedAgentBuilder which is not an actual AIAgent instance. It is a builder which has a name of registration + IHostApplicationBuilder.
I took inspiration for this pattern from Aspire's "builders" API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Aspire builders all have dependencies on DI though so you would never need to do this right? I assume the layering means we don't want to pass sp into BuildSequential to allow it to retrieve the agent so the extension methods on builder that this removes are the place we could combine both to make a convenience method that didn't require using the service provider. Why did we want to remove them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we want to remove them?
Because there's an early and steep cliff associated with them. The only two methods of this ilk that were added were for Sequential and Concurrent, which are fine for demos and some limited scenarios but which represent only a very small portion of the kinds of patterns developers need to express; even with what's on AgentWorkflowBuilder, this didn't propagate handoffs or groupchat, nevermind everything you can expresson WorkflowBuilder, with custom edges and conditional edges and fan in/out and so on. I don't think we should try to propagate all of that surface area to live on these hosting builders, and should instead ensure it's easy to register any workflow.
2 intentions here:
AddConcurrentWorkflowandAddSequentialWorkflowas per .NET: Add DevUI package for .NET #1603 (comment)IHostedAgentBuilder- this avoids need of copying the name of agent in registration+Map... methods.