interrupt
function. Calling interrupt
inside a node will pause execution. Execution can be resumed, together with new input from a human, by passing in a Command. interrupt
is ergonomically similar to Python’s built-in input()
, with some caveats.
human_assistance
toolhuman_assistance
tool to the chatbot. This tool uses interrupt
to receive information from a human.
Let’s first select a chat model:
StateGraph
with an additional tool:
human_assistance
tool:
human_assistance
tool:input()
function, calling interrupt
inside the tool will pause execution. Progress is persisted based on the checkpointer; so if it is persisting with Postgres, it can resume at any time as long as the database is alive. In this example, it is persisting with the in-memory checkpointer and can resume any time if the Python kernel is running.Command
object containing data expected by the tool. The format of this data can be customized based on needs. For this example, use a dict with a key "data"
:
interrupt
to add human-in-the-loop execution to your chatbot, allowing for human oversight and intervention when needed. This opens up the potential UIs you can create with your AI systems. Since you have already added a checkpointer, as long as the underlying persistence layer is running, the graph can be paused indefinitely and resumed at any time as if nothing had happened.
Check out the code snippet below to review the graph from this tutorial: