mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-28 00:18:25 -05:00
fix: save assistant message with tool_call before pending result
The LLM requires an assistant message with tool_calls to exist before any tool result messages. This fixes the error: "unexpected tool_use_id found in tool_result blocks"
This commit is contained in:
@@ -1384,7 +1384,15 @@ async def _yield_tool_call(
|
||||
"check back in a few minutes."
|
||||
)
|
||||
|
||||
# Save "pending" tool response to chat history immediately
|
||||
# Save assistant message with tool_call FIRST (required by LLM)
|
||||
assistant_message = ChatMessage(
|
||||
role="assistant",
|
||||
content="",
|
||||
tool_calls=[tool_calls[yield_idx]],
|
||||
)
|
||||
session.messages.append(assistant_message)
|
||||
|
||||
# Then save pending tool result
|
||||
pending_message = ChatMessage(
|
||||
role="tool",
|
||||
content=OperationPendingResponse(
|
||||
|
||||
Reference in New Issue
Block a user