Files
task-6a1864fa8a94f887e50d46f0/README.md
T
2026-06-02 15:47:44 +00:00

52 lines
1.6 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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.