mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix: prevent duplicate tool messages for long-running operations
Skip saving operation_started and operation_in_progress responses to
tool_response_messages since the pending message is already saved to
the session. This prevents duplicate tool_result blocks which caused
LLM errors ("each tool_use must have a single result").
This commit is contained in:
@@ -427,13 +427,19 @@ async def stream_chat_completion(
|
||||
if isinstance(chunk.output, str)
|
||||
else orjson.dumps(chunk.output).decode("utf-8")
|
||||
)
|
||||
tool_response_messages.append(
|
||||
ChatMessage(
|
||||
role="tool",
|
||||
content=result_content,
|
||||
tool_call_id=chunk.toolCallId,
|
||||
)
|
||||
# Skip saving long-running operation responses - pending message already saved
|
||||
is_long_running_response = any(
|
||||
op_type in result_content
|
||||
for op_type in ('"operation_started"', '"operation_in_progress"')
|
||||
)
|
||||
if not is_long_running_response:
|
||||
tool_response_messages.append(
|
||||
ChatMessage(
|
||||
role="tool",
|
||||
content=result_content,
|
||||
tool_call_id=chunk.toolCallId,
|
||||
)
|
||||
)
|
||||
has_done_tool_call = True
|
||||
# Track if any tool execution failed
|
||||
if not chunk.success:
|
||||
|
||||
Reference in New Issue
Block a user