refactor: extract post-ops helpers from pydantic agent

This commit is contained in:
2026-03-01 15:14:57 +08:00
parent 6458e7dcca
commit b323a64b0b
5 changed files with 190 additions and 211 deletions

View File

@@ -5,6 +5,7 @@ from datetime import datetime
from typing import TYPE_CHECKING
from utils.metrics_tracker import emit as metrics_emit
from core.post_ops import auto_tag, detect_discount, detect_price, record_deal_fail
if TYPE_CHECKING:
from core.pydantic_ai_agent import AgentResponse, ConversationState, CustomerMessage, CustomerServiceAgent
@@ -36,9 +37,9 @@ async def finalize_ai_reply(
except Exception:
pass
agent._detect_price(reply_text, state)
agent._detect_discount(message.msg, state)
asyncio.create_task(agent._auto_tag(message, reply_text, state))
detect_price(reply_text, state)
detect_discount(message.msg, state)
asyncio.create_task(auto_tag(message, state))
need_transfer = False
transfer_msg = ""
@@ -64,7 +65,13 @@ async def finalize_ai_reply(
if any(kw in customer_text for kw in no_convert_keywords):
reason = "嫌贵放弃" if any(k in customer_text for k in ["", "贵了", "便宜"]) else "放弃"
asyncio.create_task(
agent._record_deal_fail(message.from_id, message.from_name, message.acc_id, message.acc_type, reason)
record_deal_fail(
customer_id=message.from_id,
customer_name=message.from_name,
acc_id=message.acc_id,
platform=message.acc_type,
reason=reason,
)
)
should_reply = bool(reply_text and reply_text.strip()) and not need_transfer