feat: solution for 'Практическое задание №3: Память и подтверждение действий'
This commit is contained in:
@@ -1,62 +1,33 @@
|
|||||||
# LangGraph Agent with Memory and Tool Confirmation
|
# Практическое задание №3: Память и подтверждение действий
|
||||||
|
|
||||||
This project demonstrates a simple conversational agent built with **LangGraph** that:
|
Главная
|
||||||
|
Мои задания
|
||||||
|
Практическое задание №3: Память и подтверждение действий
|
||||||
|
5Д
|
||||||
|
EN
|
||||||
|
Практическое задание №3: Память и подтверждение действий
|
||||||
|
Зачёт
|
||||||
|
Версия 4
|
||||||
|
Дедлайн сдачи: 31.08.2026
|
||||||
|
|
||||||
- **Remembers** the conversation history across turns using an in‑memory checkpoint.
|
В работе
|
||||||
- **Pauses** before invoking any tool, asking the user for confirmation.
|
|
||||||
- Uses the **Rich** library for pretty console output.
|
|
||||||
|
|
||||||
## Prerequisites
|
Редактирование ответа
|
||||||
|
|
||||||
- Python 3.10+
|
Заполните ответ и отправьте работу на проверку преподавателю.
|
||||||
- An OpenAI API key (set as the `OPENAI_API_KEY` environment variable).
|
|
||||||
|
|
||||||
## Installation
|
Тип ответа
|
||||||
|
Текст
|
||||||
|
Ссылка
|
||||||
|
Файлы
|
||||||
|
Ссылка (URL)
|
||||||
|
Прикреплённые файлы
|
||||||
|
Загрузить файл
|
||||||
|
Отправить на проверку
|
||||||
|
Отменить
|
||||||
|
|
||||||
```bash
|
Задание
|
||||||
# Clone the repository (or copy the files)
|
|
||||||
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
|
|
||||||
python src/main.py
|
|
||||||
```
|
|
||||||
|
|
||||||
You will see a prompt:
|
|
||||||
|
|
||||||
```
|
|
||||||
Start chat. Type 'exit' to quit.
|
|
||||||
You:
|
|
||||||
```
|
|
||||||
|
|
||||||
Type any message. If the agent decides to use a tool (e.g., the `echo` tool), it will pause and ask:
|
|
||||||
|
|
||||||
```
|
|
||||||
Agent wants to call tool: echo({"text":"Hello"})
|
|
||||||
Разрешить? (Y/n):
|
|
||||||
```
|
|
||||||
|
|
||||||
- Type `Y` or press Enter to allow the tool to run.
|
|
||||||
- Type `n` to cancel the tool call.
|
|
||||||
|
|
||||||
The conversation history is preserved across turns, so the agent can refer back to earlier messages.
|
|
||||||
|
|
||||||
## Customizing
|
|
||||||
|
|
||||||
- **Tools**: Add more tools by defining functions decorated with `@tool` from `langchain.tools`.
|
|
||||||
- **Memory**: Replace `MemorySaver()` with a persistent checkpoint (e.g., `RedisSaver`) for long‑term storage.
|
|
||||||
- **Prompt**: Modify the `system_prompt` in `create_agent` to change the agent’s behavior.
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
MIT License
|
|
||||||
Reference in New Issue
Block a user