976ed2b0b929fad62ece5f9e768e376a89daa356
LangGraph Reflection Demo
This project demonstrates a simple LangGraph agent that:
- Generates a short answer (5–10 sentences) to a user‑supplied question.
- Critiques the answer for completeness, concreteness, and fluff.
- If the critique indicates
needs_revision, rewrites the answer up to a maximum number of rounds.
Features
- Separate nodes for drafting, reflecting, and rewriting.
- LLM‑based critic that returns a verdict (
okorneeds_revision) and 2–3 critique points. - Controlled loop: rewrites only if the verdict is
needs_revisionand the round count is belowmax_rounds. - CLI interface: pass a question via
-qor input interactively. - Configurable maximum rounds via
-m(default 2).
Requirements
- Python 3.10+
langgraphlangchain-openai
Install dependencies:
pip install -r requirements.txt
Usage
- Set your OpenAI API key:
export OPENAI_API_KEY="your_api_key_here"
- Run the demo:
python src/main.py -q "Explain the difference between a tool and a resource in MCP."
Or simply:
python src/main.py
and enter the question when prompted.
The script will output the final answer, the number of rounds performed, the verdict, and the critique points.
Project Structure
src/
├── main.py # CLI entry point
├── graph.py # LangGraph definition
└── nodes.py # Node implementations
requirements.txt
README.md
License
MIT License
Languages
Python
51.9%
JavaScript
39.3%
TypeScript
8.8%