Skip to content

Conversation

@alliscode
Copy link
Member

@alliscode alliscode commented Jan 8, 2026

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:

  • Added new project Microsoft.Agents.AI.Workflows.Generators targeting netstandard2.0, with all necessary build and NuGet packaging settings, and Roslyn dependencies for source generator development. [1] [2]

Source Generator Implementation:

  • Implemented the ExecutorRouteGenerator class, a Roslyn incremental source generator that scans for [MessageHandler] methods and generates partial classes to configure workflow routes at compile time.
  • Added the SourceBuilder utility to generate the actual C# code for route configuration, including overrides for ConfigureRoutes, ConfigureSentTypes, and ConfigureYieldTypes as needed.

Diagnostics and Analysis:

  • Introduced DiagnosticDescriptors to 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:

  • Registered the new generator project and its corresponding unit test project in the solution file (agent-framework-dotnet.slnx). [1] [2]
  • Updated Directory.Packages.props to include Microsoft.CodeAnalysis.Analyzers as a dependency for code analysis support.### Motivation and Context

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation .NET workflows Related to Workflows in agent-framework labels Jan 8, 2026
@github-actions github-actions bot changed the title Initial working version with tests. .NET: Initial working version with tests. Jan 8, 2026
@alliscode alliscode changed the title .NET: Initial working version with tests. .NET: Draft- Executor source gen for workflows Jan 8, 2026
@alliscode alliscode marked this pull request as ready for review January 12, 2026 17:57
@alliscode alliscode changed the title .NET: Draft- Executor source gen for workflows .NET: Executor source gen for workflow executor routing Jan 12, 2026
Copy link
Contributor

Copilot AI left a 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.Generators project with incremental source generator
  • Introduces three new attributes: MessageHandlerAttribute, SendsMessageAttribute, and YieldsMessageAttribute
  • 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.
Copy link

Copilot AI Jan 12, 2026

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'.

Suggested change
// Step 3: Generate source for valid executors using the associted AnalysisResult.
// Step 3: Generate source for valid executors using the associated AnalysisResult.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation .NET workflows Related to Workflows in agent-framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants