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)