Delete conversation from modes
This commit is contained in:
@@ -4,26 +4,11 @@ import sys
|
|||||||
from .config import GATEWAY_URL, AGENT, log
|
from .config import GATEWAY_URL, AGENT, log
|
||||||
from .audio import record
|
from .audio import record
|
||||||
from .tts import speak, stop_speaking
|
from .tts import speak, stop_speaking
|
||||||
from .llm import ask_agent_stream, Conversation, is_reset_command
|
from .llm import ask_agent_stream, is_reset_command
|
||||||
|
|
||||||
# Персистентные сессии — одна на день для каждого агента
|
|
||||||
_sessions: dict[str, Conversation] = {}
|
|
||||||
|
|
||||||
|
|
||||||
def _get_session(agent_id: str) -> Conversation:
|
|
||||||
"""Возвращает текущую сессию, создаёт новую если день сменился"""
|
|
||||||
conv = _sessions.get(agent_id)
|
|
||||||
if conv is None or conv.is_expired():
|
|
||||||
conv = Conversation(agent_id=agent_id)
|
|
||||||
_sessions[agent_id] = conv
|
|
||||||
print(f"🆕 Новая сессия для {agent_id}")
|
|
||||||
return conv
|
|
||||||
|
|
||||||
|
|
||||||
def _handle_reset(text: str, agent_id: str) -> bool:
|
def _handle_reset(text: str, agent_id: str) -> bool:
|
||||||
"""Проверяет команду сброса. Возвращает True если сброс произошёл."""
|
"""Команда сброса — на сервере OpenClaw сессия рулится session_key, клиент только сообщает."""
|
||||||
if is_reset_command(text):
|
if is_reset_command(text):
|
||||||
_sessions[agent_id] = Conversation(agent_id=agent_id)
|
|
||||||
msg = "Начинаю новую сессию."
|
msg = "Начинаю новую сессию."
|
||||||
print(f"🔄 {msg}")
|
print(f"🔄 {msg}")
|
||||||
speak(msg, agent_id)
|
speak(msg, agent_id)
|
||||||
@@ -34,8 +19,6 @@ def _handle_reset(text: str, agent_id: str) -> bool:
|
|||||||
def _conversation_loop(agent_id: str, agent_name: str = "Cosmo"):
|
def _conversation_loop(agent_id: str, agent_name: str = "Cosmo"):
|
||||||
"""Основной цикл диалога — слушает и отвечает пока пользователь говорит.
|
"""Основной цикл диалога — слушает и отвечает пока пользователь говорит.
|
||||||
Выходит когда в течение MAX_DURATION не было речи."""
|
Выходит когда в течение MAX_DURATION не было речи."""
|
||||||
conv = _get_session(agent_id)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
text = record()
|
text = record()
|
||||||
if not text:
|
if not text:
|
||||||
@@ -45,10 +28,9 @@ def _conversation_loop(agent_id: str, agent_name: str = "Cosmo"):
|
|||||||
print(f"📝 Ты → {agent_name}: {text}")
|
print(f"📝 Ты → {agent_name}: {text}")
|
||||||
|
|
||||||
if _handle_reset(text, agent_id):
|
if _handle_reset(text, agent_id):
|
||||||
conv = _get_session(agent_id)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
response = ask_agent_stream(text, conv=conv, agent_id=agent_id)
|
response = ask_agent_stream(text, agent_id=agent_id)
|
||||||
print(f"🤖 {agent_name}: {response}\n")
|
print(f"🤖 {agent_name}: {response}\n")
|
||||||
# после ответа — следующая итерация с новым record()
|
# после ответа — следующая итерация с новым record()
|
||||||
# record() сам гасит эхо через ECHO_WARMUP
|
# record() сам гасит эхо через ECHO_WARMUP
|
||||||
|
|||||||
Reference in New Issue
Block a user