Fix parallel tool calls in the Anthropic passthrough adapter #15315
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title
Fix parallel tool calls in the Anthropic passthrough adapter
Relevant issues
Fixes #15307
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/
directory, Adding at least 1 test is a hard requirement - see detailsMy PR passes all unit tests onwill rely on CImake test-unit
Type
🐛 Bug Fix
Changes
This PR adds support for parallel tool calling for models that can stream multiple back-to-back tool calls. We do this by adding an additional fall-through behaviour to the
_should_start_new_content_block
check: if the current block type is atool_use
block, and we have a name, this is necessarily a new tool call.This matches the behaviour of what OpenAI and Anthropic return.
OpenAI's example:
Anthropic's example:
So as long as we get a
name
, this block should necessarily be a new tool call.Test plan
See the repro script and full configuration in the original issue. With the changes, we now get:
So we're now parsing multiple back-to-back tool calls properly.