Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions slaver/agents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 7 additions & 1 deletion slaver/agents/slaver_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import tempfile
import textwrap
import time
import uuid
from collections import deque
from logging import getLogger
from pathlib import Path
Expand Down Expand Up @@ -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
Expand Down