pip install langgraph★Pullslanggraph-checkpoint(in-memory saver + base classes). Add a model package (langchain-openai) to call LLMs inside nodes.from langgraph.graph import StateGraph, START, END★Core builder + the two sentinel nodes.STARTis the entry,ENDis the exit.from langgraph.checkpoint.memory import InMemorySaver from langgraph.types import Command, Send, interruptPersistence + the dynamic-control primitives. Production checkpointers:langgraph-checkpoint-sqlite,-postgres.from typing import TypedDict, Annotated from langgraph.graph.message import add_messagesState is aTypedDict; reducers are attached withAnnotated. Python 3.10+.
class State(TypedDict): count: int builder = StateGraph(State)★A graph is typed by its state schema. Nodes receive the state and return a partial update.def inc(state: State): return {"count": state["count"] + 1} builder.add_node("inc", inc)★A node is any callablestate -> partial-state. The dict you return is merged into state (via reducers).builder.add_edge(START, "inc") builder.add_edge("inc", END) graph = builder.compile()★Wire the flow, thencompile()into a runnable.compile()is where you attach a checkpointer/store.graph.invoke({"count": 0}) # -> {'count': 1}★The compiled graph is a Runnable:.invoke/.stream/.batchand async.ainvoke/.astream.