LangGraphLangGraph 1.2 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
38 small wins to finish your pathNext lesson →

add_edge: two steps in a row

An edge is a connection between two nodes: add_edge(a, b) tells LangGraph that node b runs after node a.

Last updated: 27 Sep, 2026 · LangGraph 1.2

One node is not a program. The moment you have two, you have to say which runs first, and an edge is how you say it. The second node can then read what the first one wrote to the state.

The add_edge call

python
from langgraph.graph import START, END

builder.add_edge(START, "first")     # the run begins at "first"
builder.add_edge("first", "second")  # "second" runs after "first"
builder.add_edge("second", END)      # the run ends after "second"

The state

Describe a state with three keys: the ticket in, the category the first node writes, and the reply the second node writes.

python
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START

class State(TypedDict):
    ticket: str
    category: str
    reply: str

The categorise node

The first node sets the category.

python
def categorise(state):
    return {"category": "billing"}

The write_reply node

The second node reads that category from the state and writes a reply that uses it.

python
def write_reply(state):
    # read category from the state the first node wrote
    return {"reply": f"Sending this to our {state['category']} team."}

Wiring the edge

Register both nodes, then add the edge that puts categorise before write_reply.

python
builder = StateGraph(State)
builder.add_node("categorise", categorise)
builder.add_node("write_reply", write_reply)
builder.add_edge(START, "categorise")
builder.add_edge("categorise", "write_reply")   # categorise runs first, then write_reply
graph = builder.compile()

Running the graph

Run it and print the reply key from the final state.

python
print(graph.invoke({"ticket": "charged twice", "category": "", "reply": ""})["reply"])

Two nodes in a row

The same pieces in one file, ready to run.

Example
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START

class State(TypedDict):
    ticket: str
    category: str
    reply: str

def categorise(state):
    return {"category": "billing"}

def write_reply(state):
    return {"reply": f"Sending this to our {state['category']} team."}

builder = StateGraph(State)
builder.add_node("categorise", categorise)
builder.add_node("write_reply", write_reply)
builder.add_edge(START, "categorise")
builder.add_edge("categorise", "write_reply")
graph = builder.compile()

print(graph.invoke({"ticket": "charged twice", "category": "", "reply": ""})["reply"])

How the value crossed the edge

  • The second add_edge is the new part: it is the only thing that says categorise runs before write_reply.
  • The word billing was not written by write_reply. It came out of the state, where categorise put it a moment earlier.
  • Passing values between nodes through the state is the whole point of an edge.

When one step feeds the next

  • Any flow with more than one step: classify then reply, retrieve then answer, validate then act.
  • Whenever a later step needs something an earlier step worked out.
Watch out. Swapping the two add_node lines changes nothing. Nodes are only registered by name; the edges decide the order.
Try it yourself
  • Add a third node log after write_reply that prints the reply. Wire the edge.
  • Remove the categorise → write_reply edge and run it. What is in reply now?
  • Swap the two add_node lines and confirm the output does not change.

Every expert started right here.