Skip to content

Commit 35d6fe7

Browse files
Fix:check tool_calls return (#72)
1 parent 4e8e92b commit 35d6fe7

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

slaver/agents/models.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -834,10 +834,12 @@ def postprocess_message(
834834
) -> ChatMessage:
835835
"""Sometimes APIs fail to properly parse a tool call: this function tries to parse."""
836836
message.role = MessageRole.ASSISTANT # Overwrite role if needed
837-
for tool_call in message.tool_calls:
838-
tool_call.function.arguments = parse_json_if_needed(
839-
tool_call.function.arguments
840-
)
837+
# 修复:添加对tool_calls为None的检查
838+
if message.tool_calls:
839+
for tool_call in message.tool_calls:
840+
tool_call.function.arguments = parse_json_if_needed(
841+
tool_call.function.arguments
842+
)
841843
return message
842844

843845

slaver/agents/slaver_agent.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import tempfile
99
import textwrap
1010
import time
11+
import uuid
1112
from collections import deque
1213
from logging import getLogger
1314
from pathlib import Path
@@ -1174,7 +1175,12 @@ def step(self, memory_step: ActionStep) -> Union[None, Any]:
11741175
tool_json = self._extract_json(final_answer)
11751176
if tool_json:
11761177
tool_name, tool_arguments = tool_json["name"], tool_json["arguments"]
1177-
tool_call_id = model_message.raw.id
1178+
# 修复:添加对model_message.raw和model_message.raw.id的空值检查
1179+
if model_message.raw and hasattr(model_message.raw, 'id') and model_message.raw.id:
1180+
tool_call_id = model_message.raw.id
1181+
else:
1182+
# 如果无法获取id,则生成一个唯一的ID
1183+
tool_call_id = str(uuid.uuid4())
11781184
else:
11791185
memory_step.action_output = final_answer
11801186
return final_answer

0 commit comments

Comments
 (0)