AI / LangGraph LangChain Interview questions
How do you implement human-in-the-loop with LangGraph?
Human-in-the-loop (HITL) in LangGraph means pausing graph execution at a specified point so a human can inspect the current state, approve an action, or modify a value before the graph continues. This is a first-class LangGraph feature built on top of checkpointing.
Step 1: Compile the graph with interrupt_before or interrupt_after
from langgraph.checkpoint.memory import MemorySaver
graph = graph_builder.compile(
checkpointer=MemorySaver(),
interrupt_before=["tool_executor"], # pause before this node runs
)
Step 2: Run until the interrupt
config = {"configurable": {"thread_id": "session-1"}}
for event in graph.stream({"messages": [HumanMessage("Search for X")]}, config):
print(event) # stops before tool_executor
Step 3: Inspect and optionally update state
current_state = graph.get_state(config)
print(current_state.values) # see what the agent is about to do
# Optionally modify the state before continuing:
graph.update_state(config, {"messages": [HumanMessage("Actually search for Y")]}, as_node="agent")
Step 4: Resume execution
# Pass None as input to resume from the checkpoint
for event in graph.stream(None, config):
print(event)
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...
