Merge branch 'main' into agent-plugin

This commit is contained in:
hrz
2025-06-11 23:07:33 +08:00
3 changed files with 44 additions and 7 deletions
+2 -2
View File
@@ -617,7 +617,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,
@@ -644,7 +644,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"]
@@ -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: # 直接回复前端
@@ -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)