LangGraph¶
Code Examples¶
MessagesState vs GraphState¶
Since having a list of messages in your state is a common requirement, a prebuilt state called MessagesState is available to simplify message handling. MessagesState is defined with a single messages key, which is a list of AnyMessageobjects, and it uses the add_messages reducer for state updates.
Using MessagesState:
from langgraph.graph import StateGraph, START, END, MessagesState
graph_builder = StateGraph(MessagesState)
The StateGraph
equivalent of MessagesState
is as follows: