.NET Samples - Create 03-workflows learning path step (#4102)

This commit is contained in:
Chris
2026-02-19 13:45:25 -08:00
committed by GitHub
Unverified
parent 160cc635c1
commit eeb8644f3c
128 changed files with 444 additions and 252 deletions
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.Agents.AI.Workflows;
namespace WorkflowVisualizationSample;
/// <summary>
/// Sample demonstrating workflow visualization using Mermaid and DOT (Graphviz) formats.
/// </summary>
/// <remarks>
/// This sample shows how to use the ToMermaidString() and ToDotString() extension methods
/// to generate visual representations of workflow graphs. The visualizations can be used
/// for documentation, debugging, and understanding complex workflow structures.
/// </remarks>
internal static class Program
{
/// <summary>
/// Entry point that generates and displays workflow visualizations in Mermaid and DOT formats.
/// </summary>
/// <param name="args">Command line arguments (not used).</param>
private static void Main(string[] args)
{
// Step 1: Build the workflow you want to visualize
Workflow workflow = WorkflowMapReduceSample.Program.BuildWorkflow();
// Step 2: Generate and display workflow visualization
Console.WriteLine("Generating workflow visualization...");
// Mermaid
Console.WriteLine("Mermaid string: \n=======");
var mermaid = workflow.ToMermaidString();
Console.WriteLine(mermaid);
Console.WriteLine("=======");
// DOT
Console.WriteLine("DiGraph string: *** Tip: To export DOT as an image, install Graphviz and pipe the DOT output to 'dot -Tsvg', 'dot -Tpng', etc. *** \n=======");
var dotString = workflow.ToDotString();
Console.WriteLine(dotString);
Console.WriteLine("=======");
}
}
@@ -0,0 +1,39 @@
# Workflow Visualization Sample
This sample demonstrates how to visualize workflows using `ToMermaidString()` and `ToDotString()` extension methods. It uses a map-reduce workflow with fan-out/fan-in patterns as an example.
## Running the Sample
```bash
dotnet run
```
## Output Formats
The sample generates two visualization formats:
### Mermaid
Paste the output into any Mermaid-compatible viewer (GitHub, Mermaid Live Editor, etc.):
![Mermaid Visualization](Resources/mermaid_render.png)
### DOT (Graphviz)
Render with Graphviz (requires `graphviz` to be installed):
```bash
dotnet run | tail -n +20 | dot -Tpng -o workflow.png
```
![Graphviz Visualization](Resources/graphviz_render.png)
## Usage
```csharp
Workflow workflow = BuildWorkflow();
// Generate Mermaid format
string mermaid = workflow.ToMermaidString();
// Generate DOT format
string dotString = workflow.ToDotString();
```
Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 KiB

@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net10.0</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Microsoft.Agents.AI.Workflows\Microsoft.Agents.AI.Workflows.csproj" />
<ProjectReference Include="..\Concurrent\MapReduce\MapReduce.csproj" />
</ItemGroup>
</Project>