diff --git a/main/xiaozhi-server/config/logger.py b/main/xiaozhi-server/config/logger.py index a99013aa..7cff241c 100644 --- a/main/xiaozhi-server/config/logger.py +++ b/main/xiaozhi-server/config/logger.py @@ -114,6 +114,7 @@ def update_module_string(selected_module_str): current_module = logger._core.extra["selected_module"] if current_module == selected_module_str: + logger.debug(f"组件未更改无需更新") return try: diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index 9102b76d..cf9a157d 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -424,6 +424,14 @@ class ConnectionHandler: init_vad = check_vad_update(self.common_config, private_config) init_asr = check_asr_update(self.common_config, private_config) + if init_vad: + self.config["selected_module"]["VAD"] = private_config["selected_module"][ + "VAD" + ] + if init_asr: + self.config["selected_module"]["ASR"] = private_config["selected_module"][ + "ASR" + ] if private_config.get("TTS", None) is not None: init_tts = True self.config["TTS"] = private_config["TTS"] @@ -612,7 +620,7 @@ class ConnectionHandler: uuid_str = str(uuid.uuid4()).replace("-", "") self.sentence_id = uuid_str - if functions is not None: + if self.intent_type == "function_call" and functions is not None: # 使用支持functions的streaming接口 llm_responses = self.llm.response_with_functions( self.session_id, @@ -639,7 +647,7 @@ class ConnectionHandler: for response in llm_responses: if self.client_abort: break - if functions is not None: + if self.intent_type == "function_call" and functions is not None: content, tools_call = response if "content" in response: content = response["content"] diff --git a/main/xiaozhi-server/core/handle/intentHandler.py b/main/xiaozhi-server/core/handle/intentHandler.py index 35660bdf..027a03a6 100644 --- a/main/xiaozhi-server/core/handle/intentHandler.py +++ b/main/xiaozhi-server/core/handle/intentHandler.py @@ -1,11 +1,13 @@ import json +import asyncio import uuid from core.handle.sendAudioHandle import send_stt_message from core.handle.helloHandle import checkWakeupWords from core.utils.util import remove_punctuation_and_length from core.providers.tts.dto.dto import ContentType from core.utils.dialogue import Message -from plugins_func.register import Action +from core.handle.mcpHandle import call_mcp_tool +from plugins_func.register import Action, ActionResponse from loguru import logger TAG = __name__ @@ -101,10 +103,38 @@ async def process_intent_result(conn, intent_result, original_text): # 使用executor执行函数调用和结果处理 def process_function_call(): conn.dialogue.put(Message(role="user", content=original_text)) - result = conn.func_handler.handle_llm_function_call( - conn, function_call_data - ) - logger.bind(tag=TAG).debug(f"检测到Action : {result.action}") + + # 处理Server端MCP工具调用 + if conn.mcp_manager.is_mcp_tool(function_name): + result = conn._handle_mcp_tool_call(function_call_data) + elif hasattr(conn, "mcp_client") and conn.mcp_client.has_tool( + function_name + ): + # 如果是小智端MCP工具调用 + conn.logger.bind(tag=TAG).debug( + f"调用小智端MCP工具: {function_name}, 参数: {function_args}" + ) + try: + result = asyncio.run_coroutine_threadsafe( + call_mcp_tool( + conn, conn.mcp_client, function_name, function_args + ), + conn.loop, + ).result() + conn.logger.bind(tag=TAG).debug(f"MCP工具调用结果: {result}") + result = ActionResponse( + action=Action.REQLLM, result=result, response="" + ) + except Exception as e: + conn.logger.bind(tag=TAG).error(f"MCP工具调用失败: {e}") + result = ActionResponse( + action=Action.REQLLM, result="MCP工具调用失败", response="" + ) + else: + # 处理系统函数 + result = conn.func_handler.handle_llm_function_call( + conn, function_call_data + ) if result: if result.action == Action.RESPONSE: # 直接回复前端 diff --git a/main/xiaozhi-server/core/providers/intent/intent_llm/intent_llm.py b/main/xiaozhi-server/core/providers/intent/intent_llm/intent_llm.py index 29605393..3eafced8 100644 --- a/main/xiaozhi-server/core/providers/intent/intent_llm/intent_llm.py +++ b/main/xiaozhi-server/core/providers/intent/intent_llm/intent_llm.py @@ -151,6 +151,13 @@ class IntentProvider(IntentProviderBase): if self.promot == "": functions = conn.func_handler.get_functions() + if hasattr(conn, "mcp_client"): + mcp_tools = conn.mcp_client.get_available_tools() + if mcp_tools is not None and len(mcp_tools) > 0: + if functions is None: + functions = [] + functions.extend(mcp_tools) + self.promot = self.get_intent_system_prompt(functions) music_config = initialize_music_handler(conn)