From 0bf778407fd57386874ae3435a9667edaaa98ba8 Mon Sep 17 00:00:00 2001 From: laojiahuo2003 <2944346255@qq.com> Date: Fri, 7 Nov 2025 19:32:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9tool=5Fcalls=E4=B8=BANone=E7=9A=84=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E7=9A=84=E8=BF=99=E4=B8=AA=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- slaver/agents/models.py | 10 ++++++---- slaver/agents/slaver_agent.py | 8 +++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/slaver/agents/models.py b/slaver/agents/models.py index 6f5becf..e2d653b 100644 --- a/slaver/agents/models.py +++ b/slaver/agents/models.py @@ -834,10 +834,12 @@ def postprocess_message( ) -> ChatMessage: """Sometimes APIs fail to properly parse a tool call: this function tries to parse.""" message.role = MessageRole.ASSISTANT # Overwrite role if needed - for tool_call in message.tool_calls: - tool_call.function.arguments = parse_json_if_needed( - tool_call.function.arguments - ) + # 修复:添加对tool_calls为None的检查 + if message.tool_calls: + for tool_call in message.tool_calls: + tool_call.function.arguments = parse_json_if_needed( + tool_call.function.arguments + ) return message diff --git a/slaver/agents/slaver_agent.py b/slaver/agents/slaver_agent.py index 486204b..0e7ed8f 100644 --- a/slaver/agents/slaver_agent.py +++ b/slaver/agents/slaver_agent.py @@ -8,6 +8,7 @@ import tempfile import textwrap import time +import uuid from collections import deque from logging import getLogger from pathlib import Path @@ -1174,7 +1175,12 @@ def step(self, memory_step: ActionStep) -> Union[None, Any]: tool_json = self._extract_json(final_answer) if tool_json: tool_name, tool_arguments = tool_json["name"], tool_json["arguments"] - tool_call_id = model_message.raw.id + # 修复:添加对model_message.raw和model_message.raw.id的空值检查 + if model_message.raw and hasattr(model_message.raw, 'id') and model_message.raw.id: + tool_call_id = model_message.raw.id + else: + # 如果无法获取id,则生成一个唯一的ID + tool_call_id = str(uuid.uuid4()) else: memory_step.action_output = final_answer return final_answer