feat(sprint5): state machine + bouncing — thread_state и служебные теги
Таблица thread_state (intent, step, slots) ведётся per-thread. В системный
промпт ветки дописывается текущее состояние, LLM возвращает служебный тег
[STATE: step=N; slots={...}] после основного ответа — парсер в chat_service
вырезает его и обновляет состояние. Если ветка решила, что тема ушла в другую,
она выдаёт [INTENT_CHANGE: code] — делаем один повторный вызов LLM с новой
веткой и сброшенным state (bouncing, MAX_BOUNCES=1). Если роутер сам выбрал
другую ветку, чем в thread_state, — state тоже сбрасывается. Промпт new_booking
переписан под 6-шаговый сценарий (имя → повод → специалист → время → подтверждение
→ запись), в «Песочнице» появился блок «Состояние треда» с intent/step/slots
и списком переходов.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ from models.responses import (
|
||||
ThreadDetailResponse,
|
||||
ThreadInfo,
|
||||
ThreadListResponse,
|
||||
ThreadStateInfo,
|
||||
)
|
||||
from services import chat_service
|
||||
|
||||
@@ -34,6 +35,7 @@ async def get_thread(thread_id: int, session: AsyncSession = Depends(get_session
|
||||
data = await chat_service.get_thread_detail(session, thread_id)
|
||||
if data is None:
|
||||
raise HTTPException(status_code=404, detail="Thread not found")
|
||||
state = data.get("thread_state") or {}
|
||||
return ThreadDetailResponse(
|
||||
id=data["id"],
|
||||
name=data["name"],
|
||||
@@ -47,9 +49,16 @@ async def get_thread(thread_id: int, session: AsyncSession = Depends(get_session
|
||||
created_at=m["created_at"],
|
||||
sources=[SourceInfo(**s) for s in m["sources"]],
|
||||
assembled_prompt=m["assembled_prompt"],
|
||||
intent_code=m.get("intent_code", ""),
|
||||
intent_name=m.get("intent_name", ""),
|
||||
)
|
||||
for m in data["messages"]
|
||||
],
|
||||
thread_state=ThreadStateInfo(
|
||||
current_intent_code=state.get("current_intent_code"),
|
||||
current_step=state.get("current_step", 0),
|
||||
slots=state.get("slots", {}),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user