AI / LangGraph LangChain Interview questions
How does state management work in LangGraph?
State in LangGraph is a TypedDict that is shared across all nodes in a graph run. Every time a node executes, it can return a partial update — a dict containing only the keys it wants to change. LangGraph merges the update into the current state using reducers.
The default reducer is last-write-wins: the node's returned value replaces the current value for that key. You can override this with Annotated[type, reducer_fn] where reducer_fn takes (current, update) and returns the new value:
from typing import TypedDict, Annotated
import operator
class GraphState(TypedDict):
# Append-only: new messages are added to the list
messages: Annotated[list, operator.add]
# Last-write-wins: iteration count is replaced each time
iteration_count: int
# Custom reducer: keep the highest score seen so far
best_score: Annotated[float, lambda a, b: max(a, b)]
State is immutable between node calls — nodes receive a snapshot and return updates; they do not mutate state in place. This design enables checkpointing (save the full state after each node), time-travel debugging (replay from any past state), and parallel node execution (each branch gets a copy of the state).
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...
