-
Notifications
You must be signed in to change notification settings - Fork 1k
.NET: Executor source gen for workflow executor routing #3131
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
0ed461a to
46bb208
Compare
46bb208 to
97c7f78
Compare
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 introduces source generation for workflow executors, enabling automatic generation of route configuration code for classes decorated with [MessageHandler] attributes. The implementation includes a Roslyn incremental source generator, supporting attributes, comprehensive test infrastructure, and detailed diagnostic reporting.
Changes:
- Adds
Microsoft.Agents.AI.Workflows.Generatorsproject with incremental source generator - Introduces three new attributes:
MessageHandlerAttribute,SendsMessageAttribute, andYieldsMessageAttribute - Creates comprehensive unit test project with 20+ test cases covering various scenarios
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Microsoft.Agents.AI.Workflows.Generators.csproj | New source generator project targeting netstandard2.0 |
| ExecutorRouteGenerator.cs | Main incremental generator implementation using ForAttributeWithMetadataName |
| SemanticAnalyzer.cs | Two-phase semantic analysis for method and class validation |
| SourceBuilder.cs | Code generation for ConfigureRoutes and protocol type methods |
| DiagnosticDescriptors.cs | Seven diagnostic descriptors for validation errors |
| Models/*.cs | Value-equatable models for incremental generator caching |
| MessageHandlerAttribute.cs | Attribute to mark handler methods for route generation |
| SendsMessageAttribute.cs | Class-level attribute declaring sent message types |
| YieldsMessageAttribute.cs | Class-level attribute declaring yielded message types |
| Microsoft.Agents.AI.Workflows.Generators.UnitTests.csproj | Test project configuration |
| GeneratorTestHelper.cs | Helper utilities for testing source generators |
| ExecutorRouteGeneratorTests.cs | 20+ comprehensive test cases covering all scenarios |
| Microsoft.Agents.AI.Workflows.csproj | Updated to reference generator as analyzer |
| agent-framework-dotnet.slnx | Solution file updated with new projects |
| Directory.Packages.props | Added Microsoft.CodeAnalysis.Analyzers package version |
| Directory.Build.targets | Build configuration for handling incompatible TFMs |
| SkipIncompatibleBuild.targets | Targets to skip builds with incompatible frameworks |
| .Select(group => SemanticAnalyzer.CombineMethodResults(group)); | ||
| }); | ||
|
|
||
| // Step 3: Generate source for valid executors using the associted AnalysisResult. |
Copilot
AI
Jan 12, 2026
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.
Typo in comment: 'associted' should be 'associated'.
| // Step 3: Generate source for valid executors using the associted AnalysisResult. | |
| // Step 3: Generate source for valid executors using the associated AnalysisResult. |
3930d93 to
d675f46
Compare
This pull request introduces a new Roslyn source generator project for the Microsoft Agent Framework Workflows, enabling compile-time route configuration for executor classes using the
[MessageHandler]attribute. It includes the generator implementation, diagnostics, build configuration, and integration into the solution and dependency management.Follow-up PRs will update samples and docs to use this new pattern and obsolete the ReflectingExecutor
New Source Generator Project:
Microsoft.Agents.AI.Workflows.Generatorstargetingnetstandard2.0, with all necessary build and NuGet packaging settings, and Roslyn dependencies for source generator development. [1] [2]Source Generator Implementation:
ExecutorRouteGeneratorclass, a Roslyn incremental source generator that scans for[MessageHandler]methods and generates partial classes to configure workflow routes at compile time.SourceBuilderutility to generate the actual C# code for route configuration, including overrides forConfigureRoutes,ConfigureSentTypes, andConfigureYieldTypesas needed.Diagnostics and Analysis:
DiagnosticDescriptorsto define and register custom diagnostics for common usage errors (e.g., missing parameters, invalid return types, non-partial classes, etc.) in handler methods and executor classes.Solution and Dependency Integration:
agent-framework-dotnet.slnx). [1] [2]Directory.Packages.propsto includeMicrosoft.CodeAnalysis.Analyzersas a dependency for code analysis support.### Motivation and ContextContribution Checklist