feat: solution for 'Практическое задание №3: Память и подтверждение действий'

This commit is contained in:
2026-06-24 15:49:40 +03:00
parent af6701671b
commit ddd2bdb8a9
3 changed files with 99 additions and 131 deletions
+40 -25
View File
@@ -1,33 +1,48 @@
# Практическое задание №3: Память и подтверждение действий
# Interactive LangGraph Agent with Memory and Tool Confirmation
Главная
Мои задания
Практическое задание №3: Память и подтверждение действий
EN
Практическое задание №3: Память и подтверждение действий
Зачёт
Версия 4
Дедлайн сдачи: 31.08.2026
This project demonstrates a simple interactive agent built with LangGraph that:
- Maintains conversation memory across turns.
- Pauses before invoking tools and asks the user for confirmation.
- Uses the `rich` library for pretty console output.
В работе
## Prerequisites
Редактирование ответа
- Python 3.10 or newer
- An OpenAI API key (set as the environment variable `OPENAI_API_KEY`)
Заполните ответ и отправьте работу на проверку преподавателю.
## Installation
Тип ответа
Текст
Ссылка
Файлы
Ссылка (URL)
Прикреплённые файлы
Загрузить файл
Отправить на проверку
Отменить
```bash
# Clone the repository
git clone https://github.com/yourusername/langgraph-agent.git
cd langgraph-agent
Задание
# Create a virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
Цель
# Install dependencies
pip install -r requirements.txt
```
Доработать агента из предыдущих заданий: добавить память разговора и механизм подтверждения каждо
## Usage
```bash
# Ensure your OpenAI API key is set
export OPENAI_API_KEY="sk-..."
# Run the agent
python src/main.py
```
You will see a prompt where you can type messages. The agent will respond, and if it needs to use the calculator tool, it will pause and ask for your confirmation before executing the tool.
Type `exit` to quit the program.
## How It Works
- **Memory**: `MemorySaver` stores the conversation history, allowing the agent to remember previous messages.
- **Interrupt Before Tool Calls**: The agent is configured with `interrupt_before=['tools']`, causing it to pause before calling any tool.
- **User Confirmation**: When the agent pauses, it prints the pending tool call and asks you whether to proceed. If you confirm, the agent resumes; otherwise, the tool call is cancelled.
Feel free to extend the toolset or modify the system prompt to suit your needs.