Skip to content

Python: .NET: Executor source gen for workflow executor routing - #3131

Merged
Ben Thomas (alliscode) merged 8 commits into
microsoft:mainfrom
alliscode:wf-source-gen
Jan 22, 2026
Merged

Ben Thomas (alliscode) merged 8 commits into
microsoft:mainfrom
alliscode:wf-source-gen

Conversation

@alliscode

@alliscode Ben Thomas (alliscode) commented Jan 8, 2026 •

Copy link
Copy Markdown
Member

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 Mark Wallace (markwallace-microsoft) added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows 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 Ben Thomas (alliscode) changed the title .NET: Initial working version with tests. .NET: Draft- Executor source gen for workflows Jan 8, 2026
@alliscode
Ben Thomas (alliscode) marked this pull request as ready for review January 12, 2026 17:57
@markwallace-microsoft Mark Wallace (markwallace-microsoft) added python Usage: [Issues, PRs], Target: Python lab labels Jan 16, 2026
@github-actions github-actions Bot changed the title .NET: Executor source gen for workflow executor routing Python: .NET: Executor source gen for workflow executor routing Jan 16, 2026
@alliscode
Ben Thomas (alliscode) added this pull request to the merge queue Jan 21, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 21, 2026
@alliscode
Ben Thomas (alliscode) added this pull request to the merge queue Jan 21, 2026
github-merge-queue Bot pushed a commit that referenced this pull request Jan 21, 2026
* Roslyn Source Generators for Workflow Executor Routing.

* Update dotnet/src/Microsoft.Agents.AI.Workflows.Generators/ExecutorRouteGenerator.cs

Co-authored-by: Copilot <[email protected]>

* WIP.

* All fixed up except dangling sends/yields attriutes, working on that next.

* Add protocol-only generation for SendsMessage/YieldsOutput attributes

* Ensuring collections that can change order are sorted to enable pipeline caching.

* Improvents per PR feedback.

---------

Co-authored-by: alliscode <[email protected]>
Co-authored-by: Copilot <[email protected]>
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 21, 2026

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net python Usage: [Issues, PRs], Target: Python workflows Usage: [Issues, PRs], Target: Workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants