Title: Tool results interleaved with image blocks break Anthropic API (tool_use without immediate tool_result)
Extension version: 3.78.0
Provider: Anthropic (claude-opus-5 / claude-fable-5)
Summary
When an assistant turn issues multiple tool_use blocks and the following user turn includes images (e.g. from read_file on an image, screenshots, or tool output), Zoo Code builds the user message with image blocks interleaved between tool_result blocks. Anthropic requires every tool_use to have a matching tool_result immediately in the next message, with results contiguous. The interleaved layout causes a hard 400 and the task cannot continue without manually editing api_conversation_history.json.
Error
text400 invalid_request_error
messages.N: tool_use ids were found without tool_result blocks immediately after: toolu_...
Each tool_use block must have a corresponding tool_result block in the next message.
Actual message shape (broken)
Assistant (msg N):
texttool_use id=A
tool_use id=B
User (msg N+1) — what Zoo Code stores:
text[0] tool_result id=A
[1] image
[2] tool_result id=B
[3] image
[4] text (environment_details)
Expected shape
text[0] tool_result id=A
[1] tool_result id=B
[2] image (optional, after all results)
[3] image
[4] text
Repro (typical)
Task with Anthropic provider, tools enabled.
Agent issues parallel tools that involve reading/viewing images (or any path that attaches image content to tool results).
Next API request fails with the orphaned tool_use error above.
Inspect api_conversation_history.json: tool_result blocks are present but not contiguous at the start of the user message.
Workaround
Manually reorder the user message so all tool_result blocks come first, then images/text. After that the same task resumes successfully.
Why this matters
Corrupts long-running tasks permanently until history is hand-edited.
Shows up repeatedly on vision / screenshot / image-read turns.
Anthropic’s rule is strict; clients must emit contiguous tool_results immediately after tool_use.
Suggested fix
When assembling the user message that follows a multi-tool_use assistant turn, always emit all tool_result blocks first (in tool_use order), then any image or text blocks. Do not interleave images between results.
Title: Tool results interleaved with image blocks break Anthropic API (tool_use without immediate tool_result)
Extension version: 3.78.0
Provider: Anthropic (claude-opus-5 / claude-fable-5)
Summary
When an assistant turn issues multiple tool_use blocks and the following user turn includes images (e.g. from read_file on an image, screenshots, or tool output), Zoo Code builds the user message with image blocks interleaved between tool_result blocks. Anthropic requires every tool_use to have a matching tool_result immediately in the next message, with results contiguous. The interleaved layout causes a hard 400 and the task cannot continue without manually editing api_conversation_history.json.
Error
text400 invalid_request_error
messages.N:
tool_useids were found withouttool_resultblocks immediately after: toolu_...Each
tool_useblock must have a correspondingtool_resultblock in the next message.Actual message shape (broken)
Assistant (msg N):
texttool_use id=A
tool_use id=B
User (msg N+1) — what Zoo Code stores:
text[0] tool_result id=A
[1] image
[2] tool_result id=B
[3] image
[4] text (environment_details)
Expected shape
text[0] tool_result id=A
[1] tool_result id=B
[2] image (optional, after all results)
[3] image
[4] text
Repro (typical)
Task with Anthropic provider, tools enabled.
Agent issues parallel tools that involve reading/viewing images (or any path that attaches image content to tool results).
Next API request fails with the orphaned tool_use error above.
Inspect api_conversation_history.json: tool_result blocks are present but not contiguous at the start of the user message.
Workaround
Manually reorder the user message so all tool_result blocks come first, then images/text. After that the same task resumes successfully.
Why this matters
Corrupts long-running tasks permanently until history is hand-edited.
Shows up repeatedly on vision / screenshot / image-read turns.
Anthropic’s rule is strict; clients must emit contiguous tool_results immediately after tool_use.
Suggested fix
When assembling the user message that follows a multi-tool_use assistant turn, always emit all tool_result blocks first (in tool_use order), then any image or text blocks. Do not interleave images between results.