
LANGCHAIN — Is Human-in-the-Loop Possible with OpenGPTs and LangGraph?
The most profound technologies are those that disappear. They weave themselves into the fabric of everyday life until they are indistinguishable from it. — Mark Weiser.
Human-in-the-loop with OpenGPTs and LangGraph
Today, we’re introducing two “human in the loop” features in OpenGPTs, Interrupt and Authorize, both powered by LangGraph. LangGraph is a library created to assist developers in constructing multi-actor, multi-step, stateful LLM applications. Let’s dive into each feature.
Multi-actor
A team of specialists can build something together that none of them could build alone. Similarly, combining an LLM with a search engine in novel ways can lead to the creation of powerful applications.
# Define actors
actors = {
"LLM": LLM_actor,
"search_engine": search_engine_actor
}
# Define work handoff
work_handoff = {
"LLM": "search_engine",
"search_engine": "LLM"
}
# Schedule execution
schedule_execution(actors, work_handoff)Multi-step
Model the interaction between actors as happening across multiple discrete steps, ensuring proper coordination and order of actions.
# Define multi-step interactions
for step in range(total_steps):
actor1_work = actor1.handle_work()
actor2_work = actor2.handle_work(actor1_work)Stateful
Communication across steps implies updating of some state, and a single central state helps in collaboration and easy snapshotting.
# Update central state
central_state.update(actor1_state)
central_state.update(actor2_state)
# Snapshot central state
snapshot_state(central_state)Human-in-the-loop
A shared state makes the process easier to observe, interrupt, and modify. LangGraph introduces support for two forms of Human in the Loop in OpenGPTs: Interrupt and Authorize.
Interrupt
The Interrupt mode allows the user to manually interrupt the application and choose to resume from that point onwards, send new input, or take no action.
# Implement Interrupt mode
def on_interrupt():
# Save state
save_state()
# User actions
if user_action == "resume":
resume_computation()
elif user_action == "send_new_input":
send_new_input()
else:
do_nothing()Authorize
In the Authorize mode, the user can define ahead of time that they want the application to hand off control to them every time a particular actor is about to be called.
# Implement Authorize mode
def authorize_tool_call():
if user_confirms_tool_call:
resume_computation()
elif user_sends_new_message:
send_new_message()
else:
do_nothing()Where to find this?
You can find an example notebook for building your own LangGraph application with Human-in-the-loop controls here.
In conclusion, with the introduction of Interrupt and Authorize modes in OpenGPTs, powered by LangGraph, human-in-the-loop control is now possible, providing users with a more interactive and supervisory role in the application’s processes.





