Workflow Nodes
A workflow node is a single step in the workflow graph. Each node receives state, performs an action, writes results back to state, and returns the name of the next node.
8 min•By Priygop Team•Updated 2026
Node Implementation Pattern
Node Implementation Pattern
from typing import Callable
# Standard node interface: receives state, returns next node name
NodeFn = Callable[[dict], str]
def lookup_order_node(state: dict) -> str:
"""
Node 1: Look up the order from the database.
Returns: next node name based on whether order was found.
"""
order_id = state["input"]["order_id"]
# Simulated order lookup
orders = {"ORD-123": {"total": 49.99, "days_since": 5, "status": "delivered"}}
order = orders.get(order_id)
if order:
state["data"]["order"] = order
print(f" [lookup_order] Found: $" + str(order['total']) + f", {order['days_since']} days old")
return "check_eligibility" # Next node
else:
state["data"]["error"] = f"Order {order_id} not found"
print(f" [lookup_order] Order not found")
return "notify_not_found" # Different path
def check_eligibility_node(state: dict) -> str:
"""Node 2: Check if the order is eligible for a refund."""
order = state["data"]["order"]
if order["days_since"] > 30:
state["data"]["rejection_reason"] = "Outside 30-day return window"
return "reject_refund"
elif order["total"] >= 100:
return "request_human_approval" # Large refund → human review
else:
return "issue_refund" # Small refund → auto-approve
# Define the node map
nodes = {
"lookup_order": lookup_order_node,
"check_eligibility": check_eligibility_node,
}
# Test node execution
state = {"input": {"order_id": "ORD-123", "reason": "damaged"}, "data": {}}
next_node = lookup_order_node(state)
print(f"Next node: {next_node}")
next_node = check_eligibility_node(state)
print(f"Next node: {next_node}")