add README.md

This commit is contained in:
2026-05-26 13:43:26 +00:00
parent 3adafc9091
commit 13bc8755de
+55 -1
View File
@@ -1,2 +1,56 @@
# task-69b19fbf67bbf488a1177d94
# Humanintheloop (interrupt / resume) LangGraph example
## What this project does
This repository contains a minimal, selfcontained example that demonstrates how to use **LangGraph**s custom interrupt mechanism for *Humanintheloop* (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:
1. **State definition** a `TypedDict` that holds data produced by the user.
2. **Interrupt node** uses `interrupt(payload)` to pause the graph.
3. **Resume handling** the main loop detects `__interrupt__`, shows a question, collects an answer and sends it back with `Command(resume=payload)`.
4. **Checkpointing** `InMemorySaver` keeps the graph state so that resumption works correctly.
## File structure
| File | Purpose |
|------|---------|
| `requirements.txt` | Python dependencies (langgraph, questionary, pythondotenv) |
| `main.py` | Entry point builds and runs the graph, handles interrupts |
| `README.md` | Project description and usage instructions |
## Installation
```bash
# 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
```bash
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 (highlevel)
1. **Graph construction** two nodes: `ask_user` (interrupt) and `process_answer` (continues after resume).
2. **Interrupt payload** a dictionary with `type`, `question`, and `options`.
3. **Main loop** streams the graph, intercepts `__interrupt__`, uses `questionary.select` to get user input, then resumes the graph with the answer attached.
4. **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 `FileSaver` if you need longterm state.
---
**Author:** Kirill Kutlakhmetov