fix(customer-service): FAQ 型回答不能把"问"字当成追问的主语

给 C1-C5 补 FAQ 之后暴露的连带问题:FAQ 型回答的首行是"问:C1 客户能买什么产品?",
_topic_of 取冒号前的内容会拿到一个孤零零的"问"字,客户追问时检索词被污染成
"问 那它能买基金吗"。

改为"问"/"答"这类纯标签直接判为取不出主语,退化成只查当前这一句。

另附一条实测结论(**没有改代码**):在 FAQ 型回答之后追问「那它能买基金吗」仍会转人工,
这是安全且合理的——上一轮回答里没有可指代的产品实体,而"C1 能不能买基金"本身取决于
那只基金的风险等级,知识库没有、也不该有这种一概而论的答案。按金融场景的原则,
"答不了"好过"答错"。
This commit is contained in:
2026-09-10 22:35:17 +08:00
parent 7b3a72860c
commit ee9de1b520
2 changed files with 12 additions and 1 deletions
@@ -262,7 +262,11 @@ class CustomerServiceAgent(BaseAgent):
first = next((line.strip() for line in answer.splitlines() if line.strip()), "") first = next((line.strip() for line in answer.splitlines() if line.strip()), "")
first = first.lstrip("#").strip() first = first.lstrip("#").strip()
topic = first.split(":", 1)[0].strip() if ":" in first else first topic = first.split(":", 1)[0].strip() if ":" in first else first
if not topic or len(topic) > 20 or "," in topic or "。" in topic: # FAQ 型回答的首行是"问:C1 客户能买什么产品?",冒号前只有一个"问"字;
# 拿它当主语只会把检索词污染成"问 那它风险高吗"。
if not topic or topic in {"问", "答"}:
return ""
if len(topic) > 20 or "," in topic or "。" in topic:
return "" return ""
return topic return topic
@@ -51,6 +51,13 @@ def test_fallback_answer_yields_no_topic() -> None:
assert CustomerServiceAgent._topic_of("") == "" assert CustomerServiceAgent._topic_of("") == ""
def test_faq_style_answer_yields_no_topic() -> None:
"""FAQ 型回答首行是"问:…",冒号前只有一个"问"字,不能当主语。"""
assert CustomerServiceAgent._topic_of(
"问:C1 客户能买什么产品?\n答:C1(保守型)客户可以购买 R1、R2 等级的产品。"
) == ""
def test_topic_change_does_not_drag_previous_question_in() -> None: def test_topic_change_does_not_drag_previous_question_in() -> None:
"""客户换话题时,检索词里不能出现上一轮的痕迹(实测的答非所问场景)。""" """客户换话题时,检索词里不能出现上一轮的痕迹(实测的答非所问场景)。"""
query = CustomerServiceAgent._search_query(_request("基金赎回几天到账", PREVIOUS, ANSWER)) query = CustomerServiceAgent._search_query(_request("基金赎回几天到账", PREVIOUS, ANSWER))