diff --git a/integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py b/integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py index b65292398f..22af56e121 100644 --- a/integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py +++ b/integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py @@ -508,6 +508,13 @@ def _resolve_flattened_generation_kwargs(generation_kwargs: dict[str, Any]) -> d thinking["budget_tokens"] = thinking_budget_tokens thinking.setdefault("type", "enabled") + adaptive_thinking_effort = generation_kwargs.pop("adaptive_thinking_effort", None) + if adaptive_thinking_effort is not None: + thinking = generation_kwargs.setdefault("thinking", {}) + thinking.setdefault("type", "adaptive") + output_config = generation_kwargs.setdefault("output_config", {}) + output_config["effort"] = adaptive_thinking_effort + return generation_kwargs @component.output_types(replies=list[ChatMessage]) diff --git a/integrations/amazon_bedrock/tests/test_chat_generator.py b/integrations/amazon_bedrock/tests/test_chat_generator.py index 09157b49f7..1206985a91 100644 --- a/integrations/amazon_bedrock/tests/test_chat_generator.py +++ b/integrations/amazon_bedrock/tests/test_chat_generator.py @@ -628,9 +628,19 @@ def tool_fn(city: str) -> str: "thinking_budget_tokens": None, "parallel_tool_use": None, "tool_choice_type": None, + "adaptive_thinking_effort": None, }, {}, ), + ( + { + "adaptive_thinking_effort": "max", + }, + { + "thinking": {"type": "adaptive"}, + "output_config": {"effort": "max"}, + }, + ), ], ) def test_prepare_request_params_with_flattened_generation_kwargs( diff --git a/integrations/anthropic/src/haystack_integrations/components/generators/anthropic/chat/chat_generator.py b/integrations/anthropic/src/haystack_integrations/components/generators/anthropic/chat/chat_generator.py index c37241d7fe..cc9bd44a49 100644 --- a/integrations/anthropic/src/haystack_integrations/components/generators/anthropic/chat/chat_generator.py +++ b/integrations/anthropic/src/haystack_integrations/components/generators/anthropic/chat/chat_generator.py @@ -321,6 +321,13 @@ def _resolve_flattened_generation_kwargs(self, generation_kwargs: dict[str, Any] thinking["budget_tokens"] = thinking_budget_tokens thinking.setdefault("type", "enabled") + adaptive_thinking_effort = generation_kwargs.pop("adaptive_thinking_effort", None) + if adaptive_thinking_effort is not None: + thinking = generation_kwargs.setdefault("thinking", {}) + thinking.setdefault("type", "adaptive") + output_config = generation_kwargs.setdefault("output_config", {}) + output_config["effort"] = adaptive_thinking_effort + return generation_kwargs def _process_response( diff --git a/integrations/anthropic/tests/test_chat_generator.py b/integrations/anthropic/tests/test_chat_generator.py index efed8ff500..6a5f03b3a3 100644 --- a/integrations/anthropic/tests/test_chat_generator.py +++ b/integrations/anthropic/tests/test_chat_generator.py @@ -394,9 +394,19 @@ def test_run_with_output_config(self, chat_messages, mock_anthropic_completion): "thinking_budget_tokens": None, "parallel_tool_use": None, "tool_choice_type": None, + "adaptive_thinking_effort": None, }, {}, ), + ( + { + "adaptive_thinking_effort": "max", + }, + { + "thinking": {"type": "adaptive"}, + "output_config": {"effort": "max"}, + }, + ), ], ) def test_run_with_flattened_generation_kwargs( @@ -415,6 +425,7 @@ def test_run_with_flattened_generation_kwargs( actual_kwargs = mock_anthropic_completion.call_args.kwargs assert actual_kwargs.get("tool_choice") == expected_kwargs.get("tool_choice") assert actual_kwargs.get("thinking") == expected_kwargs.get("thinking") + assert actual_kwargs.get("output_config") == expected_kwargs.get("output_config") def test_check_duplicate_tool_names(self, tools): """Test that the AnthropicChatGenerator component fails to initialize with duplicate tool names."""