
Control Flow vs Data Flow
Separating the 'How' from the 'What'.
Control Flow vs Data Flow
In spaghetti code, data logic and control logic are mixed.
Code Comparison
Bad (Mixed Logic):
# Bad: Node decides where to go next inside its own logic
def my_node(input):
result = llm(input)
if "error" in result:
return run_retry_node(result) # Tightly coupled
return run_success_node(result)
Good (LangGraph):
# Good: Node only cares about data
def my_node(state):
result = llm(state['input'])
return {"output": result}
# Edge handles control flow
def route(state):
if "error" in state['output']:
return "retry"
return "success"
Why Separating Them Matters
- Reusability: You can reuse the "SearchNode" in 5 different graphs.
- Visual Clarity: The graph structure defines the logic, not hidden if-statements.