转人工协同按运输方式各自落地:海运说转人工直接建正式单建群发摘要和空白表,陆运先选业务类型和报价场景再建群,空运先落正式单让销售把工单号发进原群,转人工后群里报价不再被当成冻结单拦住。产品报价只发摘要和成交卡,要 Excel/PDF 说「生成报价单」再出,多段逐段出、没价出空白表,出表后补推成交跟进不涨版本、不重置等待计时。结束询价口令不再进模型,直接清上下文。卡片回执按本次入站消息号去重,第二次点提交不会再被静默吞掉。陆转人工按选定模板名直取,避免陆运七种业务靠关键词猜错;空运舱位只回一条时直接出价,TMS 分桶费用落到对应段。后台工单补需求字段与模板预览样例,新增 AIR_NEED_WO 回复语、协同模式、陆运岗位与陆运超时卡迁移脚本;测服文档改为独立企微应用 1000015。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
linmianxun
2026-11-19 14:07:52 +08:00
co-authored by Cursor
parent b878a094b5
commit b3637f3fc4
84 changed files with 9293 additions and 572 deletions
+6
View File
@@ -93,8 +93,14 @@ class IntentRouter:
return RouteDecision(intent="card_action", confidence=1.0)
from agent.handlers.text_inquiry import is_land_confirm_action
from agent.channel.wecom.models import InboundMessage
from agent.policy import inquiry_copy as copy
from agent.schema.land_options import looks_like_confirm
# 结束/终止询价是产品短指令:不进模型,避免被当成补字段或闲聊。
if copy.looks_like_end_inquiry(text or ""):
logger.info("route 结束询价口令:跳过模型 sender=%s", sender_id)
return RouteDecision(intent="end_inquiry", confidence=1.0)
if looks_like_confirm(text or ""):
if is_land_confirm_action(
InboundMessage(
@@ -19,6 +19,8 @@ from agent.routing.group_intent import (
INTENT_DEAL,
INTENT_DROP_TMS,
INTENT_FIELDS,
INTENT_GENERATE_PDF,
INTENT_GENERATE_SHEET,
INTENT_KEEP_TMS,
INTENT_ADJUST,
INTENT_LOST,
@@ -28,6 +30,7 @@ from agent.routing.group_intent import (
_exact_tms_choice,
_hint_confirm_tms,
_hint_deal_outcome,
_hint_generate_sheet,
_hint_tms_choice,
_prefer_staff_quote,
text_is_staff_fee_quote,
@@ -58,6 +61,8 @@ _VALID = {
INTENT_DEAL,
INTENT_LOST,
INTENT_NEGOTIATE,
INTENT_GENERATE_SHEET,
INTENT_GENERATE_PDF,
INTENT_OTHER,
}
@@ -110,6 +115,10 @@ def classify_air_group_text(
locked = _hint_lock_or_release(raw)
if locked:
return locked
# 按需出表口令优先于激活/报价,避免「给我报价单」被当成闲聊。
hinted_sheet = _hint_generate_sheet(raw)
if hinted_sheet:
return hinted_sheet
# 补舱位不限写法。凑齐舱位编号、航司、航班号就当选舱,不要先当成报价。
from agent.policy.air_group_ops import text_has_lock_supplement
@@ -298,10 +307,13 @@ def _classify_with_model(text: str, settings) -> str:
"quote_drop_tms=不要TMS、只用刚报的价;"
"deal_won=销售确认成交;deal_lost=销售确认未成交;"
"deal_negotiate=销售要继续协商;"
"generate_quote_sheet=销售/商务/航线要生成或下载 Excel 报价单,没有报新价格;"
"generate_quote_pdf=销售/商务/航线要生成或下载 PDF 报价单;"
"other=闲聊。"
"一句话里既有锁舱又有工单号,回 air_lock。"
"一句话里既有工单号又确认成交/未成交/协商中,回 deal_won/deal_lost/deal_negotiate,不要回 air_activate。"
"有具体费用金额就是 product_quote。只有比例或只改总价才是 quote_adjust。"
"说生成报价单/下载报价单/给我报价单且无新价格,回 generate_quote_sheet 或 generate_quote_pdf。"
)
data = client.chat(
mode=LlmMode.ORDERED_ACTIONS,
+11 -1
View File
@@ -73,6 +73,9 @@ def _prepare_model_tool_args(
if intent == "handoff_human" or action_type == "HANDOFF_HUMAN":
data["intent"] = "handoff_human"
action["action_type"] = "HANDOFF_HUMAN"
if intent == "end_inquiry" or action_type == "END_INQUIRY":
data["intent"] = "end_inquiry"
action["action_type"] = "END_INQUIRY"
target = action.get("target") if isinstance(action.get("target"), dict) else {}
wo = str(target.get("work_order_no") or "").strip()
if data.get("intent") == "continue_thread" and not wo:
@@ -112,6 +115,9 @@ _SYSTEM = (
"【转人工】intent=handoff_human,action_type=HANDOFF_HUMAN。"
"销售明确要求人来报价或接管:转人工、人工报价、找产品/航线、别自动查了、不要机器人了。"
"口令不写死。抱怨慢、骂两句、只问进度不算,那些仍走新询价或闲聊。"
"【结束询价】intent=end_inquiry,action_type=END_INQUIRY。"
"销售要断开当前询价上下文、好开新单:结束询价、终止询价、这单先不算了、别跟这单了。"
"不是成交/未成交,也不是转人工。问「怎么结束询价」仍是闲聊。"
"【闲聊】intent=ordinary_text_other,action_type=ORDINARY_TEXT_OTHER。"
"问候、谢谢、无关闲聊。点卡片按钮字(生成Excel/生成PDF/不采用等)也标闲聊。"
"禁止因为销售没说指定口令就把续办或调价判成新询价或闲聊。"
@@ -210,7 +216,11 @@ class DeepSeekARouter:
digest = _digest_text(content)
# 无网夹具:正式路由仍走模型。此处只给单测一个「像续办」的可重复结论。
wo = copy.extract_work_order_no(content)
if wo and copy.looks_like_continue_ticket(content):
if copy.looks_like_end_inquiry(content):
intent = "end_inquiry"
action = "END_INQUIRY"
wo = ""
elif wo and copy.looks_like_continue_ticket(content):
intent = "continue_thread"
action = "CONTINUE_HISTORICAL_TICKET"
else:
+18
View File
@@ -13,6 +13,7 @@ from typing import Callable, Optional
from agent.channel.wecom.models import InboundMessage
from agent.handlers import abnormal, card_action, close_deal, continue_thread, new_inquiry
from agent.handlers.echo_text import handle_echo_text
from agent.handlers.end_inquiry import handle_end_inquiry
from agent.handlers.group_collab import handle_group_collab
from agent.handlers.image_inquiry import handle_image_inquiry
from agent.handlers.attachment_inquiry import handle_attachment_inquiry
@@ -87,6 +88,11 @@ def _wrap_card(message: InboundMessage) -> None:
action = copy.canonical_button(message.content or "") or (message.content or "").strip()
payload = dict(message.raw or {})
payload.setdefault("event_key", message.content or "")
# 本次点击的入站消息号:出一张卡会被反复点,回执去重必须按「这一次点击」算,
# 不能只按工单+动作+正文,否则第二次点提交会被当成重复消息静默吞掉
# (销售看到按钮已置灰却收不到任何回复)。
if message.message_id:
payload.setdefault("inbound_msg_id", message.message_id)
if message.chat_id:
payload["chat_id"] = message.chat_id
payload["chat_type"] = message.chat_type
@@ -111,6 +117,11 @@ def _wrap_abnormal(message: InboundMessage) -> None:
abnormal.handle_abnormal(sender_id=message.sender_id, inquiry_no="", reason="dispatch")
def _wrap_end_inquiry(message: InboundMessage) -> None:
"""结束/终止询价:清上下文,允许新开。"""
handle_end_inquiry(message)
def _wrap_route_failed(message: InboundMessage) -> None:
"""模型没给出路由结论:请销售再说一次,不假装听懂。"""
from agent.channel.queue import get_message_store
@@ -169,6 +180,7 @@ HANDLER_REGISTRY: dict[str, HandlerFn] = {
"continue_thread": _wrap_continue,
"card_action": _wrap_card,
"close_deal": _wrap_close,
"end_inquiry": _wrap_end_inquiry,
"abnormal": _wrap_abnormal,
"reject_no_sender": _noop,
"ignore_empty": _noop,
@@ -263,6 +275,12 @@ def dispatch_inbound(message: InboundMessage, decision: RouteDecision) -> str:
handle_image_inquiry(message)
return "image_inquiry"
if kind in {"text", ""}:
from agent.policy import inquiry_copy as copy
# 结束询价优先于附件/图片波次并字:否则「结束询价」会被当成补字段。
if copy.looks_like_end_inquiry(message.content or ""):
handle_end_inquiry(message)
return "end_inquiry"
from agent.handlers.attachment_inquiry import (
abandon_idle_attach_wait,
append_attach_text,
@@ -24,6 +24,9 @@ INTENT_CONFIRM_TMS = "quote_confirm_tms"
INTENT_DEAL = "deal_won"
INTENT_LOST = "deal_lost"
INTENT_NEGOTIATE = "deal_negotiate"
# 销售/商务/航线按需出表:默认 Excel;含 PDF 字样走 pdf。
INTENT_GENERATE_SHEET = "generate_quote_sheet"
INTENT_GENERATE_PDF = "generate_quote_pdf"
INTENT_OTHER = "other"
_VALID = {
@@ -37,6 +40,8 @@ _VALID = {
INTENT_DEAL,
INTENT_LOST,
INTENT_NEGOTIATE,
INTENT_GENERATE_SHEET,
INTENT_GENERATE_PDF,
INTENT_OTHER,
}
@@ -203,6 +208,10 @@ def classify_group_text(
raw = (text or "").strip()
if not raw:
return INTENT_OTHER
# 按需出表口令优先:避免模型把「给我报价单」判成 other / 报价。
hinted_sheet = _hint_generate_sheet(raw)
if hinted_sheet:
return hinted_sheet
# 问句让回 1 或 2。整句就是选项时先认,不能把「2」抽成价格。
exact = _exact_tms_choice(raw)
if exact:
@@ -236,6 +245,10 @@ def classify_group_text(
if hinted_deal and got in {INTENT_DISSOLVE, INTENT_OTHER, INTENT_FIELDS}:
logger.warning("群意图模型把成交判成%s,改回 %s text=%s", got, hinted_deal, raw[:40])
return hinted_deal
hinted_sheet = _hint_generate_sheet(raw)
if hinted_sheet and got in {INTENT_OTHER, INTENT_FIELDS, INTENT_QUOTE}:
logger.info("群意图模型判成%s,按出表口令改回 %s text=%s", got, hinted_sheet, raw[:40])
return hinted_sheet
return _prefer_staff_quote(got, raw)
except Exception:
logger.exception("群意图模型失败,回退标签字段")
@@ -263,6 +276,19 @@ def classify_group_text(
return INTENT_OTHER
def _hint_generate_sheet(text: str) -> str:
"""
生成/下载/给我报价单。含 pdf 走 PDF,否则 Excel。
口令不写死整句;「直接生成报价单」是私聊跳过协同按钮,群里仍可当写出表。
"""
from agent.policy.group_quote_sheet import detect_sheet_kind, looks_like_sheet_request
if not looks_like_sheet_request(text):
return ""
return INTENT_GENERATE_PDF if detect_sheet_kind(text) == "PDF" else INTENT_GENERATE_SHEET
def _norm_intent_text(text: str) -> str:
"""去掉空格和 @机器人显示名,方便整句就是「2」时对上选项。"""
from agent.policy.bot_name import strip_bot_mention
@@ -352,11 +378,14 @@ def _classify_with_model(text: str, settings) -> str:
"deal_won=销售确认这单成交了;"
"deal_lost=销售确认这单未成交;"
"deal_negotiate=销售要继续协商;"
"generate_quote_sheet=销售/商务/航线要生成或下载 Excel 报价单,没有报新价格;"
"generate_quote_pdf=销售/商务/航线要生成或下载 PDF 报价单;"
"dissolve=要把这个协同群解散;"
"other=闲聊、问候、对询价港口的随口更正(不当改单)。"
"一句话里既补字段又报价,回 product_quote。"
"有具体费用金额就是 product_quote,不要判成 quote_adjust 或 quote_keep_tms。"
"只有比例或只改总价才是 quote_adjust。"
"说生成报价单/下载报价单/给我报价单且无新价格,回 generate_quote_sheet 或 generate_quote_pdf。"
)
data = client.chat(
mode=LlmMode.ORDERED_ACTIONS,
@@ -367,6 +396,8 @@ def _classify_with_model(text: str, settings) -> str:
)
content = str(getattr(data, "content", "") or "").strip().lower()
for token in (
INTENT_GENERATE_PDF,
INTENT_GENERATE_SHEET,
INTENT_ADJUST,
INTENT_QUOTE,
INTENT_CONFIRM_TMS,
@@ -34,6 +34,7 @@ ACTION_INTENTS: dict[str, str] = {
"CONTINUE_HISTORICAL_TICKET": "continue_thread",
"QUOTE_ADJUST": "quote_adjust",
"HANDOFF_HUMAN": "handoff_human",
"END_INQUIRY": "end_inquiry",
}
@@ -105,7 +106,9 @@ def ordered_actions_tool_definition() -> dict[str, Any]:
"Resume any past ticket (any wording, or a bare WO+12-digit number) "
"with CONTINUE_HISTORICAL_TICKET / continue_thread and fill "
"target.work_order_no. New shipping demand uses ORDINARY_TEXT_INQUIRY. "
"Adjusting an existing quoted price (any wording) uses QUOTE_ADJUST."
"Adjusting an existing quoted price (any wording) uses QUOTE_ADJUST. "
"Ending the current inquiry to start fresh uses END_INQUIRY "
"(结束询价 / 终止询价)."
),
"strict": True,
"parameters": parameters,