Skip to content

Nodes

A node is a Python function that owns one unit of work. It reads state and returns an update. The function may be synchronous or asynchronous.1

def classify_ticket(state: TicketState) -> dict:
urgent = "production" in state["message"].lower()
return {"priority": "high" if urgent else "normal"}
builder.add_node("classify_ticket", classify_ticket)

Good node boundaries match failure boundaries:

  1. Read one input.
  2. Perform one understandable operation.
  3. Return a small update.

If the last operation in a large node fails, the node attempt may run again from its beginning. Separate external services into separate nodes, and make writes idempotent.2

  1. LangChain, Graph API overview.

  2. LangChain, Thinking in LangGraph.