from vellum.workflows import BaseWorkflow
from vellum.workflows.nodes import BaseNode
from vellum.workflows.state import BaseState
class SourceNode(BaseNode):
pass
class MiddleNode(BaseNode):
class Ports(BaseNode.Ports):
top = Port.on_if(SourceNode.Execution.count.less_than(1))
bottom = Port.on_else()
class TargetNode(BaseNode):
pass
class MyWorkflow(BaseWorkflow):
graph = SourceNode >> {
# here we use Ports to execute the SourceNode one more time
# before proceeding to the TargetNode
MiddleNode.Ports.top >> SourceNode,
MiddleNode.Ports.bottom >> TargetNode,
}
class Outputs(BaseWorkflow.Outputs):
result = TargetNode.Outputs