-
Notifications
You must be signed in to change notification settings - Fork 950
.NET: adds support for labels in edges, fixes rendering of labels in dot a… #1507
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
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
Adds edge label support across workflow data structures, builder APIs, and visualization (DOT/Mermaid), and updates tests/samples accordingly.
- Adds Label to DirectEdgeData, FanOutEdgeData, FanInEdgeData and threads it through WorkflowBuilder.
- Updates visualization: DOT escapes labels and applies dashed style for conditional edges; Mermaid renders labeled edges.
- Refactors tests and samples to new builder signatures; adds sample usage of labels.
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilder.cs | Extends AddEdge/AddFanOutEdge/AddFanInEdge with label support and propagates to edge data. |
| dotnet/src/Microsoft.Agents.AI.Workflows/Visualization/WorkflowVisualizer.cs | Emits labels for DOT and Mermaid; adds DOT label escaping; refactors ComputeNormalEdges to include labels. |
| dotnet/src/Microsoft.Agents.AI.Workflows/FanOutEdgeData.cs | Adds Label property and ctor parameter. |
| dotnet/src/Microsoft.Agents.AI.Workflows/FanInEdgeData.cs | Adds Label property and ctor parameter. |
| dotnet/src/Microsoft.Agents.AI.Workflows/DirectEdgeData.cs | Adds Label property and ctor parameter. |
| dotnet/src/Microsoft.Agents.AI.Workflows/SwitchBuilder.cs | Updates fan-out calls to include label parameter. |
| dotnet/src/Microsoft.Agents.AI.Workflows/AgentWorkflowBuilder.cs | Updates fan-out calls to include label parameter. |
| dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowVisualizerTests.cs | Adapts tests to new AddFanOutEdge/AddFanInEdge signatures. |
| dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/RepresentationTests.cs | Updates FanInEdgeData construction to include label. |
| dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/JsonSerializationTests.cs | Updates FanInEdgeData test data to include label. |
| dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/InProcessStateTests.cs | Updates fan-out call to include label parameter. |
| dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/EdgeRunnerTests.cs | Constructs FanInEdgeData with a custom label. |
| dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/EdgeMapSmokeTests.cs | Updates FanInEdgeData construction to include label. |
| dotnet/samples/GettingStarted/Workflows/_Foundational/01_ExecutorsAndEdges/Program.cs | Demonstrates labeled direct edge in sample. |
| dotnet/samples/GettingStarted/Workflows/SharedStates/Program.cs | Updates fan-out/fan-in calls to include label parameter. |
| dotnet/samples/GettingStarted/Workflows/Concurrent/MapReduce/Program.cs | Demonstrates labels on fan-out/fan-in edges. |
| dotnet/samples/GettingStarted/Workflows/Concurrent/Concurrent/Program.cs | Demonstrates labels on fan-out/fan-in edges. |
| dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/WorkflowHelper.cs | Updates fan-out/fan-in calls to include label parameter. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
dotnet/src/Microsoft.Agents.AI.Workflows/Visualization/WorkflowVisualizer.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Workflows/Visualization/WorkflowVisualizer.cs
Outdated
Show resolved
Hide resolved
|
Hi @lokitoth & @alliscode, any opinion & feedback on this? |
dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/WorkflowHelper.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Workflows/Visualization/WorkflowVisualizer.cs
Show resolved
Hide resolved
|
@lokitoth what do you say about my replies? what should we do to proceed? |
|
@lokitoth all is updated and fixed (I believe so at least ) |
…d mermaid, adds rendering of labels in edges
…wVisualizer.cs Co-authored-by: Copilot <[email protected]>
…acters that would break the diagram and enabling the previous signature so the API has backwards compatibility.
a77fc77 to
4f6b6fb
Compare
Head branch was pushed to by a user without write access
Hi @TaoChenOSU, I think the test is fixed now. Commit is in and looking forward to a successful pass now - sorry again for the delay, I basically overlooked the issue.. |
Motivation and Context
1. Why is this change required?
The workflow visualization system currently lacks support for adding labels or annotations to edges. This limitation makes it impossible to document edge purpose, data flow, or business logic directly in workflow visualizations, forcing developers to rely on external documentation or code comments.
2. What problem does it solve?
This PR solves several critical documentation and communication challenges:
Example:
Generated Mermaid code:
Rendered Mermaid:

3. What scenario does it contribute to?
Quality-based Routing:
Data Transformation Pipeline:
4. Related Issues
Fixes:
Addresses the need for edge annotations in workflow visualizations to improve documentation and diagram clarity.
Description
This PR adds comprehensive support for custom labels on workflow edges and fixes critical rendering issues in both DOT (Graphviz) and Mermaid visualization formats.
Core Changes
1. Extended Edge Data Structures
Labelproperty toDirectEdgeData,FanOutEdgeData, andFanInEdgeDatastring?type2. Enhanced WorkflowBuilder API
Extended all
AddEdgemethods with optionallabelparameter:All label parameters are optional to maintain backward compatibility.
3. Fixed Visualization Rendering
DOT (Graphviz) Format Fixes:
style=dashedMermaid Format Fixes:
4. Refactored Label Logic
ComputeNormalEdgesreturns raw label datastyle=dashedfor conditional edgesBenefits
✅ Self-documenting workflows - Purpose is clear from diagrams
✅ Better conditional clarity - Each condition has meaningful context
✅ Data flow visibility - Documents transformations at each stage
✅ Professional diagrams - Ready for stakeholders and documentation
✅ Industry standard - Uses standard "label" terminology from DOT/Mermaid
✅ Backward compatible - No breaking changes, all labels are optional
✅ Proper rendering - Fixed DOT and Mermaid syntax issues
Contribution Checklist
labelparameter is optional in all methods, and existing code without labels continues to work unchanged.