feat(api): 访谈路径轻量门控、Memoir Phase1 批处理与叙事/记忆管线加固
- 新增 utterance_substance:短时/应答/元话语可跳过记忆检索、阶段 LLM 与资料抽取 LLM;可配置 - 输入归一化:LLM 模式默认仅语音/ASR;配置项写入 .env.example - Memoir Phase1:可选 batch LLM 一次性抽取+分类(失败回退逐段);Extraction 空槽位时阶段与 current_stage 对齐,prompt 约束收紧 - 叙事与忠实度:narrative_safety、证据重叠/场合锚点、标题 slots 与履历短语 grounded;fidelity 解析失败 fail-open 可配置 - 章节管线:锁 TTL 上调、锁竞争 Celery 重试、Phase2 immediate singleflight 等;story_pipeline_sync / chapter_compose / memoir_tasks 联动 - Memory:compaction / repo / summarizer / evidence 小修;事实 FTS 未命中是否回退最近事实可配置 - 新增 memoir_pipeline_trace;补充 memoir_reliability 文档与多项回归/门控测试
This commit is contained in:
@@ -19,9 +19,13 @@ from app.agents.chat.stage_detection import (
|
||||
detect_primary_life_stage,
|
||||
life_stage_display_name,
|
||||
)
|
||||
from app.agents.chat.utterance_substance import should_run_chat_stage_memory_heavy_work
|
||||
from app.core.config import settings
|
||||
from app.core.dependencies import get_llm_provider
|
||||
from app.features.conversation.input_normalize import normalize_chat_input_for_agent
|
||||
from app.features.conversation.input_normalize import (
|
||||
apply_conversation_input_rules,
|
||||
normalize_chat_input_for_agent,
|
||||
)
|
||||
from app.features.memoir.state_service import get_or_create_state, switch_stage
|
||||
|
||||
|
||||
@@ -58,6 +62,11 @@ async def _fetch_interview_memory_evidence(
|
||||
msg = (user_message or "").strip()
|
||||
if not msg:
|
||||
return ""
|
||||
if (
|
||||
settings.chat_memory_retrieval_require_substantive
|
||||
and not should_run_chat_stage_memory_heavy_work(msg)
|
||||
):
|
||||
return ""
|
||||
try:
|
||||
ms = MemoryService(db, embedding_provider=get_embedding_provider())
|
||||
bundle = await ms.retrieve(user_id, msg, top_k=settings.chat_memory_top_k)
|
||||
@@ -122,9 +131,19 @@ class ChatOrchestrator:
|
||||
missing,
|
||||
len(user_message or ""),
|
||||
)
|
||||
extracted = await self.profile_agent.extract_profile_from_message(
|
||||
user_message, missing, conversation_id=conversation_id
|
||||
)
|
||||
run_extract = True
|
||||
if settings.chat_profile_extract_require_substantive:
|
||||
rules_only = apply_conversation_input_rules(user_message or "")
|
||||
run_extract = should_run_chat_stage_memory_heavy_work(
|
||||
rules_only
|
||||
)
|
||||
extracted = None
|
||||
if run_extract:
|
||||
extracted = (
|
||||
await self.profile_agent.extract_profile_from_message(
|
||||
user_message, missing, conversation_id=conversation_id
|
||||
)
|
||||
)
|
||||
if extracted:
|
||||
await apply_extracted_profile_fn(user, extracted, db)
|
||||
|
||||
@@ -184,12 +203,17 @@ class ChatOrchestrator:
|
||||
normalized_user_message = normalize_chat_input_for_agent(
|
||||
user_message or "",
|
||||
llm=llm_n,
|
||||
is_from_voice=is_from_voice,
|
||||
)
|
||||
state = await get_or_create_state(user_id, db)
|
||||
substantive_turn = should_run_chat_stage_memory_heavy_work(
|
||||
normalized_user_message
|
||||
)
|
||||
detected = await detect_primary_life_stage(
|
||||
normalized_user_message,
|
||||
state.current_stage,
|
||||
self.interview_agent.llm,
|
||||
skip_llm=not substantive_turn,
|
||||
)
|
||||
if detected != state.current_stage:
|
||||
state = await switch_stage(user_id, detected, db)
|
||||
|
||||
Reference in New Issue
Block a user