Repository navigation
fix(bedrock): preserve tool choice for parallel tool calls - #28617
fuchengwarrenzhu wants to merge 6 commits into
Conversation
Preserve explicit Bedrock tool_choice intent when moving parallel_tool_calls configuration into Anthropic's Bedrock extension.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR fixes the Bedrock Converse transformation for
Confidence Score: 5/5Safe to merge — the change is narrowly scoped to Claude 4.5+ Bedrock models when The core fix correctly pops No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/chat/converse_transformation.py | Adds _map_bedrock_tool_choice_to_anthropic_tool_choice helper and uses it to inject the required Anthropic type discriminator into additionalModelRequestFields.tool_choice; pops tool_choice from inference_params early so it is not redundantly placed in toolConfig.toolChoice. |
| tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py | Strengthens existing test to assert the new type field, and adds two new test cases: one for parallel_tool_calls=True and a parametrised matrix covering all three explicit tool_choice modes with both parallel_tool_calls values. |
| tests/test_litellm/interactions/test_openapi_compliance.py | Adds budget_exceeded to the expected status enum list to match the updated live Google Interactions OpenAPI spec, fixing an unrelated CI failure. |
| docker/Dockerfile.non_root | Adds libatomic to both the builder and runtime apk add stages to satisfy Prisma's Node binary libatomic.so.1 dependency on Wolfi/Alpine. |
Reviews (1): Last reviewed commit: "Cover explicit tool choice with parallel..." | Re-trigger Greptile
Greptile SummaryThis PR fixes Bedrock Claude 4.5+ requests that were rejected when
Confidence Score: 4/5Safe to merge — the change is narrowly scoped to the Claude 4.5+ parallel-tool-calls path on Bedrock, older models are unaffected, and the transformation logic is covered by new unit tests. The core transformation is straightforward: a new helper maps the Bedrock ToolChoiceValuesBlock to the Anthropic type discriminator, and the merge order ({**anthropic_tool_choice, **value}) is correct because the parallel_tool_use_config value only carries disable_parallel_tool_use and never a competing type key. The pop at transform time correctly prevents tool_choice from also landing in toolConfig.toolChoice. One minor scenario worth awareness: if a caller somehow constructs a SpecificToolChoiceBlock with an empty name, the mapper returns {"type": "tool"} without a name field, which Anthropic may reject — but that path requires invalid upstream input and is already a latent issue in map_tool_choice_values. converse_transformation.py deserves a final read-through, specifically the interaction between the new inference_params.pop("tool_choice") at line 1262 and the existing pop at line 1540 — both are correct but easy to misread during future refactors.
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/chat/converse_transformation.py | Adds _map_bedrock_tool_choice_to_anthropic_tool_choice helper and wires it into the parallel_tool_calls path to inject the required Anthropic type discriminator; pops tool_choice from inference_params so it doesn't also land in toolConfig.toolChoice. |
| tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py | Strengthens existing parallel-tool-calls test with a type assertion and adds two new pure unit tests covering parallel_tool_calls=True and all explicit tool_choice/parallel_tool_calls combinations; no real network calls. |
| tests/test_litellm/interactions/test_openapi_compliance.py | Adds budget_exceeded to expected Interaction.status enum to match the upstream Google Interactions OpenAPI spec change; pre-existing test that fetches the live spec. |
| docker/Dockerfile.non_root | Adds libatomic to both the builder and runtime Alpine/Wolfi package lists to satisfy Prisma's Node binary dependency. |
Reviews (2): Last reviewed commit: "Cover explicit tool choice with parallel..." | Re-trigger Greptile
|
🤖 litellm-agent: This PR is currently BLOCKED from merge. Score: 3/5 ❌ Why blocked:
Details: Score docked for: 1 PR-related CI failure (This PR will be auto-closed as it lacks a screenshot for proof of fix. Please include one in the PR description. Add the Fix the issues above and push an update — the bot will re-review automatically.
|
|
@litellm-bot review — current head |
| done && \ | ||
| for i in 1 2 3; do \ | ||
| apk add --no-cache python3 bash openssl tzdata libsndfile nodejs && break || sleep 5; \ | ||
| apk add --no-cache python3 bash openssl tzdata libsndfile libatomic nodejs && break || sleep 5; \ |
Relevant issues
Fixes #22637
Related stale PR: #22638
Replaces #28509, which became unreopenable after the temporary
shin_agent_oss_staging_05_21_2026base branch was deleted.Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, adding at least 1 test is a hard requirement - see details@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewScreenshots / Proof of Fix
The terminal proof compares the contribution base (
base_*) with this PR head (head_*). The base request is rejected becauseadditionalModelRequestFields.tool_choice.typeis missing andtoolConfig.toolChoiceis still present. The PR head request succeeds with{"disable_parallel_tool_use": false, "name": "get_weather", "type": "tool"}and no duplicatetoolConfig.toolChoiceentry.Type
Bug Fix
Test
Changes
This fixes the Bedrock Claude 4.5+
parallel_tool_callsrequest shape foradditionalModelRequestFields.tool_choice.Current upstream code on the contribution base still creates:
{"tool_choice": {"disable_parallel_tool_use": bool}}The Anthropic Bedrock extension requires a
typediscriminator. Without it, Bedrock rejects the request withtool_choice.type: Field required.This PR:
typeforparallel_tool_calls=Trueandparallel_tool_calls=False;tool_choiceintent whenparallel_tool_callsis also present:tool_choice="auto"->{"type": "auto", ...};tool_choice="required"->{"type": "any", ...};{"type": "tool", "name": "...", ...};toolConfig.toolChoicewhen that explicit choice has been moved intoadditionalModelRequestFields.tool_choice;Difference from #22638: that PR adds
type: "auto"for the base bug, but it does not preserve explicittool_choice="required"or named-tool choices when combined withparallel_tool_calls, and it is currently merge-conflicting.This PR also keeps current LiteLLM CI green by:
budget_exceededto the Google Interactions OpenAPIInteraction.statusexpectation, matching the live spec;libatomicto the non-root Dockerfile package lists required by Prisma Node binaries.Testing
UV_CACHE_DIR=/private/tmp/uv-cache-litellm uv run --no-sync pytest tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py -k parallel_tool_calls -q->9 passed, 119 deselectedUV_CACHE_DIR=/private/tmp/uv-cache-litellm uv run --no-sync pytest tests/test_litellm/interactions/test_openapi_compliance.py -q->13 passedUV_CACHE_DIR=/private/tmp/uv-cache-litellm uv run --no-sync black --check litellm/llms/bedrock/chat/converse_transformation.py tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py->2 files would be left unchangedUV_CACHE_DIR=/private/tmp/uv-cache-litellm uv run --no-sync ruff check litellm/llms/bedrock/chat/converse_transformation.py->All checks passedgit diff --check-> passed