From 237bb61692916956d73d57ae36d61f2020b5b608 Mon Sep 17 00:00:00 2001 From: Mason Daugherty Date: Mon, 22 Jun 2026 23:09:00 -0400 Subject: [PATCH] test(openrouter): cover `cache_control` passthrough on tool defs (#38215) The OpenRouter SDK preserves `cache_control` on tool definitions, and `ChatOpenRouter` forwards full tool dicts unchanged. This adds a regression test confirming a top-level `cache_control` on a tool dict passed to `bind_tools` survives into the SDK request payload. Made by [Open SWE](https://openswe.vercel.app/agents/5059cee2-c2de-1ca4-200d-c3fdb8c5814e) --------- Co-authored-by: open-swe[bot] --- .../tests/unit_tests/test_chat_models.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libs/partners/openrouter/tests/unit_tests/test_chat_models.py b/libs/partners/openrouter/tests/unit_tests/test_chat_models.py index 4d62e042374..aad8e0663a9 100644 --- a/libs/partners/openrouter/tests/unit_tests/test_chat_models.py +++ b/libs/partners/openrouter/tests/unit_tests/test_chat_models.py @@ -824,6 +824,28 @@ class TestRequestPayload: assert tools[0]["function"]["name"] == "GetWeather" assert "parameters" in tools[0]["function"] + def test_tool_cache_control_preserved_in_payload(self) -> None: + """Test that top-level `cache_control` on a tool dict is preserved.""" + model = _make_model() + model.client = MagicMock() + model.client.chat.send.return_value = _make_sdk_response(_TOOL_RESPONSE_DICT) + + tool = { + "type": "function", + "function": { + "name": "GetWeather", + "description": "Get the weather.", + "parameters": {"type": "object", "properties": {}}, + }, + "cache_control": {"type": "ephemeral"}, + } + bound = model.bind_tools([tool]) + bound.invoke("What's the weather?") + call_kwargs = model.client.chat.send.call_args[1] + tools = call_kwargs["tools"] + assert len(tools) == 1 + assert tools[0]["cache_control"] == {"type": "ephemeral"} + def test_openrouter_params_in_payload(self) -> None: """Test that OpenRouter-specific params appear in the SDK call.""" model = _make_model(