A node is one processing step in a LangGraph workflow. It receives the current state, performs a task, and returns updates that merge into the workflow state. Nodes are usually Python functions; edges determine which node runs next. This separation is useful when an application must do more than follow a fixed sequence—for example, searching again when research results are insufficient. section 5.4 section 5.4.2 section 5.5.2
To add a node, decide:
- What state it needs. A research query generator, for example, reads the user's question. section 5.4.3
- What one task it performs and which state fields it returns. The query generator calls a query-generation function and returns search queries, rather than replacing the entire state. section 5.4.3 section 5.4.2
- How execution reaches and leaves it. Register the function with `graph.add_node(...)`, then use an edge for a fixed next step or a conditional edge to choose a path from the runtime state. section 5.4.3
A research node
`generate_search_queries(state)` reads `state["user_question"]`, generates queries, and returns `{"search_queries": queries}`. Registering it as `graph.add_node("generate_queries", generate_search_queries)` makes it a graph step. A subsequent edge can send execution to `perform_searches`; a later conditional edge can send weak results back for refinement instead of proceeding to a summary. section 5.4.3 section 5.5.2
Listing 11.8 Graph of the tool-based agent
builder = StateGraph(AgentState) #1
builder.add_node("llm_node", llm_node) #2
builder.add_node("tools", tools_execution_node) #2
builder.add_conditional_edges("llm_node",
tools_condition) #3
builder.add_edge("tools", "llm_node") #4
builder.set_entry_point("llm_node") #5
travel_info_agent = builder.compile() #6
See how a `StateGraph` registers separate LLM and tool-execution nodes, routes conditionally after the LLM, and connects tool execution back to it. section 11.3
A node need not call an LLM. In a tool-based agent, an LLM node reads messages and returns a response message; a tools node executes requested tools. A conditional edge sends tool calls to the tools node or ends the graph when no tool call is needed. A node can even be a no-op: a guardrail refusal node returns `{}` and provides a direct path to `END` after a router has prepared the refusal. Keeping tasks separate makes errors and their input data easier to locate, and nodes easier to test or change. section 11.2.6 section 11.4 section 14.2.1 section 5.5.4


















