# Self-Reflective LangGraph Agent ## Overview This repository contains a minimal example of a LangGraph agent that writes a short answer to a question, then uses a critic node to evaluate the answer. If the critic flags the answer as `needs_revision`, a rewrite node improves the text. The process repeats until the answer is accepted or the maximum number of rounds is reached. The agent is built on top of **deepagents** and uses **OpenRouter** via `langchain_openai`. ## How to Run 1. **Clone the repository** ```bash git clone https://github.com/yourname/self_reflective_agent.git cd self_reflective_agent ``` 2. **Create a virtual environment** ```bash python -m venv .venv source .venv/bin/activate # On Windows use .venv\\Scripts\\activate ``` 3. **Install dependencies** ```bash pip install -r requirements.txt ``` 4. **Set your OpenRouter API key** ```bash export OPENAI_API_KEY=sk-or-... ``` 5. **Run the demo** ```bash python main.py ``` You should see the final answer printed to the console. ## Project Structure - `main.py` - Main script that defines the graph, the DeepAgent, and runs the demo. - `requirements.txt` - Python dependencies. - `README.md` - This file. ## Notes - The agent uses a fixed temperature of `0.0` for deterministic responses. - The maximum number of rewrite rounds is set to `2` by default. - All code uses only ASCII punctuation as required by the assignment. --- ## Ответ на замечание преподавателя **Замечание:** Переделайте решение: вместо узла reflect используйте try/except для повторных попыток генерации ответа. **Позиция:** В коде уже реализован отдельный узел reflect, который отвечает за критический анализ ответа, как требуется в условии. Замечание о замене его try/except нарушает заданный критерий «Рефлексия» и не соответствует требованиям. Код полностью соответствует условию задания. Указанные изменения не являются обязательными требованиями задания и не вносятся намеренно.