LangGraph Agents

Course Content

LangGraph Agents

7 sections · 49 lessons

What are nodes and edges in LangGraph, and what do they represent in execution?


Nodes compute, the edge after classify decidesclassifybill too high —lookup_accountinternet slow — troubleshootcancel — create_ticketmissing: slow after 3 fixes
Drawing the conditional edge exposed the missing route that the code review never noticed.

What you need to know

Python
from typing import TypedDictfrom langgraph.graph import StateGraph, START, ENDclass State(TypedDict):    question: str    docs: list[str]    answer: strdef retrieve(state: State) -> dict:    return {"docs": [f"policy text about {state['question']}"]}def generate(state: State) -> dict:    return {"answer": f"Based on {len(state['docs'])} document(s): ..."}builder = StateGraph(State)builder.add_node("retrieve", retrieve)builder.add_node("generate", generate)builder.add_edge(START, "retrieve")builder.add_edge("retrieve", "generate")builder.add_edge("generate", END)graph = builder.compile()print(graph.invoke({"question": "return window"}))

This runs as written. Each node reads the state and returns only its own keys.

Kinds of edges

  • Static — add_edge("a", "b"): after a, always run b.
  • Conditional — add_conditional_edges("a", route_fn, {...}): route_fn(state) returns a name, a list of names, or Send objects.
  • Several outgoing static edges — from one node to two nodes means both run in the next super-step, in parallel (fan-out).
  • Command from a node — a node can return Command(update=..., goto="b"), combining the update and the next hop.

How execution uses them

Execution is breadth-first by super-step. All nodes scheduled in a step run, their updates are merged, then edges from every node that just ran decide the next step. If two edges lead into one node from branches of equal length, that node runs once after both finish. If the branches have different lengths, it may run more than once unless you mark it defer=True.

A real-life example

A telecom support bot has five nodes: classify, lookup_account, troubleshoot, create_ticket and reply. The conditional edge after classify sends "bill too high" to lookup_account, "internet slow" to troubleshoot, and anything with the word "cancel" to create_ticket for a human retention team. When the team drew the graph with graph.get_graph().draw_mermaid(), the product manager spotted that "slow internet" users never reached create_ticket even after three failed fixes — a missing edge, found by reading the diagram rather than the code.

Follow-up questions to expect

  • "Can a node call another node?" — No. Nodes never call each other; they communicate only through state, and edges decide the order.
  • "What can a node return?" — A dict of changed keys, None for no change, or a Command that also chooses the next node.
  • "Are START and END real nodes?" — They are virtual markers. You add edges from START and to END, but they run no code.