From 13bc8755dee704dc68b7b64e0460ea8f6fd997a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9A=D1=83=D1=82?= =?UTF-8?q?=D0=BB=D0=B0=D1=85=D0=BC=D0=B5=D1=82=D0=BE=D0=B2?= Date: Tue, 26 May 2026 13:43:26 +0000 Subject: [PATCH] add README.md --- README.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a0d540d..2b81c84 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,56 @@ -# task-69b19fbf67bbf488a1177d94 +# 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: + +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, python‑dotenv) | +| `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 (high‑level) + +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 long‑term state. + +--- + +**Author:** Kirill Kutlakhmetov