mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.Net: Visualizing dotnet workflows (#882)
* Adding more test for workflow vizualization. * Improving README for sample. * More cleanup. * Removing rendering of workflow visualization and adding basic support for mermaid format. * Adding basic mermaid tests. * Improving sample. Switching to another branch. * About to merge from main. * Formatting. * More fromatting. * Removng uneeded call to ToUpper. * Adding README. * Moving samples under workflow to workflows. * Removing uneeded README for map-reduce sample.
This commit is contained in:
committed by
GitHub
Unverified
parent
522bf4bf23
commit
df3e12b2ed
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System;
|
||||
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,43 @@
|
||||
# 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.):
|
||||
|
||||

|
||||
|
||||
### DOT (Graphviz)
|
||||
Render with Graphviz (requires `graphviz` to be installed):
|
||||
|
||||
```bash
|
||||
dotnet run | tail -n +20 | dot -Tpng -o workflow.png
|
||||
```
|
||||
|
||||

|
||||
|
||||
## Usage
|
||||
|
||||
```csharp
|
||||
Workflow workflow = BuildWorkflow();
|
||||
|
||||
// Generate Mermaid format
|
||||
string mermaid = workflow.ToMermaidString();
|
||||
|
||||
// Generate DOT format
|
||||
string dotString = workflow.ToDotString();
|
||||
```
|
||||
|
||||
## Related Samples
|
||||
|
||||
- [Map-Reduce Workflow Sample](../../../Workflows/Visualization/README.md): The workflow implementation being visualized
|
||||
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>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\src\Microsoft.Agents.AI.Workflows\Microsoft.Agents.AI.Workflows.csproj" />
|
||||
<ProjectReference Include="..\Concurrent\MapReduce\MapReduce.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user