AI Hints
Home›LangGraph Tutorial›State, Nodes and Edges
LangGraph · Lesson 6 of 120

Edges

What runs next.

⏱ 2 min read▶ Video at 5:23🎓 Free
Watch this lesson in the LangGraph courseWatch on YouTube ↗Full LangGraph course

Edges are the arrows between nodes. An edge from A to B means, when A finishes, run B. Edges turn separate functions into a process.

Edges
From the video: Edges
  • Arrows between nodes
  • A then B
  • A process

Three nodes in order

Each node prints its name, so we can see the order. The edges go from start to discount, discount to delivery, and delivery to the end. Run it. The nodes run in the order of the edges, and the final state has the discounted total, and the delivery fee.

edges.pypython
from typing import TypedDict
from langgraph.graph import StateGraph, START, END

class State(TypedDict):
    total: float
    delivery: float

def discount(state):
    print("running discount")
    return {"total": round(state["total"] * 0.9, 2)}
def delivery(state):
    print("running delivery")
    return {"delivery": 0 if state["total"] > 25 else 2.99}

builder = StateGraph(State)
builder.add_node(discount); builder.add_node(delivery)
builder.add_edge(START, "discount"); builder.add_edge("discount", "delivery")
builder.add_edge("delivery", END)
print(builder.compile().invoke({"total": 30.0}))
Output
running discount
running delivery
{'total': 27.0, 'delivery': 0}

Edge tips

When you add a node by passing just the function, its name becomes the node name. Every graph needs an edge from start. And soon, you'll meet conditional edges, which choose the next node, based on the state.

keyvalue
add_node(fn)name from function
STARTneeds one edge
ENDfinishes the run
Coming soonconditional edges

Summary

Edges connect nodes, and set the order they run in. Every graph needs an edge from start. Next, a closer look at start and end.

Key takeaways
  • add_edge(A, B)
  • Runs in order
  • Start to end
Next up: START and END — entry and exit