
Nodes as Actions
Understanding the fundamental unit of work in a graph.
Nodes as Actions
In LangGraph, a Node is where "work" happens.
What is a Node?
A node is simply a Python function.
- Input: The current
State. - Process: Do something (call API, run computation, think).
- Output: An update to the
State.
graph LR
StateInputs[Current State] --> Node((Node Logic))
Node --> API[Call LLM/Tool]
API --> Result
Result --> StateUpdate[State Update]
Code Example
def my_node(state):
# 1. Read from State
question = state["messages"][-1]
# 2. Do Work
answer = call_llm(question)
# 3. Update State
return {"messages": [answer]}
Think of nodes as meaningful steps in a flowchart. If you would draw a box for it on a whiteboard, it should be a node.