fix(bedrock): ask for encrypted reasoning whenever the Responses bridge sends store=false

An explicit store=false skipped the include of reasoning.encrypted_content that the
default path and extra_body.store=false both add, so later chat turns lost Bedrock's
reasoning. The bridge now reads the store the request ends up sending (extra_body wins,
as the bridge applies it) and keeps the request as-is only when that is true.
This commit is contained in:
mateo-berri 2026-11-06 16:49:57 -08:00
parent 36133923a3
commit e4fe5d6f20
2 changed files with 27 additions and 4 deletions

View file

@ -1554,10 +1554,10 @@ def _bedrock_serves_responses(model: str) -> bool:
def bedrock_responses_bridge_optional_params(optional_params: Mapping[str, object]) -> Mapping[str, object]:
if optional_params.get("store") is not None:
return optional_params
extra_body: Final = optional_params.get("extra_body")
extra_body_params: Final = _EXTRA_BODY_ADAPTER.validate_python(extra_body) if isinstance(extra_body, dict) else {}
if extra_body_params.get("store", optional_params.get("store")) is True:
return optional_params
include: Final = extra_body_params.get("include", optional_params.get("include"))
requested: Final = _INCLUDE_ADAPTER.validate_python(include or ())
return {

View file

@ -1253,15 +1253,16 @@ async def test_a_provider_specific_param_keeps_converse_and_reaches_the_model(lo
assert json.loads(requests[0].content)["additionalModelRequestFields"]["foo_bar"] == 1
async def test_tools_with_reasoning_bridge_stores_only_when_the_caller_asks(local_cost_map, fake_aws_env):
@pytest.mark.parametrize("store_param", [{"store": True}, {"extra_body": {"store": True}}])
async def test_tools_with_reasoning_bridge_stores_only_when_the_caller_asks(local_cost_map, fake_aws_env, store_param):
requests, client = _async_recording_client(json={**RESPONSES_TOOL_CALL_JSON, "model": "global.openai.gpt-6-sol"})
await litellm.acompletion(
model="bedrock/global.openai.gpt-6-sol",
messages=[{"role": "user", "content": "weather in Paris"}],
tools=[GET_WEATHER_TOOL],
reasoning_effort="low",
store=True,
client=client,
**store_param,
)
body = json.loads(requests[0].content)
@ -1269,6 +1270,28 @@ async def test_tools_with_reasoning_bridge_stores_only_when_the_caller_asks(loca
assert "include" not in body
@pytest.mark.parametrize(
"store_param",
[{}, {"store": False}, {"extra_body": {"store": False}}, {"store": True, "extra_body": {"store": False}}],
)
async def test_tools_with_reasoning_bridge_asks_for_encrypted_reasoning_whenever_store_is_off(
local_cost_map, fake_aws_env, store_param
):
requests, client = _async_recording_client(json={**RESPONSES_TOOL_CALL_JSON, "model": "global.openai.gpt-6-sol"})
await litellm.acompletion(
model="bedrock/global.openai.gpt-6-sol",
messages=[{"role": "user", "content": "weather in Paris"}],
tools=[GET_WEATHER_TOOL],
reasoning_effort="low",
client=client,
**store_param,
)
body = json.loads(requests[0].content)
assert body["store"] is False
assert body["include"] == ["reasoning.encrypted_content"]
@pytest.mark.parametrize(
"include_param",
[