Anthropic rejects when multiple tool_result are split across separate messages #81

Open
opened 2026-02-15 17:15:33 -05:00 by yindo · 0 comments
Owner

Originally created by @briascoi on GitHub (Feb 5, 2026).

Summary

When one assistant message contains multiple tool_use blocks, OpenClaw writes each tool_result as a separate message. Anthropic requires all tool_result blocks to appear in the immediately following message. This causes a 400 error.

Environment

  • OpenClaw version: 2026.2.2-3
  • Provider: google-antigravity / Claude Opus 4.5 Thinking
  • OS: Linux
  • Session file: /home/molt/.openclaw/agents/main/sessions/67604464-5353-4655-8086-796d5151cfe2.jsonl

Minimal repro

  1. In a single assistant response, call two tools (e.g. two read calls).
  2. Observe OpenClaw writes two separate tool_result messages.
  3. Anthropic rejects with:
    tool_use ids were found without tool_result blocks immediately after...

JSONL snippet (redacted payloads)

[
  {
    "type": "message",
    "id": "c3412c69",
    "parentId": "313d8bac",
    "timestamp": "2026-02-05T19:08:53.219Z",
    "message": {
      "role": "assistant",
      "content": [
        { "type": "toolCall", "id": "toolu_vrtx_012BRiUia3H6raM8ez18KXgX", "name": "read", "arguments": { "file_path": "<redacted>" } },
        { "type": "toolCall", "id": "toolu_vrtx_01D8fR7fHsUPBK8icsbp5rAc", "name": "read", "arguments": { "file_path": "<redacted>" } }
      ],
      "stopReason": "toolUse"
    }
  },
  {
    "type": "message",
    "id": "06dc6420",
    "parentId": "c3412c69",
    "timestamp": "2026-02-05T19:08:53.251Z",
    "message": {
      "role": "toolResult",
      "toolCallId": "toolu_vrtx_012BRiUia3H6raM8ez18KXgX",
      "toolName": "read",
      "content": [ { "type": "text", "text": "<redacted tool_result payload>" } ]
    }
  },
  {
    "type": "message",
    "id": "31d345d0",
    "parentId": "06dc6420",
    "timestamp": "2026-02-05T19:08:53.315Z",
    "message": {
      "role": "toolResult",
      "toolCallId": "toolu_vrtx_01D8fR7fHsUPBK8icsbp5rAc",
      "toolName": "read",
      "content": [ { "type": "text", "text": "<redacted tool_result payload>" } ]
    }
  }
]

Error

Cloud Code Assist API error (400):
messages.246: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_vrtx_01D8fR7fHsUPBK8icsbp5rAc.
Each `tool_use` block must have a corresponding `tool_result` block in the next message.

Expected

If there are multiple tool calls in one assistant message:

  • emit one tool_result message containing all tool_result blocks, or
  • enforce max_tool_calls=1.

Actual

Each tool_result is persisted in its own message, which violates Anthropic’s tool protocol.

Originally created by @briascoi on GitHub (Feb 5, 2026). ### Summary When one assistant message contains multiple tool_use blocks, OpenClaw writes each tool_result as a separate message. Anthropic requires all tool_result blocks to appear in the *immediately following* message. This causes a 400 error. ### Environment - OpenClaw version: 2026.2.2-3 - Provider: google-antigravity / Claude Opus 4.5 Thinking - OS: Linux - Session file: /home/molt/.openclaw/agents/main/sessions/67604464-5353-4655-8086-796d5151cfe2.jsonl ### Minimal repro 1) In a single assistant response, call two tools (e.g. two `read` calls). 2) Observe OpenClaw writes two separate tool_result messages. 3) Anthropic rejects with: `tool_use ids were found without tool_result blocks immediately after...` ### JSONL snippet (redacted payloads) ```json [ { "type": "message", "id": "c3412c69", "parentId": "313d8bac", "timestamp": "2026-02-05T19:08:53.219Z", "message": { "role": "assistant", "content": [ { "type": "toolCall", "id": "toolu_vrtx_012BRiUia3H6raM8ez18KXgX", "name": "read", "arguments": { "file_path": "<redacted>" } }, { "type": "toolCall", "id": "toolu_vrtx_01D8fR7fHsUPBK8icsbp5rAc", "name": "read", "arguments": { "file_path": "<redacted>" } } ], "stopReason": "toolUse" } }, { "type": "message", "id": "06dc6420", "parentId": "c3412c69", "timestamp": "2026-02-05T19:08:53.251Z", "message": { "role": "toolResult", "toolCallId": "toolu_vrtx_012BRiUia3H6raM8ez18KXgX", "toolName": "read", "content": [ { "type": "text", "text": "<redacted tool_result payload>" } ] } }, { "type": "message", "id": "31d345d0", "parentId": "06dc6420", "timestamp": "2026-02-05T19:08:53.315Z", "message": { "role": "toolResult", "toolCallId": "toolu_vrtx_01D8fR7fHsUPBK8icsbp5rAc", "toolName": "read", "content": [ { "type": "text", "text": "<redacted tool_result payload>" } ] } } ] ``` ### Error ``` Cloud Code Assist API error (400): messages.246: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_vrtx_01D8fR7fHsUPBK8icsbp5rAc. Each `tool_use` block must have a corresponding `tool_result` block in the next message. ``` ### Expected If there are multiple tool calls in one assistant message: - emit **one** tool_result message containing **all** tool_result blocks, or - enforce `max_tool_calls=1`. ### Actual Each tool_result is persisted in its own message, which violates Anthropic’s tool protocol.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: openclaw/clawhub#81