Human-in-the-loop (interrupt / resume): README.md

This commit is contained in:
2026-05-27 11:26:47 +00:00
parent 4775411370
commit e71047aa97
@@ -0,0 +1,103 @@
# HumanintheLoop (HITL) with LangGraph
This repository contains a minimal example of how to implement a **HumanintheLoop** interruption in a LangGraph workflow.
The graph consists of a single node that triggers an interrupt, presents a question to the user via a console menu (`questionary`), receives the answer, and then resumes execution.
---
## 📦 Project Overview
- **Purpose**: Demonstrate how to pause a LangGraph flow for human input and resume it afterward.
- **Key Components**:
- `main.py`: The only script builds the graph, defines the interrupt handler, and runs the workflow.
- Uses **LangGraph** for state management and interruption handling.
- Uses **questionary** to display a CLI menu and capture user responses.
---
## ⚙️ Prerequisites
| Dependency | Minimum Version |
|------------|-----------------|
| Python | 3.10+ |
| LangGraph | Latest (pip install `langgraph`) |
| questionary| Latest (pip install `questionary`) |
> **Note**: No external services (Ollama, Qdrant, etc.) are required for this demo.
---
## 📥 Installation
```bash
# Clone the repository
git clone https://github.com/your-username/hitl-langgraph.git
cd hitl-langgraph
# Create a virtual environment (optional but recommended)
python -m venv .venv
source .venv/bin/activate # On Windows: .\.venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
```
`requirements.txt` contains:
```text
langgraph>=0.1.0
questionary>=2.0.0
```
---
## 🚀 Running the Example
The project has a single executable file: `main.py`.
```bash
python main.py
```
### What Happens?
1. The graph starts and immediately triggers an interrupt.
2. A console menu appears:
```
❓ What is your favorite programming language?
1) Python
2) JavaScript
3) Rust
4) Go
```
3. After you select an option, the workflow resumes and prints a confirmation message.
---
## 📄 Example Output
```text
$ python main.py
❓ What is your favorite programming language?
1) Python
2) JavaScript
3) Rust
4) Go
> 1
You selected: Python
Workflow finished.
```
Feel free to modify the question or options in `main.py` to suit your own use case.
---
## 📚 Further Reading
- [LangGraph Documentation](https://langgraph.org/docs/)
- [questionary Docs](https://github.com/tmbo/questionary)
Happy hacking!