Add stream-mode agent with messages and updates handling

This commit is contained in:
2026-05-12 11:04:06 +03:00
commit d7b827593e
3 changed files with 128 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
# Stream-режим AI-агента
Агент с потоковым выводом в консоль.
## Что реализовано
1. **`.stream()` вместо `.invoke()`** — `agent.stream(..., stream_mode=['messages', 'updates'])`
2. **Обработка `'messages'`** — вывод токенов текста сразу (`end=''`), разделители `--- --- ---` при смене шага
3. **Обработка `'updates'`** — отображение вызовов инструментов через `format_message()`
## Запуск
```bash
pip install -r requirements.txt
export OPENAI_API_KEY="your-key"
python stream_agent.py
```