AI / LangGraph LangChain Interview questions
How do streaming and callbacks work in LangGraph?
LangGraph's .stream() and .astream() methods yield events as each node finishes executing, rather than waiting for the full graph to complete. The stream_mode parameter controls what is yielded.
The three main stream modes:
- stream_mode='updates' (default) — yields the state update returned by each node as
{node_name: {updated_keys}} - stream_mode='values' — yields the full state after each node runs
- stream_mode='debug' — yields detailed debug events for each step
config = {"configurable": {"thread_id": "1"}} # Stream node updates for event in graph.stream({"messages": [HumanMessage("Hello")]}, config, stream_mode="updates"): node_name, state_update = list(event.items())[0] print(f"Node '{node_name}' updated: {list(state_update.keys())}") # Stream token-by-token from LLM inside a node async for event in graph.astream_events({"messages": [...]}, config, version="v2"): if event["event"] == "on_chat_model_stream": print(event["data"]["chunk"].content, end="")
For token-level streaming from LLMs called inside nodes, use astream_events() which propagates the standard LangChain callback events (on_chat_model_stream, on_tool_start, on_tool_end) through the entire graph execution tree.
More Related questions...