AI / LangGraph LangChain Interview questions
What is the difference between MessageGraph and StateGraph?
MessageGraph is a specialised version of StateGraph where the entire state is a single list of messages (using the add_messages reducer). Nodes receive the message list and return new messages to append. StateGraph is the general-purpose graph where you define any TypedDict as the state, with full control over all fields and their reducers.
| Feature | MessageGraph | StateGraph |
|---|---|---|
| State structure | Always a list of BaseMessage objects | Any TypedDict with any fields |
| Node input | List of messages | Full state dict |
| Node output | One or more messages to append | Partial dict of any fields to update |
| Custom fields | Not supported | Any fields: scores, iteration counts, flags, etc. |
| Status | Simpler but less flexible | Recommended for all but trivial chatbots |
from langgraph.graph import MessageGraph
# MessageGraph - state is just the messages list
graph = MessageGraph()
graph.add_node("model", lambda msgs: llm.invoke(msgs))
graph.set_entry_point("model")
graph.set_finish_point("model")
MessageGraph was the original LangGraph API and is still useful for pure chatbot flows with no additional state. For anything more complex, StateGraph with Annotated[list, add_messages] for the messages field is preferred because it lets you add other state fields alongside the conversation history.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
