Sequential Workflows
A sequential workflow runs nodes one after another in a fixed order. Each node must complete before the next begins. This is the simplest and most reliable workflow pattern.
8 min•By Priygop Team•Updated 2026
Sequential Workflow Runner
Sequential Workflow Runner
# Complete sequential workflow runner
class SequentialWorkflowRunner:
def __init__(self, nodes: dict, edge_map: dict):
"""
nodes: dict of node_id -> node function
edge_map: dict of node_id -> {condition: next_node_id}
"""
self.nodes = nodes
self.edge_map = edge_map
def run(self, workflow_name: str, initial_input: dict) -> dict:
state = {
"workflow": workflow_name,
"input": initial_input,
"data": {},
"status": "running",
"step": 0,
"path": ["START"]
}
current_node = self.edge_map["START"]["*"]
while current_node not in ("END", "ERROR") and state["step"] < 20:
if current_node not in self.nodes:
state["status"] = "failed"
state["error"] = f"Node '{current_node}' not defined"
break
print(f" [{state['step']+1}] Running node: {current_node}")
try:
# Execute the node — returns a condition string
condition = self.nodes[current_node](state)
except Exception as e:
state["status"] = "failed"
state["error"] = f"Node '{current_node}' raised: {e}"
break
state["path"].append(current_node)
state["step"] += 1
# Resolve next node
transitions = self.edge_map.get(current_node, {"*": "END"})
current_node = transitions.get(condition, transitions.get("*", "END"))
state["status"] = "complete" if state["status"] == "running" else state["status"]
state["final_node"] = state["path"][-1]
return state
# Define simple nodes
def get_data(state):
state["data"]["value"] = 42
return "success"
def process_data(state):
state["data"]["result"] = state["data"]["value"] * 2
return "success"
def deliver_result(state):
print(f" Result: {state['data']['result']}")
return "done"
nodes = {"get_data": get_data, "process_data": process_data, "deliver": deliver_result}
edges = {"START": {"*": "get_data"}, "get_data": {"success": "process_data"},
"process_data": {"success": "deliver"}, "deliver": {"done": "END"}}
runner = SequentialWorkflowRunner(nodes, edges)
result = runner.run("data_pipeline", {"input_id": "X1"})
print(f"Status: {result['status']}, Path: {result['path']}")