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