2026-06-02 15:47:49 +00:00
2026-06-02 15:47:38 +00:00
2026-06-02 15:47:44 +00:00
2026-06-02 15:47:49 +00:00

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

# 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

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.
S
Description
Экзамен: Самокорректирующийся агент
Readme
56 KiB
0 Stars 1 Watchers 0 Forks
Languages
Python 100%