From c2b95ca8967b04a13921f317ceee4b07607f51da Mon Sep 17 00:00:00 2001 From: lgy1027 Date: Tue, 10 Mar 2026 11:45:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E9=80=80=E5=87=BA?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E5=B9=B6=E6=B7=BB=E5=8A=A0=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 is_exiting 标志防止退出流程被中断 - 工具调用添加 30 秒超时保护,避免流程卡死 - TTS 相关操作添加超时保护 - 优化 OpenAI 客户端超时配置 --- main/xiaozhi-server/core/connection.py | 22 +++++++++++++++++-- .../xiaozhi-server/core/handle/abortHandle.py | 4 ++++ .../core/handle/intentHandler.py | 13 ++++++++--- .../core/handle/receiveAudioHandle.py | 2 ++ .../core/providers/llm/openai/openai.py | 10 ++++++--- .../xiaozhi-server/core/providers/tts/base.py | 2 +- .../providers/tts/huoshan_double_stream.py | 7 +++--- .../functions/handle_exit_intent.py | 1 + 8 files changed, 49 insertions(+), 12 deletions(-) diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index 20b55a91..850f6f7a 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -116,6 +116,8 @@ class ConnectionHandler: self.memory = _memory self.intent = _intent + self.is_exiting = False # 标记是否正在执行退出流程 + # 为每个连接单独管理声纹识别 self.voiceprint_provider = None @@ -289,6 +291,10 @@ class ConnectionHandler: async def _route_message(self, message): """消息路由""" + # 退出状态丢弃所有消息 + if self.is_exiting: + return + # 检查是否已经获取到真实的绑定状态 if not self.bind_completed_event.is_set(): # 还没有获取到真实状态,等待直到获取到真实状态或超时 @@ -991,11 +997,23 @@ class ConnectionHandler: ) futures_with_data.append((future, tool_call_data)) + TOOL_CALL_TIMEOUT = 30 # 等待协程结束(实际等待时长为最慢的那个) tool_results = [] for future, tool_call_data in futures_with_data: - result = future.result() - tool_results.append((result, tool_call_data)) + try: + result = future.result(timeout=TOOL_CALL_TIMEOUT) + tool_results.append((result, tool_call_data)) + except Exception as e: + self.logger.bind(tag=TAG).error( + f"工具调用超时或异常: {tool_call_data['name']}, 错误: {e}" + ) + # 超时时返回错误响应,避免整个流程卡死 + from plugins_func.register import Action, ActionResponse + tool_results.append(( + ActionResponse(action=Action.ERROR, result="哎呀,网络遇到点问题,请稍后再试下!"), + tool_call_data + )) # 统一处理所有工具调用结果 if tool_results: diff --git a/main/xiaozhi-server/core/handle/abortHandle.py b/main/xiaozhi-server/core/handle/abortHandle.py index b7bf1611..b74b2893 100644 --- a/main/xiaozhi-server/core/handle/abortHandle.py +++ b/main/xiaozhi-server/core/handle/abortHandle.py @@ -7,6 +7,10 @@ TAG = __name__ async def handleAbortMessage(conn: "ConnectionHandler"): + if conn.close_after_chat or conn.is_exiting: + conn.logger.bind(tag=TAG).info("退出流程中被打断,直接关闭连接") + return + conn.logger.bind(tag=TAG).info("Abort message received") # 设置成打断状态,会自动打断llm、tts任务 conn.client_abort = True diff --git a/main/xiaozhi-server/core/handle/intentHandler.py b/main/xiaozhi-server/core/handle/intentHandler.py index a9e3ee15..35ade945 100644 --- a/main/xiaozhi-server/core/handle/intentHandler.py +++ b/main/xiaozhi-server/core/handle/intentHandler.py @@ -32,6 +32,10 @@ async def handle_user_intent(conn: "ConnectionHandler", text): if await check_direct_exit(conn, filtered_text): return True + # 明确再见不被打断 + if conn.is_exiting: + return True + # 检查是否是唤醒词 if await checkWakeupWords(conn, filtered_text): return True @@ -57,6 +61,7 @@ async def check_direct_exit(conn: "ConnectionHandler", text): if text == cmd: conn.logger.bind(tag=TAG).info(f"识别到明确的退出命令: {text}") await send_stt_message(conn, text) + conn.is_exiting = True await conn.close() return True return False @@ -144,7 +149,9 @@ async def process_intent_result( # 使用executor执行函数调用和结果处理 def process_function_call(): conn.dialogue.put(Message(role="user", content=original_text)) - + + # 使用统一工具处理器处理所有工具调用,添加超时保护 + TOOL_CALL_TIMEOUT = 30 # 使用统一工具处理器处理所有工具调用 try: result = asyncio.run_coroutine_threadsafe( @@ -152,11 +159,11 @@ async def process_intent_result( conn, function_call_data ), conn.loop, - ).result() + ).result(timeout=TOOL_CALL_TIMEOUT) except Exception as e: conn.logger.bind(tag=TAG).error(f"工具调用失败: {e}") result = ActionResponse( - action=Action.ERROR, result=str(e), response=str(e) + action=Action.ERROR, result="工具调用超时,请一会再试下哈", response="工具调用超时,请一会再试下哈" ) if result: diff --git a/main/xiaozhi-server/core/handle/receiveAudioHandle.py b/main/xiaozhi-server/core/handle/receiveAudioHandle.py index 4f69aa99..280d72cf 100644 --- a/main/xiaozhi-server/core/handle/receiveAudioHandle.py +++ b/main/xiaozhi-server/core/handle/receiveAudioHandle.py @@ -15,6 +15,8 @@ TAG = __name__ async def handleAudioMessage(conn: "ConnectionHandler", audio): + if conn.is_exiting: + return # 当前片段是否有人说话 have_voice = conn.vad.is_vad(conn, audio) # 如果设备刚刚被唤醒,短暂忽略VAD检测 diff --git a/main/xiaozhi-server/core/providers/llm/openai/openai.py b/main/xiaozhi-server/core/providers/llm/openai/openai.py index 58ec725c..e6be8ddb 100644 --- a/main/xiaozhi-server/core/providers/llm/openai/openai.py +++ b/main/xiaozhi-server/core/providers/llm/openai/openai.py @@ -17,8 +17,12 @@ class LLMProvider(LLMProviderBase): self.base_url = config.get("base_url") else: self.base_url = config.get("url") - timeout = config.get("timeout", 300) - self.timeout = int(timeout) if timeout else 300 + custom_timeout = httpx.Timeout( + pool=2.0, + connect=3.0, + write=5.0, + read=10.0 + ) param_defaults = { "max_tokens": int, @@ -45,7 +49,7 @@ class LLMProvider(LLMProviderBase): model_key_msg = check_model_key("LLM", self.api_key) if model_key_msg: logger.bind(tag=TAG).error(model_key_msg) - self.client = openai.OpenAI(api_key=self.api_key, base_url=self.base_url, timeout=httpx.Timeout(self.timeout)) + self.client = openai.OpenAI(api_key=self.api_key, base_url=self.base_url, timeout=custom_timeout) @staticmethod def normalize_dialogue(dialogue): diff --git a/main/xiaozhi-server/core/providers/tts/base.py b/main/xiaozhi-server/core/providers/tts/base.py index 4fef87dd..bc99dcec 100644 --- a/main/xiaozhi-server/core/providers/tts/base.py +++ b/main/xiaozhi-server/core/providers/tts/base.py @@ -357,7 +357,7 @@ class TTSProviderBase(ABC): sendAudioMessage(self.conn, sentence_type, audio_datas, text), self.conn.loop, ) - future.result() + future.result(timeout=15) # 记录输出和报告 if self.conn.max_output_size > 0 and text: diff --git a/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py b/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py index 152aa33f..cdca9ed8 100644 --- a/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py +++ b/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py @@ -149,6 +149,7 @@ class TTSProvider(TTSProviderBase): self.cluster = config.get("cluster") self.resource_id = config.get("resource_id") self.activate_session = False + self.timeout = 30 if config.get("private_voice"): self.voice = config.get("private_voice") else: @@ -307,7 +308,7 @@ class TTSProvider(TTSProviderBase): self.start_session(self.conn.sentence_id), loop=self.conn.loop, ) - future.result() + future.result(self.timeout) self.before_stop_play_files.clear() logger.bind(tag=TAG).debug("TTS会话启动成功") except Exception as e: @@ -324,7 +325,7 @@ class TTSProvider(TTSProviderBase): self.text_to_speak(message.content_detail, None), loop=self.conn.loop, ) - future.result() + future.result(self.timeout) logger.bind(tag=TAG).debug("TTS文本发送成功") except Exception as e: logger.bind(tag=TAG).error(f"发送TTS文本失败: {str(e)}") @@ -344,7 +345,7 @@ class TTSProvider(TTSProviderBase): self.finish_session(self.conn.sentence_id), loop=self.conn.loop, ) - future.result() + future.result(self.timeout) except Exception as e: logger.bind(tag=TAG).error(f"结束TTS会话失败: {str(e)}") continue diff --git a/main/xiaozhi-server/plugins_func/functions/handle_exit_intent.py b/main/xiaozhi-server/plugins_func/functions/handle_exit_intent.py index bd24f372..154c4f89 100644 --- a/main/xiaozhi-server/plugins_func/functions/handle_exit_intent.py +++ b/main/xiaozhi-server/plugins_func/functions/handle_exit_intent.py @@ -31,6 +31,7 @@ handle_exit_intent_function_desc = { "handle_exit_intent", handle_exit_intent_function_desc, ToolType.SYSTEM_CTL ) def handle_exit_intent(conn: "ConnectionHandler", say_goodbye: str | None = None): + conn.is_exiting = True # 处理退出意图 try: if say_goodbye is None: From bcf03a0378c26f2991f325d0d88166341e073dbb Mon Sep 17 00:00:00 2001 From: lgy1027 Date: Wed, 11 Mar 2026 18:05:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=93=8D=E5=BA=94=E7=A4=BE?= =?UTF-8?q?=E5=8C=BA=E5=8F=8D=E9=A6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 工具调用超时改为可配置项 tool_call_timeout,默认30秒 - OpenAI 超时恢复可配置机制,支持细粒度配置和单一值 - TTS 超时保护统一添加到所有流式TTS实现 - 将 ActionResponse 导入移到文件顶部 - 修复超时配置边界情况处理 --- main/xiaozhi-server/config.yaml | 2 ++ main/xiaozhi-server/core/connection.py | 8 +++---- .../core/handle/intentHandler.py | 6 ++--- .../core/providers/llm/openai/openai.py | 22 ++++++++++++++----- .../core/providers/tts/alibl_stream.py | 6 ++--- .../core/providers/tts/aliyun_stream.py | 6 ++--- .../xiaozhi-server/core/providers/tts/base.py | 3 ++- .../providers/tts/huoshan_double_stream.py | 7 +++--- .../core/providers/tts/xunfei_stream.py | 4 ++-- 9 files changed, 38 insertions(+), 26 deletions(-) diff --git a/main/xiaozhi-server/config.yaml b/main/xiaozhi-server/config.yaml index c4662afa..ce6e6780 100644 --- a/main/xiaozhi-server/config.yaml +++ b/main/xiaozhi-server/config.yaml @@ -61,6 +61,8 @@ delete_audio: true close_connection_no_voice_time: 120 # TTS请求超时时间(秒) tts_timeout: 10 +# 工具调用超时时间(秒) +tool_call_timeout: 30 # 开启唤醒词加速 enable_wakeup_words_response_cache: true # 开场是否回复唤醒词 diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index 850f6f7a..5e069e79 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -32,7 +32,7 @@ from core.providers.asr.dto.dto import InterfaceType from core.handle.textHandle import handleTextMessage from core.providers.tools.unified_tool_handler import UnifiedToolHandler from plugins_func.loadplugins import auto_import_modules -from plugins_func.register import Action +from plugins_func.register import Action, ActionResponse from core.auth import AuthenticationError from config.config_loader import get_private_config_from_api from core.providers.tts.dto.dto import ContentType, TTSMessageDTO, SentenceType @@ -997,19 +997,19 @@ class ConnectionHandler: ) futures_with_data.append((future, tool_call_data)) - TOOL_CALL_TIMEOUT = 30 + # 工具调用超时时间,可配置,默认30秒 + tool_call_timeout = int(self.config.get("tool_call_timeout", 30)) # 等待协程结束(实际等待时长为最慢的那个) tool_results = [] for future, tool_call_data in futures_with_data: try: - result = future.result(timeout=TOOL_CALL_TIMEOUT) + result = future.result(timeout=tool_call_timeout) tool_results.append((result, tool_call_data)) except Exception as e: self.logger.bind(tag=TAG).error( f"工具调用超时或异常: {tool_call_data['name']}, 错误: {e}" ) # 超时时返回错误响应,避免整个流程卡死 - from plugins_func.register import Action, ActionResponse tool_results.append(( ActionResponse(action=Action.ERROR, result="哎呀,网络遇到点问题,请稍后再试下!"), tool_call_data diff --git a/main/xiaozhi-server/core/handle/intentHandler.py b/main/xiaozhi-server/core/handle/intentHandler.py index 35ade945..94c846df 100644 --- a/main/xiaozhi-server/core/handle/intentHandler.py +++ b/main/xiaozhi-server/core/handle/intentHandler.py @@ -150,8 +150,8 @@ async def process_intent_result( def process_function_call(): conn.dialogue.put(Message(role="user", content=original_text)) - # 使用统一工具处理器处理所有工具调用,添加超时保护 - TOOL_CALL_TIMEOUT = 30 + # 工具调用超时时间 + tool_call_timeout = int(conn.config.get("tool_call_timeout", 30)) # 使用统一工具处理器处理所有工具调用 try: result = asyncio.run_coroutine_threadsafe( @@ -159,7 +159,7 @@ async def process_intent_result( conn, function_call_data ), conn.loop, - ).result(timeout=TOOL_CALL_TIMEOUT) + ).result(timeout=tool_call_timeout) except Exception as e: conn.logger.bind(tag=TAG).error(f"工具调用失败: {e}") result = ActionResponse( diff --git a/main/xiaozhi-server/core/providers/llm/openai/openai.py b/main/xiaozhi-server/core/providers/llm/openai/openai.py index e6be8ddb..3d9882f3 100644 --- a/main/xiaozhi-server/core/providers/llm/openai/openai.py +++ b/main/xiaozhi-server/core/providers/llm/openai/openai.py @@ -17,12 +17,22 @@ class LLMProvider(LLMProviderBase): self.base_url = config.get("base_url") else: self.base_url = config.get("url") - custom_timeout = httpx.Timeout( - pool=2.0, - connect=3.0, - write=5.0, - read=10.0 - ) + + timeout_config = config.get("timeout") + if isinstance(timeout_config, dict): + # 细粒度超时配置 + custom_timeout = httpx.Timeout( + pool=timeout_config.get("pool", 2.0), + connect=timeout_config.get("connect", 3.0), + write=timeout_config.get("write", 5.0), + read=timeout_config.get("read", 60.0) + ) + elif isinstance(timeout_config, (int, float)) and timeout_config > 0: + # 兼容旧的单一超时配置(整数或浮点数) + custom_timeout = httpx.Timeout(timeout_config) + else: + # 未配置或配置无效,使用默认值 + custom_timeout = httpx.Timeout(300) param_defaults = { "max_tokens": int, diff --git a/main/xiaozhi-server/core/providers/tts/alibl_stream.py b/main/xiaozhi-server/core/providers/tts/alibl_stream.py index 8eb0f708..4ed9e559 100644 --- a/main/xiaozhi-server/core/providers/tts/alibl_stream.py +++ b/main/xiaozhi-server/core/providers/tts/alibl_stream.py @@ -127,7 +127,7 @@ class TTSProvider(TTSProviderBase): self.start_session(self.conn.sentence_id), loop=self.conn.loop, ) - future.result() + future.result(timeout=self.tts_timeout) self.before_stop_play_files.clear() logger.bind(tag=TAG).info("TTS会话启动成功") except Exception as e: @@ -144,7 +144,7 @@ class TTSProvider(TTSProviderBase): self.text_to_speak(message.content_detail, None), loop=self.conn.loop, ) - future.result() + future.result(timeout=self.tts_timeout) logger.bind(tag=TAG).debug("TTS文本发送成功") except Exception as e: logger.bind(tag=TAG).error(f"发送TTS文本失败: {str(e)}") @@ -165,7 +165,7 @@ class TTSProvider(TTSProviderBase): self.finish_session(self.conn.sentence_id), loop=self.conn.loop, ) - future.result() + future.result(timeout=self.tts_timeout) except Exception as e: logger.bind(tag=TAG).error(f"结束TTS会话失败: {str(e)}") continue diff --git a/main/xiaozhi-server/core/providers/tts/aliyun_stream.py b/main/xiaozhi-server/core/providers/tts/aliyun_stream.py index cf06e7ff..20a5a0c4 100644 --- a/main/xiaozhi-server/core/providers/tts/aliyun_stream.py +++ b/main/xiaozhi-server/core/providers/tts/aliyun_stream.py @@ -232,7 +232,7 @@ class TTSProvider(TTSProviderBase): self.start_session(self.task_id), loop=self.conn.loop, ) - future.result() + future.result(timeout=self.tts_timeout) self.before_stop_play_files.clear() logger.bind(tag=TAG).debug("TTS会话启动成功") @@ -250,7 +250,7 @@ class TTSProvider(TTSProviderBase): self.text_to_speak(message.content_detail, None), loop=self.conn.loop, ) - future.result() + future.result(timeout=self.tts_timeout) logger.bind(tag=TAG).debug("TTS文本发送成功") except Exception as e: logger.bind(tag=TAG).error(f"发送TTS文本失败: {str(e)}") @@ -270,7 +270,7 @@ class TTSProvider(TTSProviderBase): self.finish_session(self.task_id), loop=self.conn.loop, ) - future.result() + future.result(timeout=self.tts_timeout) except Exception as e: logger.bind(tag=TAG).error(f"结束TTS会话失败: {str(e)}") continue diff --git a/main/xiaozhi-server/core/providers/tts/base.py b/main/xiaozhi-server/core/providers/tts/base.py index bc99dcec..319494b1 100644 --- a/main/xiaozhi-server/core/providers/tts/base.py +++ b/main/xiaozhi-server/core/providers/tts/base.py @@ -36,6 +36,7 @@ class TTSProviderBase(ABC): self.delete_audio_file = delete_audio_file self.audio_file_type = "wav" self.output_file = config.get("output_dir", "tmp/") + self.tts_timeout = int(config.get("tts_timeout", 15)) self.tts_text_queue = queue.Queue() self.tts_audio_queue = queue.Queue() self.tts_audio_first_sentence = True @@ -357,7 +358,7 @@ class TTSProviderBase(ABC): sendAudioMessage(self.conn, sentence_type, audio_datas, text), self.conn.loop, ) - future.result(timeout=15) + future.result(timeout=self.tts_timeout) # 记录输出和报告 if self.conn.max_output_size > 0 and text: diff --git a/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py b/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py index cdca9ed8..bcaf75dd 100644 --- a/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py +++ b/main/xiaozhi-server/core/providers/tts/huoshan_double_stream.py @@ -149,7 +149,6 @@ class TTSProvider(TTSProviderBase): self.cluster = config.get("cluster") self.resource_id = config.get("resource_id") self.activate_session = False - self.timeout = 30 if config.get("private_voice"): self.voice = config.get("private_voice") else: @@ -308,7 +307,7 @@ class TTSProvider(TTSProviderBase): self.start_session(self.conn.sentence_id), loop=self.conn.loop, ) - future.result(self.timeout) + future.result(timeout=self.tts_timeout) self.before_stop_play_files.clear() logger.bind(tag=TAG).debug("TTS会话启动成功") except Exception as e: @@ -325,7 +324,7 @@ class TTSProvider(TTSProviderBase): self.text_to_speak(message.content_detail, None), loop=self.conn.loop, ) - future.result(self.timeout) + future.result(timeout=self.tts_timeout) logger.bind(tag=TAG).debug("TTS文本发送成功") except Exception as e: logger.bind(tag=TAG).error(f"发送TTS文本失败: {str(e)}") @@ -345,7 +344,7 @@ class TTSProvider(TTSProviderBase): self.finish_session(self.conn.sentence_id), loop=self.conn.loop, ) - future.result(self.timeout) + future.result(timeout=self.tts_timeout) except Exception as e: logger.bind(tag=TAG).error(f"结束TTS会话失败: {str(e)}") continue diff --git a/main/xiaozhi-server/core/providers/tts/xunfei_stream.py b/main/xiaozhi-server/core/providers/tts/xunfei_stream.py index be53284e..0434edbf 100644 --- a/main/xiaozhi-server/core/providers/tts/xunfei_stream.py +++ b/main/xiaozhi-server/core/providers/tts/xunfei_stream.py @@ -178,7 +178,7 @@ class TTSProvider(TTSProviderBase): self.start_session(self.conn.sentence_id), loop=self.conn.loop, ) - future.result() + future.result(timeout=self.tts_timeout) self.before_stop_play_files.clear() logger.bind(tag=TAG).info("TTS会话启动成功") @@ -197,7 +197,7 @@ class TTSProvider(TTSProviderBase): self.text_to_speak(message.content_detail, None), loop=self.conn.loop, ) - future.result() + future.result(timeout=self.tts_timeout) logger.bind(tag=TAG).debug("TTS文本发送成功") except Exception as e: logger.bind(tag=TAG).error(f"发送TTS文本失败: {str(e)}") From 140fcd5887d855d10a06843f1a1bffdd1b0d88ba Mon Sep 17 00:00:00 2001 From: Sakura-RanChen <1908198662@qq.com> Date: Wed, 1 Apr 2026 14:32:47 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=A1=A5=E5=85=85sql=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=94=99=E8=AF=AF=E8=AF=A6=E6=83=85=E4=B8=8A=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/db/changelog/202604011035.sql | 1 + .../main/resources/db/changelog/db.changelog-master.yaml | 8 +++++++- main/xiaozhi-server/core/connection.py | 8 +++++--- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 main/manager-api/src/main/resources/db/changelog/202604011035.sql diff --git a/main/manager-api/src/main/resources/db/changelog/202604011035.sql b/main/manager-api/src/main/resources/db/changelog/202604011035.sql new file mode 100644 index 00000000..7bf3f6bd --- /dev/null +++ b/main/manager-api/src/main/resources/db/changelog/202604011035.sql @@ -0,0 +1 @@ +INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (312, 'tool_call_timeout', '30', 'number', 1, '工具调用超时时间(秒)'); diff --git a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml index 77c5bfd3..caf089e3 100755 --- a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml @@ -585,4 +585,10 @@ databaseChangeLog: - sqlFile: encoding: utf8 path: classpath:db/changelog/202603311200.sql - + - changeSet: + id: 202604011035 + author: RanChen + changes: + - sqlFile: + encoding: utf8 + path: classpath:db/changelog/202604011035.sql diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index 49b51e75..d167bf1b 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -1117,6 +1117,9 @@ class ConnectionHandler: try: result = future.result(timeout=tool_call_timeout) tool_results.append((result, tool_call_data)) + # 使用公共方法上报工具调用结果 + enqueue_tool_report(self, tool_call_data['name'], tool_input, str(result.result) if result.result else None, report_tool_call=False) + except Exception as e: self.logger.bind(tag=TAG).error( f"工具调用超时或异常: {tool_call_data['name']}, 错误: {e}" @@ -1126,9 +1129,8 @@ class ConnectionHandler: ActionResponse(action=Action.ERROR, result="哎呀,网络遇到点问题,请稍后再试下!"), tool_call_data )) - - # 使用公共方法上报工具调用结果 - enqueue_tool_report(self, tool_call_data['name'], tool_input, str(result.result) if result.result else None, report_tool_call=False) + # 上报工具调用错误 + enqueue_tool_report(self, tool_call_data['name'], tool_input, str(e), report_tool_call=False) # 统一处理工具调用结果 if tool_results: