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,8 +1,11 @@
from __future__ import annotations
import logging
from datetime import datetime
from typing import TYPE_CHECKING, Optional
logger = logging.getLogger("cs_agent")
if TYPE_CHECKING:
from core.pydantic_ai_agent import AgentResponse, ConversationState, CustomerMessage, CustomerServiceAgent
@@ -55,7 +58,7 @@ async def handle_find_image_batch_flow(
fallback=defer_fallback,
)
state.last_reply_at = datetime.now()
print(f"{agent.C_REPLY}[REPLY->CUSTOMER]{agent.C_RESET} {defer_reply}")
logger.info("[REPLY->CUSTOMER] %s", defer_reply)
return AgentResponse(reply=defer_reply, should_reply=True, need_transfer=False)
quote_res = await agent._quote_pending_images(state, message)
reply_text = agent._colloquialize_reply(quote_res.get("reply", ""))
@@ -67,7 +70,7 @@ async def handle_find_image_batch_flow(
)
need_transfer = bool(quote_res.get("need_transfer"))
state.last_reply_at = datetime.now()
print(f"{agent.C_REPLY}[REPLY->CUSTOMER]{agent.C_RESET} {reply_text}")
logger.info("[REPLY->CUSTOMER] %s", reply_text)
return AgentResponse(
reply=reply_text,
should_reply=not need_transfer,
@@ -89,7 +92,7 @@ async def handle_find_image_batch_flow(
fallback=ack_fallback,
)
state.last_reply_at = datetime.now()
print(f"{agent.C_REPLY}[REPLY->CUSTOMER]{agent.C_RESET} {ack}")
logger.info("[REPLY->CUSTOMER] %s", ack)
return AgentResponse(reply=ack, should_reply=True, need_transfer=False)
if not state.pending_image_urls:
@@ -118,7 +121,7 @@ async def handle_find_image_batch_flow(
fallback=clarify_fallback,
)
state.last_reply_at = datetime.now()
print(f"{agent.C_REPLY}[REPLY->CUSTOMER]{agent.C_RESET} {clarify}")
logger.info("[REPLY->CUSTOMER] %s", clarify)
return AgentResponse(reply=clarify, should_reply=True, need_transfer=False)
if state.quote_phase == "ready_to_quote" and state.quote_ready_turns <= 0 and short_intent in {"progress_query", "ack", "finish_signal"}:
@@ -132,7 +135,7 @@ async def handle_find_image_batch_flow(
)
need_transfer = bool(quote_res.get("need_transfer"))
state.last_reply_at = datetime.now()
print(f"{agent.C_REPLY}[REPLY->CUSTOMER]{agent.C_RESET} {reply_text}")
logger.info("[REPLY->CUSTOMER] %s", reply_text)
return AgentResponse(
reply=reply_text,
should_reply=not need_transfer,
@@ -150,7 +153,7 @@ async def handle_find_image_batch_flow(
fallback=progress_fallback,
)
state.last_reply_at = datetime.now()
print(f"{agent.C_REPLY}[REPLY->CUSTOMER]{agent.C_RESET} {progress}")
logger.info("[REPLY->CUSTOMER] %s", progress)
return AgentResponse(reply=progress, should_reply=True, need_transfer=False)
if agent._needs_clarification_in_collecting(text_without_urls):
@@ -163,7 +166,7 @@ async def handle_find_image_batch_flow(
fallback=ask_fallback,
)
state.last_reply_at = datetime.now()
print(f"{agent.C_REPLY}[REPLY->CUSTOMER]{agent.C_RESET} {ask}")
logger.info("[REPLY->CUSTOMER] %s", ask)
return AgentResponse(reply=ask, should_reply=True, need_transfer=False)
if agent._is_batch_finish_intent(
text=customer_text,
@@ -182,7 +185,7 @@ async def handle_find_image_batch_flow(
fallback=defer_fallback,
)
state.last_reply_at = datetime.now()
print(f"{agent.C_REPLY}[REPLY->CUSTOMER]{agent.C_RESET} {defer_reply}")
logger.info("[REPLY->CUSTOMER] %s", defer_reply)
return AgentResponse(reply=defer_reply, should_reply=True, need_transfer=False)
quote_res = await agent._quote_pending_images(state, message)
reply_text = agent._colloquialize_reply(quote_res.get("reply", ""))
@@ -194,7 +197,7 @@ async def handle_find_image_batch_flow(
)
need_transfer = bool(quote_res.get("need_transfer"))
state.last_reply_at = datetime.now()
print(f"{agent.C_REPLY}[REPLY->CUSTOMER]{agent.C_RESET} {reply_text}")
logger.info("[REPLY->CUSTOMER] %s", reply_text)
return AgentResponse(
reply=reply_text,
should_reply=not need_transfer,
@@ -211,5 +214,5 @@ async def handle_find_image_batch_flow(
fallback=remind_fallback,
)
state.last_reply_at = datetime.now()
print(f"{agent.C_REPLY}[REPLY->CUSTOMER]{agent.C_RESET} {remind}")
logger.info("[REPLY->CUSTOMER] %s", remind)
return AgentResponse(reply=remind, should_reply=True, need_transfer=False)