13bc8755dee704dc68b7b64e0460ea8f6fd997a5
Human‑in‑the‑loop (interrupt / resume) – LangGraph example
What this project does
This repository contains a minimal, self‑contained example that demonstrates how to use LangGraph’s custom interrupt mechanism for Human‑in‑the‑loop (HITL). The graph pauses at a node, asks the user for confirmation via an interactive console prompt, and then resumes execution with the chosen answer.
The key concepts shown are:
- State definition – a
TypedDictthat holds data produced by the user. - Interrupt node – uses
interrupt(payload)to pause the graph. - Resume handling – the main loop detects
__interrupt__, shows a question, collects an answer and sends it back withCommand(resume=payload). - Checkpointing –
InMemorySaverkeeps the graph state so that resumption works correctly.
File structure
| File | Purpose |
|---|---|
requirements.txt |
Python dependencies (langgraph, questionary, python‑dotenv) |
main.py |
Entry point – builds and runs the graph, handles interrupts |
README.md |
Project description and usage instructions |
Installation
# Create a virtual environment (optional but recommended)
python -m venv .venv
source .venv/bin/activate # On Windows use `.venv\Scripts\activate`
# Install dependencies
pip install -r requirements.txt
Running the example
python main.py
You will see a prompt asking whether you want to continue. Choose an option and the graph will resume, printing the final state.
How it works (high‑level)
- Graph construction – two nodes:
ask_user(interrupt) andprocess_answer(continues after resume). - Interrupt payload – a dictionary with
type,question, andoptions. - Main loop – streams the graph, intercepts
__interrupt__, usesquestionary.selectto get user input, then resumes the graph with the answer attached. - Final state – after completion, the final state is printed showing the chosen value.
Extending the example
- Replace the console prompt with a web UI or chatbot interface.
- Add more nodes before/after the interrupt to build richer workflows.
- Persist checkpoints to disk using
FileSaverif you need long‑term state.
Author: Kirill Kutlakhmetov
Description
Languages
Python
100%