# Self‑correcting LangGraph Agent This repository contains a small demo of a **self‑correcting LangGraph agent**. The agent receives a *task* string, executes it via an unreliable tool, then asks an LLM to judge the result. If the judge says the result is **failed**, the agent retries until it reaches a maximum number of attempts. ## Features - **Unreliable tool** – 30 % chance of raising an exception. - **LLM judge** – forces the model to answer only `success` or `failed`. - **Retry logic** – automatically retries until success or a maximum number of attempts. - **LangGraph** – low‑level graph with three nodes: `execute_task`, `verify_result`, `handle_error`. ## Setup ```bash # Optional: create a virtual environment python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate # Install dependencies pip install -r requirements.txt ``` ## Running the Agent ```bash python agent.py ``` You will be prompted to enter a task. The agent will then perform the task, verify the result, and retry if necessary. Example output: ``` Self‑correcting LangGraph agent demo Enter a task: 2+2 --- Result --- Task: 2+2 Attempts: 2 Status: success Result: 22 ``` ## Project Structure - `agent.py` – main implementation. - `README.md` – this documentation. - `requirements.txt` – Python dependencies. ## Notes - The LLM used is OpenAI's `gpt-4o-mini`. If you prefer Ollama, change the `ChatOpenAI` import to `ChatOllama` and adjust the model name accordingly. - The unreliable tool is a toy example; replace it with a real tool for production use.