refactor: unify core pipeline logging with cs_agent logger

This commit is contained in:
2026-03-01 16:29:52 +08:00
parent a6b7bf1982
commit 8dd5a11b4b
11 changed files with 82 additions and 55 deletions

View File

@@ -1,6 +1,7 @@
from __future__ import annotations
import asyncio
import logging
from typing import Any
from core.ai_reply_flow import execute_ai_turn
@@ -11,6 +12,8 @@ from core.reply_finalize_flow import finalize_ai_reply
from utils.metrics_tracker import emit as metrics_emit
from utils.observability import build_trace_id
logger = logging.getLogger("cs_agent")
async def process_incoming_message(agent: Any, message: Any) -> Any:
"""主消息处理编排:预处理 -> 业务流 -> AI -> 收尾。"""
@@ -72,7 +75,7 @@ async def process_incoming_message(agent: Any, message: Any) -> Any:
)
except Exception as e:
err_str = str(e)
print(f"[Agent] AI 调用失败: {e},使用兜底回复")
logger.exception("[Agent] AI 调用失败,使用兜底回复: %s", err_str)
agent._activity_log("agent_ai_error", customer_id=message.from_id, acc_id=message.acc_id, error=err_str)
metrics_emit("ai_call_failed", customer_id=message.from_id, acc_id=message.acc_id)
if "AccountOverdueError" in err_str or "overdue" in err_str.lower():