This commit is contained in:
AYUSH ARORA 2026-09-13 00:10:35 +08:00 committed by GitHub
commit 409ba81404
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 8 deletions

View file

@ -1614,14 +1614,7 @@ class AmazonConverseConfig(BaseConfig):
Bedrock doesn't support tool calling without `tools=` param specified.
"""
if "tools" not in optional_params and messages is not None and has_tool_call_blocks(messages):
if litellm.modify_params:
optional_params["tools"] = add_dummy_tool(custom_llm_provider="bedrock_converse")
else:
raise litellm.UnsupportedParamsError(
message="Bedrock doesn't support tool calling without `tools=` param specified. Pass `tools=` param OR set `litellm.modify_params = True` // `litellm_settings::modify_params: True` to add dummy tool to the request.",
model="",
llm_provider="bedrock",
)
optional_params["tools"] = add_dummy_tool(custom_llm_provider="bedrock_converse")
# Drop thinking param if thinking is enabled but thinking_blocks are missing
# This prevents the error: "Expected thinking or redacted_thinking, but found tool_use"

View file

@ -6953,3 +6953,40 @@ def test_transform_response_honors_json_mode_kwarg_when_optional_params_lack_it(
)
assert result.choices[0].message.tool_calls is None
assert json.loads(result.choices[0].message.content) == {"city": "Paris", "population": 2100000}
def test_transform_request_injects_dummy_tool_without_tools_param(monkeypatch):
from litellm.llms.bedrock.chat.converse_transformation import AmazonConverseConfig
monkeypatch.setattr(litellm, "modify_params", False)
config = AmazonConverseConfig()
messages = [
{"role": "user", "content": "Hello"},
{
"role": "assistant",
"content": "Calling tool",
"tool_calls": [
{
"id": "tooluse_test_dummy",
"type": "function",
"function": {"name": "get_x", "arguments": "{}"},
}
],
},
{
"role": "tool",
"tool_call_id": "tooluse_test_dummy",
"content": "{}",
},
]
result = config.transform_request(
model="anthropic.claude-3-5-sonnet-20240620-v1:0",
messages=messages,
optional_params={},
litellm_params={},
headers={},
)
assert "toolConfig" in result
assert "tools" in result["toolConfig"]
assert result["toolConfig"]["tools"][0]["toolSpec"]["name"] == "dummy_tool"