Skip to content
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

.Net: Process mermaid flowchart code generation, image generation on flowchart and sample usage. #9705

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

joslat
Copy link
Contributor

@joslat joslat commented Nov 14, 2024

I propose adding functionality to render workflows/processes as visual diagrams, using Markdown (Mermaid syntax) and generating images. This feature would greatly aid in documenting and communicating process flows within the framework.

Motivation and Context

Why: Improved visualization and understanding of the workflow, reduce cognitive load and also it makes it cooler.
So we can visualize the Process Workflow in Step 01 (Step01_Processes) like this
image
Source and example (once merged): https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

And the "Fried Fish Preparation Process" looks like this:
image

And like this if we set the nesting to 1 (no nesting), so it does not go into a subprocess (a step which is a KernelProcess):
image
Source and example: https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/GettingStartedWithProcesses/Step03/Step03a_FoodPreparation.cs

Problem solved:
Eases understanding complex workflows, helps to validate your workflow and to improve it. Makes understanding FASTER.

Scenario: All scenarios
Related issue: #9514

Existing issue:
Usually a Step (node) has edges to other Steps which is OK.
But, in case of a Step which is a Process (ie, composed of other steps), This Step can have an Edge to an Inner Step, which makes no sense. After a great discussion with the team, @alliscode and @esttenorio (thanks a ton for the great interaction and discussion) this is done at the moment to represent Entry Steps, where the workflow is starting on the Process Step.

This made it impossible to draw this properly and is ignored, but upon discovery it was rendered like this for reference:
image

And if we debug the Edges of the Step which is a Process, we see it has two, the second one properly formed is the exit Edge but the first one on the Edge Key it does not have a properly formed EventId but a simple name:
image

This comes from the entry point defined next (Thanks @esttenorio for finding it):
image
Here is there the root process steps "links" with the internal steps of the nested process.

Which works, but we end up with a Edge from an "event" (FriedFishProcess.ProcessEvents.PrepareFriedFish) to an Internal Step.
The biggest problem here is that the Event is parentless, not associated to a Step. So, we cannot "paint" the graph to depict where does it come from.
The technical solution is to attach the Edge to the target Step, but it has no parent.

Proposal: Make all Events with a Single Parent. One Event, One Parent, point. And associate the events to that parent through an Edge. so we know where it starts and where it ends(goes). This way will enable proper tooling and accurate rendering - and the inherent graph will not try to "trick us".
(I will create an issue for this)

Solution:
At the moment we are identifying and ignoring those Edges.

Description

Added ProcessVisualizationExtensions.cs in Process.Core to render the markdown at the core, next to the ProcessBuilder, as an extension method to it.
Updated Sample 01 to showcase example, also added the MermaidRenderer.cs to render an image of this mermaid code by using PuppeteerSharp, which had to be added to the GettingStartedWithProcesses.

Contribution Checklist

@joslat joslat requested a review from a team as a code owner November 14, 2024 19:30
@markwallace-microsoft markwallace-microsoft added the .NET Issue or Pull requests regarding .NET code label Nov 14, 2024
@joslat
Copy link
Contributor Author

joslat commented Nov 25, 2024

Anybody? :)

@esttenorio
Copy link
Contributor

Anybody? :)

@joslat just reviewed this PR

@esttenorio esttenorio requested a review from crickman December 17, 2024 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement experimental Associated with an experimental feature .NET Issue or Pull requests regarding .NET code PR: ready for review All feedback addressed, ready for reviews processes
Projects
Status: Sprint: In Review
Development

Successfully merging this pull request may close these issues.

5 participants