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:
@@ -104,12 +104,27 @@ class ThreadListResponse(BaseModel):
|
||||
total: int
|
||||
|
||||
|
||||
class ThreadStateInfo(BaseModel):
|
||||
current_intent_code: str | None = None
|
||||
current_step: int = 0
|
||||
slots: dict = Field(default_factory=dict)
|
||||
|
||||
|
||||
class BounceInfo(BaseModel):
|
||||
from_: str = Field(alias="from")
|
||||
to: str
|
||||
preface: str = ""
|
||||
|
||||
model_config = {"populate_by_name": True}
|
||||
|
||||
|
||||
class ThreadDetailResponse(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
created_at: str
|
||||
updated_at: str
|
||||
messages: list[MessageInfo] = Field(default_factory=list)
|
||||
thread_state: ThreadStateInfo | None = None
|
||||
|
||||
|
||||
class ChatResponse(BaseModel):
|
||||
@@ -118,12 +133,15 @@ class ChatResponse(BaseModel):
|
||||
message_id: int
|
||||
intent_code: str = ""
|
||||
intent_name: str = ""
|
||||
router_intent_code: str = ""
|
||||
config_version: int = 0
|
||||
router_version: int | None = None
|
||||
answer: str
|
||||
sources: list[SourceInfo]
|
||||
model_used: str
|
||||
assembled_prompt: str = ""
|
||||
thread_state: ThreadStateInfo = Field(default_factory=ThreadStateInfo)
|
||||
bounces: list[BounceInfo] = Field(default_factory=list)
|
||||
|
||||
|
||||
class ThreadDeleteResponse(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user