Home

Lab 4: Edges Fixed vs Conditional

Lab 5

Fixed Edges

Always the same path, regardless of input

graph.add_edge("process", "format")   always goes to format, no conditions

Conditional Edges

The path changes based on LLM classification of your input

Routing Logic

def route_by_category(state):
    category = state["category"]
    if category == "code":
        return "code_helper"
    elif category == "creative":
        return "creative_writer"
    else:
        return "math_solver"

graph.add_conditional_edges(
    "classifier",
    route_by_category
)

Key Concept: add_conditional_edges() takes a routing function that returns the name of the next node based on the current state. The graph dynamically picks a different path each time.