microsoft / microsoft/agent-framework
.NET: Sub-workflow visualization shows only node, not detailing subnodes neither expand/collapse or depth control
- Dominant language
- Python
- Stars
- 13.6k
- Forks
- 2.3k
- Avg merge
- 2d 45m
- Merged PRs (30d)
- 358
Description
## Summary
When a workflow contains nested sub-workflows (via ConfigureSubWorkflow() or WorkflowExecutor), the visualization APIs (ToMermaidString(), ToDotString()) display the sub-workflow as a single opaque node without showing its internal structure.
This makes it difficult to:
• Understand hierarchical workflows - Can't see what happens inside sub-workflows
• Debug complex compositions - No visibility into nested execution paths
• Document multi-level workflows - Diagrams lack important structural details
• Trace execution flow - Can't visualize the complete processing pipeline
Desired capabilities:
1. Expand/collapse sub-workflows - Toggle between high-level and detailed views
2. Depth control - Specify how many levels deep to visualize (e.g., depth=2 shows sub-workflows but not sub-sub-workflows)
3. Visual distinction - Clearly mark which nodes are sub-workflows vs regular executors
---
## Current Behavior
Sub-workflows appear as single nodes with no indication of internal structure:
```
// Build a sub-workflow with internal structure
var subWorkflow = new WorkflowBuilder(uppercaseExecutor)
.AddEdge(uppercaseExecutor, reverseExecutor)
.AddEdge(reverseExecutor, appendExecutor)
.WithOutputFrom(appendExecutor)
.Build();
// Wrap as executor
var subWorkflowExecutor = subWorkflow.ConfigureSubWorkflow("TextProcessor");
// Use in main workflow
var mainWorkflow = new WorkflowBuilder(prefixExecutor)
.AddEdge(prefixExecutor, subWorkflowExecutor)
.AddEdge(subWorkflowExecutor, postProcessExecutor)
.Build();
// Generate visualization
Console.WriteLine(mainWorkflow.ToMermaidString());
```
Actual Output (Collapsed Only):
```
flowchart TD
PrefixExecutor["PrefixExecutor"];
TextProcessor["TextProcessor"];
PostProcessExecutor["PostProcessExecutor"];
PrefixExecutor --> TextProcessor;
TextProcessor --> PostProcessExecutor;
```
Problem: TextProcessor node shows no indication that it contains:
• UppercaseExecutor
• ReverseExecutor
• AppendSuffixExecutor
• Internal edges connecting them
Impact:
• ❌ Can't understand what TextProcessor does without reading code
• ❌ No way to visualize complete workflow structure
• ❌ Debugging nested workflows requires manual diagram creation
• ❌ Documentation lacks important structural details
---
## Expected Behavior
Automatic Inline Expansion (Depth Parameter)
Provide a depth parameter to control how many levels to expand:
```
// Depth 0: Show only main workflow (current behavior)
string collapsed = mainWorkflow.ToMermaidString(depth: 0);
// Depth 1: Expand first level of sub-workflows (show internal structure)
string expanded = mainWorkflow.ToMermaidString(depth: 1);
// Depth -1: Expand all levels recursively
string fullyExpanded = mainWorkflow.ToMermaidString(depth: -1);
```
Expected Output (Depth 1 - Expanded):
```
flowchart TD
PrefixExecutor["PrefixExecutor"];
subgraph TextProcessor["TextProcessor (Sub-Workflow)"]
UppercaseExecutor["UppercaseExecutor"];
ReverseExecutor["ReverseExecutor"];
AppendSuffixExecutor["AppendSuffixExecutor"];
UppercaseExecutor --> ReverseExecutor;
ReverseExecutor --> AppendSuffixExecutor;
end
PostProcessExecutor["PostProcessExecutor"];
PrefixExecutor --> TextProcessor;
TextProcessor --> PostProcessExecutor;
```
Rendered would look approximately like:
This would be evidently more clear and useful.
✅ Shows internal structure using Mermaid subgraph
✅ Clearly labeled as sub-workflow
✅ Maintains connection to parent workflow
---
Contributor guide
Assessment
This issue has not been assessed yet.