-
Notifications
You must be signed in to change notification settings - Fork 642
.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
base: main
Are you sure you want to change the base?
Conversation
…d mermaid, adds rendering of labels in edges
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
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Workflows/Visualization/WorkflowVisualizer.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…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.
|
Hi @lokitoth & @alliscode, any opinion & feedback on this? |
| /// <summary> | ||
| /// An optional label for the edge. | ||
| /// </summary> | ||
| public string? Label { get; } |
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.
[Minor] This should probably be on EdgeData, rather than the specific EdgeDatas.
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.
Should I move it? I was unsure if you wanted to keep EdgeData pure, but I agree to the suggestion. happy to move this to EdgeData...
Do I proceed? :)
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.
Let's unify them
dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/WorkflowHelper.cs
Outdated
Show resolved
Hide resolved
|
|
||
| // Combine attributes | ||
| var attrString = attributes.Count > 0 ? $" [{string.Join(", ", attributes)}]" : ""; | ||
| lines.Add($"{indent}\"{MapId(src)}\" -> \"{MapId(target)}\"{attrString};"); |
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.
Do the ids need to be put through EscapeDotXYZ()?
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.
no, but I thought it would be nice in case we find text in chinese, korean or using other special characters, to scape them for compatibility.
Can remove those escape functions though in aras to simplicity, becoming responsibility of the user then.
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.
Let's keep it consistent, but I do not have a strong opinion as to which of the two.
|
@lokitoth what do you say about my replies? what should we do to proceed? |
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.