fix(extension): 扩展意图检测提前到 route_intent 之前

验收实测:『创建一个扩展用于统计 fastq 质量』被 route_intent 判
qa(生信词库不识别扩展创建语义),扩展意图判定在 bioflow 分支内
永远到不了。修复:扩展两层判定移到 gen() 开头,命中发
extension_* 帧后返回;不命中走原逻辑(漏判安全)。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-14 17:24:27 +08:00
co-authored by Claude Fable 5
parent c0b3026209
commit 68b45c60a0
+25 -23
View File
@@ -156,29 +156,10 @@ async def chat_stream(body: ChatStreamRequest) -> StreamingResponse:
last_seq = body.last_seq if body.last_seq is not None else -1
async def gen():
# 0. 生信流内流程咨询(has_bioflow_context + FLOW_QA_WORD)→ 知识库引用
intent = route_intent(
body.message,
has_attachments=body.has_attachments,
has_active_artifact=body.has_active_artifact,
has_bioflow_context=body.has_bioflow_context,
)
if intent == "bioflow_qa":
qa_payload = await flow_ask(FlowAskRequest(session_id=body.session_id, question=body.message))
yield _sse({"type": "message_done", "seq": -2, "data": {
"kind": "flow_qa",
"citations": qa_payload["answer"]["citations"],
"degraded": qa_payload["answer"]["degraded"],
}})
return
if intent != "bioflow":
yield _sse({"type": "message_done", "seq": -2, "data": {
"kind": "qa", "message": "已转交知识问答处理", "routed": intent,
}})
return
# 0.5. 扩展意图两层判定(契约 §5;先于阶段规划,漏判安全)。
# 命中 → 发 extension_* 引导帧后返回(不进入正常生信阶段规划)。
# 0. 扩展意图两层判定(契约 §5)——必须在 route_intent 之前:
# 「创建一个扩展用于…」这类消息会被生信词库判为 qa,永远到不了
# bioflow 分支;扩展判定先行,命中发 extension_* 帧后返回,
# 不命中走原 route_intent 逻辑(漏判安全,现网零影响)。
from ..services.bioflow import extensions as ext_mod
from ..services.bioflow.intent import detect_extension_intent
try:
@@ -217,6 +198,27 @@ async def chat_stream(body: ChatStreamRequest) -> StreamingResponse:
except Exception as exc: # noqa: BLE001 - 扩展链路异常不回退生信主链
logger.warning("chat_stream: extension intent check failed: %s", exc)
# 0. 生信流内流程咨询(has_bioflow_context + FLOW_QA_WORD)→ 知识库引用
intent = route_intent(
body.message,
has_attachments=body.has_attachments,
has_active_artifact=body.has_active_artifact,
has_bioflow_context=body.has_bioflow_context,
)
if intent == "bioflow_qa":
qa_payload = await flow_ask(FlowAskRequest(session_id=body.session_id, question=body.message))
yield _sse({"type": "message_done", "seq": -2, "data": {
"kind": "flow_qa",
"citations": qa_payload["answer"]["citations"],
"degraded": qa_payload["answer"]["degraded"],
}})
return
if intent != "bioflow":
yield _sse({"type": "message_done", "seq": -2, "data": {
"kind": "qa", "message": "已转交知识问答处理", "routed": intent,
}})
return
# 1. 规划(候选路径;复用/LLM/降级)
try:
plan: PlanResult = await ctx.planner.plan(body.message)