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

first version of Workflow::to_mermaid method #296

Merged
merged 3 commits into from
Mar 11, 2025

Conversation

maximilien
Copy link
Member

@maximilien maximilien commented Mar 11, 2025

Closes issue #290

  • implements Workflow::to_mermaid
  • includes a new Mermaid class where all the code is
  • includes both mermaid markdown for sequenceDiagram and flowchart
  • includes tests

Only tested with tests/yamsl/workflows/simple_workflow.yaml but should work for the others. If not please open bug.

Also, does not include representation for loop or condition or exception or on events. I will address these in issue #297

@maximilien maximilien added the enhancement New feature or request label Mar 11, 2025
@maximilien maximilien self-assigned this Mar 11, 2025
@maximilien maximilien linked an issue Mar 11, 2025 that may be closed by this pull request
@akihikokuroda
Copy link
Collaborator

It looks good. I tried some other workflow files. Some of them got exceptions because the agent is not required in the step. Would you change the ['agent'] to .get('agent') not to cause the exception.

--- a/maestro/src/mermaid.py
+++ b/maestro/src/mermaid.py
@@ -53,15 +53,15 @@ class Mermaid:
     def __to_sequenceDiagram(self, sb):
         sb += "sequenceDiagram\n"

-        for agent in self.workflow['spec']['template']['agents']:
+        for agent in self.workflow['spec']['template'].get('agents'):
             sb += f"participant {agent}\n"

         steps, i = self.workflow['spec']['template']['steps'], 0
         for step in steps:
-            agentL = step['agent']
+            agentL = step.get('agent')
             agentR = None
             if i < (len(steps) - 1):
-                agentR = steps[i+1]['agent']
+                agentR = steps[i+1].get('agent')
             if agentR != None:
                 sb += f"{agentL}->>{agentR}: {step['name']}\n"
             else:
@@ -84,10 +84,10 @@ class Mermaid:
         steps, i = self.workflow['spec']['template']['steps'], 0

         for step in steps:
-            agentL = step['agent']
+            agentL = step.get('agent')
             agentR = None
             if i < (len(steps) - 1):
-                agentR = steps[i+1]['agent']
+                agentR = steps[i+1].get('agent')
             if agentR != None:
                 sb += f"{agentL}-- {step['name']} -->{agentR}\n"
             else:

@maximilien
Copy link
Member Author

Will do. Thx

and also updated mermaid flowchart and sequenceDiagram links
@maximilien
Copy link
Member Author

@akihikokuroda should be good to go!

Copy link
Collaborator

@akihikokuroda akihikokuroda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@akihikokuroda akihikokuroda merged commit 5f96734 into i-am-bee:main Mar 11, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to visualize the workflow using mermaid
3 participants