From 0de57659905bddfbd6d44e82cad5001fdc973457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B8=D0=BD=D0=B0=D1=80=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D0=B8=D1=82=D0=BE=D0=B2?= Date: Tue, 16 Jun 2026 12:37:59 +0000 Subject: [PATCH] Implement LangGraph reflection agent with structured critic, rewrite loop, max_rounds cap, and CLI demo logging.: update README.md --- README.md | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 606e61f..9502baa 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,44 @@ # LangGraph Reflection Agent -This repository contains a simple implementation of a LangGraph agent that writes a short answer to a question, critiques it, and rewrites if necessary. +Небольшой CLI-агент на `LangGraph`, который: -## Requirements +1. пишет первичный ответ на вопрос; +2. отдельным узлом `reflect` критикует его по полноте, конкретике и отсутствию воды; +3. при `needs_revision` запускает `rewrite`; +4. завершает работу после `ok` или по достижении `max_rounds`. + +## Установка ```bash -pip install langgraph langchain-openai +pip install -r requirements.txt ``` -## Usage +Для запуска нужен OpenAI-совместимый API: + +```bash +export OPENAI_API_KEY=... +export OPENAI_BASE_URL=... +export OPENAI_MODEL=... +``` + +## Запуск + +Запуск с вопросом из задания: ```bash python main.py "Объясни студенту разницу между tool и resource в MCP" ``` + +Запуск без аргументов использует тот же вопрос по умолчанию: + +```bash +python main.py +``` + +## Что реализовано + +- `ReflectState(TypedDict)` с полями `question`, `draft`, `critique`, `verdict`, `round`, `max_rounds` +- узлы `draft_answer`, `reflect`, `rewrite` +- цикл `rewrite -> reflect` при `needs_revision` +- ограничение числа доработок через `max_rounds` +- CLI-демо с финальным ответом, вердиктом критика и количеством раундов