Defining Control Flow

Here are some examples of how to represent different graphs using the Vellum Workflows SDK.

Single Node Workflow

A single Node Workflow is the simplest possible Workflow, consisting of just one Node.

graph1.png

1class MyWorkflow(BaseWorkflow):
2 graph = StartNode

Serial Execution Between Two Nodes

Two Nodes connected in sequence, where the output of the first Node flows into the second Node. This is a fundamental pattern in Workflow design where a downstream operation directly depends on the output of an upstream operation.

graph2.png

1class MyWorkflow(BaseWorkflow):
2 graph = StartNode >> EndNode

Single Node Branches to Two Parallel Nodes

Here a single Node branches into two parallel execution paths, allowing multiple operations to run independently after the initial Node completes. This pattern is useful when you need to perform parallel processing or handle multiple aspects of a Workflow simultaneously.

graph3.png

1class MyWorkflow(BaseWorkflow):
2 graph = StartNode >> {
3 TopNode,
4 BottomNode,
5 }

Two Parallel Nodes Merge into One Node

Here two parallel execution paths merge back together into a single Node. This pattern is useful when you need to combine the results of multiple parallel operations before proceeding with the rest of the Workflow.

graph4.png

1class MyWorkflow(BaseWorkflow):
2 graph = StartNode >> {
3 TopNode,
4 BottomNode,
5 } >> EndNode

Loops

Loops are a powerful pattern in Workflow design that allow you to repeat a series of operations until a certain condition is met. Many agentic AI systems tend to include loops.

image.png

1class LoopNode(BaseNode):
2 class Ports(BaseNode.Ports):
3 loop = Port.on_if(Input.score.less_than(0.5))
4 exit = Port.on_else()
5
6class MyWorkflow(BaseWorkflow):
7 graph = StartNode >> {
8 LoopNode.Ports.loop >> StartNode,
9 LoopNode.Ports.exit >> ExitNode,
10 }

Map

The Map pattern is useful when you need to apply the same operation to a list of items.

image.png

1@MapNode.wrap(items=Input.items)
2class PromptNode(BaseNode):
3 ...
4
5class MyWorkflow(BaseWorkflow):
6 graph = PromptNode