feat: queue pending transfers until designers are available
This commit is contained in:
@@ -3,6 +3,7 @@ import re
|
||||
import hashlib
|
||||
import logging
|
||||
import time
|
||||
import json
|
||||
from typing import List, Optional, Any, Dict
|
||||
from pydantic_ai import Agent, RunContext
|
||||
from pydantic_ai.models.openai import OpenAIChatModel
|
||||
@@ -236,6 +237,8 @@ class CustomerServiceBrain:
|
||||
logger.info(f"[Brain] AI处理完成,总耗时{elapsed:.1f}s")
|
||||
|
||||
# ===== 详细日志:AI 的思考过程和工具调用 =====
|
||||
pending_transfer_reason = ""
|
||||
pending_transfer_error = ""
|
||||
try:
|
||||
all_msgs = result.all_messages()
|
||||
for idx, m in enumerate(all_msgs):
|
||||
@@ -247,9 +250,20 @@ class CustomerServiceBrain:
|
||||
tool_name = getattr(part, 'tool_name', '?')
|
||||
tool_args = getattr(part, 'args', {})
|
||||
logger.info(f"[AI思考] 步骤{idx+1} 调用工具: {tool_name}({tool_args})")
|
||||
if tool_name == "transfer_to_human_tool":
|
||||
if isinstance(tool_args, str):
|
||||
try:
|
||||
tool_args = json.loads(tool_args)
|
||||
except Exception:
|
||||
tool_args = {"reason": tool_args}
|
||||
if isinstance(tool_args, dict):
|
||||
pending_transfer_reason = str(tool_args.get("reason") or "").strip()
|
||||
elif part_kind == 'tool-return':
|
||||
content = str(getattr(part, 'content', ''))[:200]
|
||||
logger.info(f"[AI思考] 步骤{idx+1} 工具返回: {content}")
|
||||
full_content = str(getattr(part, 'content', ''))
|
||||
if full_content.startswith("ERROR_DESIGNER_"):
|
||||
pending_transfer_error = full_content
|
||||
elif part_kind == 'text':
|
||||
content = str(getattr(part, 'content', ''))[:150]
|
||||
if content.strip():
|
||||
@@ -298,7 +312,13 @@ class CustomerServiceBrain:
|
||||
return StandardResponse(
|
||||
reply_content=reply_text,
|
||||
need_transfer=need_transfer,
|
||||
metadata={"acc_id": msg.acc_id, "acc_type": msg.acc_type}
|
||||
metadata={
|
||||
"acc_id": msg.acc_id,
|
||||
"acc_type": msg.acc_type,
|
||||
"pending_transfer": bool(pending_transfer_error and pending_transfer_reason),
|
||||
"pending_transfer_reason": pending_transfer_reason,
|
||||
"pending_transfer_error": pending_transfer_error,
|
||||
}
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user