40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
import logging
|
|
import asyncio
|
|
from typing import List, Optional, Dict, Any
|
|
from pydantic import BaseModel, Field
|
|
from pydantic_ai import RunContext
|
|
from core.schema import StandardResponse
|
|
from services.dispatch_service import dispatch_service
|
|
|
|
logger = logging.getLogger("cs_agent")
|
|
|
|
async def transfer_to_human_tool(ctx: RunContext[Any], reason: str = Field(description="转人工的原因")) -> str:
|
|
"""
|
|
【核心工具】执行转人工逻辑。
|
|
获取设计师姓名并生成精准转接指令。
|
|
"""
|
|
logger.info(f"[Tool] 尝试呼叫设计师接手: {reason}")
|
|
|
|
# 1. 尝试派单获取设计师姓名
|
|
designer_name = await dispatch_service.assign_designer()
|
|
|
|
if designer_name:
|
|
# 2. 有设计师在线:生成标准转接指令
|
|
magic_cmd = f"正在为您转接|[转移会话],{designer_name},无原因"
|
|
logger.info(f"[Tool] 成功呼叫设计师: {designer_name}")
|
|
return magic_cmd
|
|
else:
|
|
# 3. 设计师下线:返回特定信号
|
|
logger.warning("[Tool] 派单失败:设计师们已下线或不在位")
|
|
return "ERROR_NO_DESIGNER_ONLINE"
|
|
|
|
async def check_order_status_tool(ctx: RunContext[Any], customer_id: str = Field(description="客户ID")) -> str:
|
|
"""查询订单状态。"""
|
|
return "设计师正在后台加急处理中,请稍等哈。"
|
|
|
|
def register_agent_tools(agent: Any):
|
|
"""注册工具"""
|
|
agent.tool(transfer_to_human_tool)
|
|
agent.tool(check_order_status_tool)
|
|
logger.info("[Agent] 工具箱已更新:称呼统一为“设计师”。")
|