fix:修改客服agent的意图识别

This commit is contained in:
2026-09-12 15:06:34 +08:00
parent faec16ad3e
commit da80fd0951
2 changed files with 73 additions and 20 deletions
+37 -3
View File
@@ -54,19 +54,28 @@ class AnonymousCustomerAgent:
intent = await _maybe_await(self.intent_recognize(query))
sources = []
if intent is Intent.GUIDE_PURCHASE:
if intent == Intent.GUIDE_PURCHASE:
answer = await _config(
self.config_getter,
"agent.customer.template.guide_purchase",
"请前往开户页面办理。",
)
elif intent is Intent.WANT_ADVISOR:
elif intent == Intent.WANT_ADVISOR:
answer = await _config(
self.config_getter,
"agent.customer.template.guide_advisor",
"如需基金推荐,请联系投资顾问。",
)
elif intent is Intent.KNOWLEDGE_QA:
elif intent == Intent.OFF_TOPIC:
answer = await _config(
self.config_getter,
"agent.customer.template.off_topic",
"我是华夏科技的智能客服,只能解答基金与公司业务相关的问题,"
"您可以问我基金知识、开户流程或公司信息~",
)
elif intent == Intent.CHITCHAT:
answer = await self._chitchat(session_id)
elif intent in (Intent.KNOWLEDGE_QA, Intent.COMPANY_INFO):
try:
sources = await _maybe_await(self.rag_retrieve(query, None))
except Exception:
@@ -112,6 +121,31 @@ class AnonymousCustomerAgent:
"trace_id": trace_id,
}
async def _chitchat(self, session_id: str) -> str:
"""带对话历史调用 LLM 做受限闲聊,失败时退回固定话术。"""
messages = await self.context.get(session_id)
prompt = [
{
"role": "system",
"content": (
"你是华夏科技(基金代销金融机构)的智能客服助手。"
"用户正在与你寒暄,请用一两句话简短、友好地回应,"
"并自然地引导用户咨询基金知识、开户流程或公司信息。"
"不得推荐任何基金产品,不得谈论具体收益,不得回答金融之外的实质性问题。"
),
},
*messages,
]
try:
return await _maybe_await(self.generate_answer(prompt))
except Exception:
return await _config(
self.config_getter,
"agent.customer.template.chitchat_fallback",
"您好,我是华夏科技的智能客服,很高兴为您服务!"
"您可以问我基金知识、开户流程或公司信息~",
)
@staticmethod
def _contains_sensitive_input(query: str) -> bool:
return bool(