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.
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...
