From 975cc4705dc6f51ac40d9a5bd87bd2c4e3649bf1 Mon Sep 17 00:00:00 2001 From: FuQuan233 Date: Mon, 1 Jun 2026 14:35:47 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E8=B0=83=E7=94=A8=E5=8F=82=E6=95=B0=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=B9=B6=E8=AE=B0=E5=BD=95=E8=AD=A6=E5=91=8A?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_llmchat/__init__.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/nonebot_plugin_llmchat/__init__.py b/nonebot_plugin_llmchat/__init__.py index 92a3060..d502cd9 100755 --- a/nonebot_plugin_llmchat/__init__.py +++ b/nonebot_plugin_llmchat/__init__.py @@ -479,7 +479,20 @@ async def process_messages(context_id: int, is_group: bool = True): for tool_call in message.tool_calls: tool_name = tool_call.function.name - tool_args = json.loads(tool_call.function.arguments) + try: + tool_args = json.loads(tool_call.function.arguments) + except (json.JSONDecodeError, TypeError, ValueError) as e: + error_message = ( + f"工具调用参数格式错误,无法解析 {tool_name} 的 arguments: {e!s}. " + f"原始参数: {tool_call.function.arguments}" + ) + logger.warning(error_message) + new_messages.append({ + "role": "tool", + "tool_call_id": tool_call.id, + "content": error_message, + }) + continue # 发送工具调用提示 await handler.send(Message(f"正在使用{mcp_client.get_friendly_name(tool_name)}"))