Merge pull request #22267 from BerriAI/litellm_fixParallel_tool_cal

Fix converse handling for parallel_tool_calls
This commit is contained in:
Sameer Kankute 2026-02-27 21:16:44 +05:30 • committed by GitHub
commit f297036401
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 85 additions and 0 deletions

View file

@ -1207,6 +1207,17 @@ class AmazonConverseConfig(BaseConfig):
k: v for k, v in inference_params.items() if k in total_supported_params
}
# Handle parallel_tool_calls configuration
parallel_tool_use_config = additional_request_params.pop("_parallel_tool_use_config", None)
if parallel_tool_use_config is not None and is_claude_4_5_on_bedrock(model):
for key, value in parallel_tool_use_config.items():
if key in additional_request_params and isinstance(additional_request_params[key], dict) and isinstance(value, dict):
additional_request_params[key].update(value)
else:
additional_request_params[key] = value
additional_request_params.pop("parallel_tool_calls", None)
# Only set the topK value in for models that support it
additional_request_params.update(
self._handle_top_k_value(model, inference_params)

View file

@ -3377,6 +3377,80 @@ def test_output_config_applies_additional_properties():
_TOOL_PARAM = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the weather",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The location to get weather for",
}
},
"required": ["location"],
},
},
}
]
def test_parallel_tool_calls_newer_model_adds_disable_flag():
"""Newer Claude models (4.5+) should get disable_parallel_tool_use in additionalModelRequestFields."""
config = AmazonConverseConfig()
model = "anthropic.claude-sonnet-4-5-20250929-v1:0"
messages = [{"role": "user", "content": "What's the weather in SF and NYC?"}]
optional_params = config.map_openai_params(
non_default_params={"parallel_tool_calls": False, "tools": _TOOL_PARAM},
optional_params={},
model=model,
drop_params=False,
)
request_data = config.transform_request(
model=model,
messages=messages,
optional_params=optional_params,
litellm_params={},
headers={},
)
assert "additionalModelRequestFields" in request_data
assert "tool_choice" in request_data["additionalModelRequestFields"]
assert request_data["additionalModelRequestFields"]["tool_choice"]["disable_parallel_tool_use"] is True
assert "parallel_tool_calls" not in request_data["additionalModelRequestFields"]
def test_parallel_tool_calls_older_model_drops_disable_flag():
"""Older Claude models (pre-4.5) must NOT receive disable_parallel_tool_use — Bedrock rejects it."""
config = AmazonConverseConfig()
model = "anthropic.claude-3-5-sonnet-20241022-v2:0"
messages = [{"role": "user", "content": "What's the weather in SF and NYC?"}]
optional_params = config.map_openai_params(
non_default_params={"parallel_tool_calls": False, "tools": _TOOL_PARAM},
optional_params={},
model=model,
drop_params=False,
)
request_data = config.transform_request(
model=model,
messages=messages,
optional_params=optional_params,
litellm_params={},
headers={},
)
additional = request_data.get("additionalModelRequestFields", {})
assert "tool_choice" not in additional
assert "parallel_tool_calls" not in additional
class TestBedrockMinThinkingBudgetTokens:
"""Test that thinking.budget_tokens is clamped to the Bedrock minimum (1024)."""