Update README.md

This commit is contained in:
2026-06-02 15:47:44 +00:00
parent 788624a6fc
commit f439088a22
+50 -2
View File
@@ -1,3 +1,51 @@
# task-6a1864fa8a94f887e50d46f0
# Selfcorrecting LangGraph Agent
Экзамен: Самокорректирующийся агент
This repository contains a small demo of a **selfcorrecting 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** lowlevel 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:
```
Selfcorrecting 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.