AI Hints
Home›LangGraph Tutorial›Running and Drawing Graphs
LangGraph · Lesson 7 of 120

START and END

Entry and exit.

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

Start and end are two special nodes. Start is where the input enters the graph. End is where a run finishes. You never write functions for them. You just connect edges to them.

START and END
From the video: START and END
  • Two special nodes
  • START: input enters
  • END: run finishes

Forgetting the start

What if we forget the edge from start? Here, we add a node, and an edge to the end, but nothing from start. Compile checks the graph, and raises an error. Run it. The message tells us exactly what's missing. The graph needs an entry point.

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

class State(TypedDict):
    text: str

def shout(state):
    return {"text": state["text"].upper()}

builder = StateGraph(State)
builder.add_node(shout)
builder.add_edge("shout", END)          # no edge from START!
try:
    builder.compile()
except ValueError as error:
    print("Compile failed:", error)
Output
Compile failed: Graph must have an entrypoint: add at least one edge from START to
another node

Start and end

Start must connect to at least one node. A run finishes when it reaches end. A graph can have several paths into end, and as we'll see, even several nodes after start, running in parallel.

keyvalue
STARTneeds an edge
ENDfinishes a run
Many pathscan reach END
Compilechecks for mistakes

Summary

Start is where input enters, and end is where a run finishes. Compile catches a missing start. Next, compiling and invoking in more detail.

Key takeaways
  • START
  • END
  • Compile checks
Next up: Compile and Invoke — running a graph