From 68b45c60a0032c46416b8de721167912830cd6d1 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 14 Sep 2026 17:24:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(extension):=20=E6=89=A9=E5=B1=95=E6=84=8F?= =?UTF-8?q?=E5=9B=BE=E6=A3=80=E6=B5=8B=E6=8F=90=E5=89=8D=E5=88=B0=20route?= =?UTF-8?q?=5Fintent=20=E4=B9=8B=E5=89=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 验收实测:『创建一个扩展用于统计 fastq 质量』被 route_intent 判 qa(生信词库不识别扩展创建语义),扩展意图判定在 bioflow 分支内 永远到不了。修复:扩展两层判定移到 gen() 开头,命中发 extension_* 帧后返回;不命中走原逻辑(漏判安全)。 Co-Authored-By: Claude Fable 5 --- bioflow_service/app/routers/bioflow.py | 48 ++++++++++++++------------ 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/bioflow_service/app/routers/bioflow.py b/bioflow_service/app/routers/bioflow.py index 7f6d724..ed096fa 100644 --- a/bioflow_service/app/routers/bioflow.py +++ b/bioflow_service/app/routers/bioflow.py @@ -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)