bug fixed

This commit is contained in:
2025-12-16 17:54:37 +08:00
parent f2fcbe485f
commit e8ef7c6da7
3 changed files with 164 additions and 44 deletions

View File

@@ -66,7 +66,7 @@ DEFAULT_INSTRUCTIONS = """# 角色
# 能力
- 你具有调用工具操作前端界面系统的能力
- ask_image_capture工具被调用后会在系统播放拍摄的目标和需求所以你每次在调用它之前不需要重复引导用户拍摄什么
- ask_image_capture工具被调用后会在系统播放拍摄的目标和需求所以你每次在调用它之前不需要重复引导用户拍摄什么而是使用ask_image_capture来传递拍摄需求
# 任务
你的职责是全流程引导用户完成:事故信息采集 -> 现场证据拍照 -> 驾驶员信息核实。
@@ -75,6 +75,7 @@ DEFAULT_INSTRUCTIONS = """# 角色
- 在事故信息采集阶段询问是否有人受伤请求用户简单描述事故情况询问事故发生时间并通过复述标准化时间xx年xx月xx日xx时xx分向用户确认询问事故车辆数量询问事故发生的原因例如追尾、刮擦、碰撞等。采集完成后进入现场证据拍照阶段
- 如果用户回答已包含需要问题的答案,改为与用户确认答案是否正确
- 采集完成之后进入现场证据拍照阶段
- 这个阶段不使用ask_important_question和ask_image_capture工具
## 现场证据拍照阶段
- 在现场证据拍照阶段使用askImageCapture工具引导用户依次拍摄照片1. 第一辆车的车牌2. 第一辆车的碰撞位置3. 第一辆车的驾驶员正脸;
@@ -614,11 +615,20 @@ class MyAgent(Agent):
mobile_suffix = ''.join([str(random.randint(0, 9)) for _ in range(9)])
random_mobile = f"{mobile_prefix}{mobile_suffix}"
return {
result = {
"success": True,
"plate": normalized_plate,
"mobile": random_mobile,
}
await self._send_chat_message(
"┌─✅ Result: get_mobile_by_plate\n"
f"│ plate: \"{normalized_plate}\"\n"
f"│ mobile: \"{random_mobile}\"\n"
"└───────────────"
)
return result
@function_tool()
async def get_id_card_by_plate(
@@ -652,11 +662,20 @@ class MyAgent(Agent):
check_digit = 'X' if random.random() < 0.1 else str(random.randint(0, 9))
random_id_card = f"{area_code}{birth_date}{sequence}{check_digit}"
return {
result = {
"success": True,
"plate": normalized_plate,
"id_card": random_id_card,
}
await self._send_chat_message(
"┌─✅ Result: get_id_card_by_plate\n"
f"│ plate: \"{normalized_plate}\"\n"
f"│ id_card: \"{random_id_card}\"\n"
"└───────────────"
)
return result
@function_tool()
async def validate_mobile_number(
@@ -678,17 +697,33 @@ class MyAgent(Agent):
)
is_valid = bool(re.fullmatch(r"1[3-9]\\d{9}", normalized))
if is_valid:
return {
result = {
"success": True,
"valid": True,
"mobile": normalized,
}
return {
await self._send_chat_message(
"┌─✅ Result: validate_mobile_number\n"
f"│ mobile: \"{normalized}\"\n"
f"│ valid: true\n"
"└───────────────"
)
return result
result = {
"success": True,
"valid": False,
"mobile": normalized,
"error": "手机号格式不正确应为1[3-9]开头的11位数字",
}
await self._send_chat_message(
"┌─✅ Result: validate_mobile_number\n"
f"│ mobile: \"{normalized}\"\n"
f"│ valid: false\n"
f"│ error: \"{result['error']}\"\n"
"└───────────────"
)
return result
@function_tool()
async def validate_id_card_number(
@@ -710,25 +745,44 @@ class MyAgent(Agent):
)
is_valid = bool(re.fullmatch(r"(\\d{17}[\\dX]|\\d{15})", normalized))
if is_valid:
return {
result = {
"success": True,
"valid": True,
"id_card": normalized,
}
return {
await self._send_chat_message(
"┌─✅ Result: validate_id_card_number\n"
f"│ id_card: \"{normalized}\"\n"
f"│ valid: true\n"
"└───────────────"
)
return result
result = {
"success": True,
"valid": False,
"id_card": normalized,
"error": "身份证格式不正确应为18位末位可为X或15位数字",
}
await self._send_chat_message(
"┌─✅ Result: validate_id_card_number\n"
f"│ id_card: \"{normalized}\"\n"
f"│ valid: false\n"
f"│ error: \"{result['error']}\"\n"
"└───────────────"
)
return result
@function_tool()
async def enter_hand_off_to_human_mode(
self,
context: RunContext,
):
"""切换到“转人工”模式(前端电话界面进入人工处理)。返回成功/失败。"""
await self._send_chat_message("🔨 Call: enter_hand_off_to_human_mode")
"""切换到"转人工"模式(前端电话界面进入人工处理)。返回成功/失败。"""
await self._send_chat_message(
"┌─🔨 Call: enter_hand_off_to_human_mode\n"
"└───────────────"
)
try:
room = get_job_context().room
participant_identity = next(iter(room.remote_participants))
@@ -739,10 +793,21 @@ class MyAgent(Agent):
response_timeout=5.0,
)
logger.info(f"Entered hand off to human mode: {response}")
await self._send_chat_message(f"✅ Result: enter_hand_off_to_human_mode\n • status: success")
await self._send_chat_message(
"┌─✅ Result: enter_hand_off_to_human_mode\n"
f"│ status: success\n"
f"│ response: {response}\n"
"└───────────────"
)
return response
except Exception as e:
logger.error(f"Failed to enter hand off to human mode: {e}")
await self._send_chat_message(
"┌─❌ Result: enter_hand_off_to_human_mode\n"
f"│ status: error\n"
f"│ error: \"{str(e)}\"\n"
"└───────────────"
)
raise ToolError(f"Unable to enter hand off to human mode: {str(e)}")
@function_tool()
@@ -751,7 +816,10 @@ class MyAgent(Agent):
context: RunContext,
):
"""挂断当前通话(结束会话),返回成功/失败。"""
await self._send_chat_message("🔨 Call: hang_up_call")
await self._send_chat_message(
"┌─🔨 Call: hang_up_call\n"
"└───────────────"
)
try:
room = get_job_context().room
participant_identity = next(iter(room.remote_participants))
@@ -762,10 +830,21 @@ class MyAgent(Agent):
response_timeout=5.0,
)
logger.info(f"Hung up call: {response}")
await self._send_chat_message(f"✅ Result: hang_up_call\n • status: disconnected")
await self._send_chat_message(
"┌─✅ Result: hang_up_call\n"
f"│ status: disconnected\n"
f"│ response: {response}\n"
"└───────────────"
)
return response
except Exception as e:
logger.error(f"Failed to hang up call: {e}")
await self._send_chat_message(
"┌─❌ Result: hang_up_call\n"
f"│ status: error\n"
f"│ error: \"{str(e)}\"\n"
"└───────────────"
)
raise ToolError(f"Unable to hang up call: {str(e)}")
@function_tool()