Rewrite: agent with MemorySaver and interrupt_before tools

This commit is contained in:
2026-05-12 10:52:54 +03:00
parent c8f41b250f
commit 9b1e8fabbe
3 changed files with 178 additions and 23 deletions
+19 -2
View File
@@ -1,3 +1,20 @@
# Praticial 3:
# Практическое задание №3: Память и подтверждение действий
Testing main code - Memory and HTML include and recommendation of tools.
Агент с памятью разговора и механизмом подтверждения вызова инструментов.
## Что реализовано
1. **Память**`MemorySaver` + `thread_id="разговор-1"` — агент помнит контекст
2. **Пауза перед инструментом**`interrupt_before=['tools']` в `create_react_agent`
3. **Обнаружение паузы** — ловим `__interrupt__` в стриме, проверяем `state.next == ('tools',)`
4. **Просмотр вызова**`state.values['messages'][-1].tool_calls[0]`
5. **Возобновление/отмена** — Y для продолжения, n для отмены
6. **Чат-цикл**`while True` с вводом пользователя
## Запуск
```bash
pip install -r requirements.txt
export OPENAI_API_KEY="your-key"
python agent.py
```