Skip to content

Issues w/ async parallel tool calls when using AWS bedrock #169

@ndebard

Description

@ndebard

I ran into this bug (deterministically) in a workflow where I ask URSA to read 3 docs, it uses read_file tool 3 times async and then there's a merged tool result coming back. Apparently (according to Chat) this is a known bug (BerriAI/litellm#5277).

Chat says:

The AIMessage contains 3 tool calls with IDs tooluse_...
You append 3 ToolMessages with matching tool_call_id
ToolMessage content is a plain str
So the bug is not in your loop.
What the bug actually is
It’s downstream in the gateway that translates “OpenAI-style tool messages” into the Bedrock/Anthropic tool schema.
Bedrock’s Anthropic tool format requires that all tool results from the previous assistant turn be delivered as toolResult blocks in the next message’s content array (and effectively grouped correctly). The error you’re getting (“Expected toolResult blocks at messages.2.content…”) matches a known class of failures where the translator doesn’t merge / place multiple tool results correctly for Bedrock.
In other words: you’re sending 3 tool results correctly (OpenAI style), but the Bedrock adapter is failing to package them as toolResult blocks in the place Bedrock expects.
Why you see it now
Your model is doing parallel tool calling (3 read_file calls in one turn). That’s the trigger for this specific Bedrock toolResult error in a bunch of adapters.

It suggests disabling parallel tool calls:
llm_kwargs = _deep_merge_dicts(llm_kwargs, {"parallel_tool_calls": False})
or
llm_with_tools = llm_with_tools.bind(parallel_tool_calls=False)

I will experiment with this, but this is probably going to come up in other places for other users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions