@@ -344,26 +344,71 @@ def test_run_with_params(self, chat_messages, mock_anthropic_completion):
344344 assert response ["replies" ][0 ].meta ["model" ] == "claude-sonnet-4-5"
345345 assert response ["replies" ][0 ].meta ["finish_reason" ] == "stop"
346346
347- def test_run_with_flattened_generation_kwargs (self , chat_messages , mock_anthropic_completion ):
347+ @pytest .mark .parametrize (
348+ "generation_kwargs,expected_kwargs" ,
349+ [
350+ (
351+ {
352+ "parallel_tool_use" : False ,
353+ "tool_choice_type" : "any" ,
354+ "thinking_budget_tokens" : 1024 ,
355+ },
356+ {
357+ "tool_choice" : {"disable_parallel_tool_use" : True , "type" : "any" },
358+ "thinking" : {"budget_tokens" : 1024 , "type" : "enabled" },
359+ },
360+ ),
361+ (
362+ {
363+ "parallel_tool_use" : True ,
364+ "tool_choice_type" : "all" ,
365+ },
366+ {
367+ "tool_choice" : {"disable_parallel_tool_use" : False , "type" : "all" },
368+ },
369+ ),
370+ (
371+ {
372+ "parallel_tool_use" : True ,
373+ },
374+ {
375+ "tool_choice" : {"disable_parallel_tool_use" : False , "type" : "auto" },
376+ },
377+ ),
378+ (
379+ {
380+ "disable_parallel_tool_use" : True ,
381+ },
382+ {
383+ "tool_choice" : {"disable_parallel_tool_use" : True , "type" : "auto" },
384+ },
385+ ),
386+ (
387+ {
388+ "thinking_budget_tokens" : None ,
389+ "parallel_tool_use" : None ,
390+ "tool_choice_type" : None ,
391+ },
392+ {},
393+ ),
394+ ],
395+ )
396+ def test_run_with_flattened_generation_kwargs (
397+ self , chat_messages , mock_anthropic_completion , generation_kwargs , expected_kwargs
398+ ):
348399 """
349400 Test that the AnthropicChatGenerator component can run with parameters.
350401 """
351402 component = AnthropicChatGenerator (
352403 api_key = Secret .from_token ("test-api-key" ),
353- generation_kwargs = {
354- "max_tokens" : 10 ,
355- "thinking_budget_tokens" : 1024 ,
356- "parallel_tool_use" : False ,
357- "tool_choice_type" : "any" ,
358- },
404+ generation_kwargs = generation_kwargs ,
359405 )
360406 component .run (chat_messages )
361407
362408 # Check that the component calls the Anthropic API with the correct parameters
363- _ , kwargs = mock_anthropic_completion .call_args
364- assert kwargs ["max_tokens" ] == 10
365- assert kwargs ["thinking" ] == {"budget_tokens" : 1024 , "type" : "enabled" }
366- assert kwargs ["tool_choice" ] == {"disable_parallel_tool_use" : True , "type" : "any" }
409+ actual_kwargs = mock_anthropic_completion .call_args .kwargs
410+ assert actual_kwargs .get ("tool_choice" ) == expected_kwargs .get ("tool_choice" )
411+ assert actual_kwargs .get ("thinking" ) == expected_kwargs .get ("thinking" )
367412
368413 def test_check_duplicate_tool_names (self , tools ):
369414 """Test that the AnthropicChatGenerator component fails to initialize with duplicate tool names."""
0 commit comments