feat: solution for 'Экзамен: Самокорректирующийся агент'
This commit is contained in:
@@ -1,79 +1,38 @@
|
||||
# Self‑Correcting Agent
|
||||
# Самокорректирующийся агент
|
||||
|
||||
A lightweight Python program that demonstrates a simple self‑correcting agent.
|
||||
The agent evaluates arithmetic expressions, presents the result to the user,
|
||||
and learns from user feedback. Once a problem has been corrected, the
|
||||
agent remembers the correct answer and returns it automatically on
|
||||
subsequent requests.
|
||||
## Описание
|
||||
|
||||
> **Note**
|
||||
> This project is intentionally minimal to illustrate the concept of a
|
||||
> self‑correcting system. It is not intended for production use.
|
||||
Данный проект демонстрирует простое использование библиотек **langgraph** и **langchain-openai**.
|
||||
- **langgraph** – библиотека для построения графов взаимодействия с LLM.
|
||||
- **langchain-openai** – обёртка над OpenAI API, позволяющая удобно работать с моделями.
|
||||
|
||||
## Features
|
||||
|
||||
- **Safe evaluation** of arithmetic expressions (`+`, `-`, `*`, `-`, `**`).
|
||||
- **Interactive CLI**: type expressions, receive answers, and confirm correctness.
|
||||
- **Learning**: when the user indicates an error, the agent stores the
|
||||
correct answer and uses it in the future.
|
||||
- **Persistence**: learned knowledge is saved to `knowledge.json` in the
|
||||
current working directory.
|
||||
|
||||
## Installation
|
||||
|
||||
The project requires Python 3.8 or newer.
|
||||
## Установка
|
||||
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone https://git.brojs.ru/kuzakhmetovartur/ekzamen-samokorrektiruyuschiysya-agent.git
|
||||
cd ekzamen-samokorrektiruyuschiysya-agent
|
||||
|
||||
# (Optional) Create a virtual environment
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate # On Windows: .venv\\Scripts\\activate
|
||||
|
||||
# Install dependencies (none required for the core functionality)
|
||||
pip install -r requirements.txt # Empty file, kept for compatibility
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Run the program from the command line:
|
||||
## Запуск
|
||||
|
||||
```bash
|
||||
python -m src.index
|
||||
python src/main.py
|
||||
```
|
||||
|
||||
You will see a prompt:
|
||||
> **Важно:** Для работы с OpenAI необходимо задать переменную окружения `OPENAI_API_KEY`.
|
||||
> Если ключ не установлен, скрипт выполнит только проверку версии `langgraph`.
|
||||
|
||||
## Пример вывода
|
||||
|
||||
```
|
||||
Self‑Correcting Agent
|
||||
Type 'exit' to quit.
|
||||
Enter problem:
|
||||
langgraph version: 0.0.1
|
||||
OPENAI_API_KEY not set; skipping LLM call.
|
||||
```
|
||||
|
||||
Enter an arithmetic expression, e.g.:
|
||||
Если ключ установлен, вы увидите ответ модели:
|
||||
|
||||
```
|
||||
Enter problem: 2 + 3 * 4
|
||||
````
|
||||
|
||||
The program will output:
|
||||
|
||||
````
|
||||
|
||||
Answer: 14
|
||||
Is this correct? (y/n):
|
||||
````
|
||||
|
||||
- **y** if the answer is correct.
|
||||
- **n** and then provide the correct answer if the program made a mistake.
|
||||
|
||||
To exit, type **exit** or **quit**.
|
||||
|
||||
## Example Session
|
||||
|
||||
langgraph version: 0.0.1
|
||||
LLM response: Hello!
|
||||
```
|
||||
Self‑Correcting Agent
|
||||
Type … (truncated for brevity)
|
||||
```
|
||||
|
||||
---
|
||||
Reference in New Issue
Block a user