@@ -405,17 +405,25 @@ def function_declaration_to_tool_param(
405405def _build_thinking_param (
406406 thinking_config : Optional [types .ThinkingConfig ],
407407 max_tokens : int ,
408- ) -> Union [anthropic_types .ThinkingConfigEnabledParam , NotGiven ]:
409- """Converts ADK ThinkingConfig to Anthropic ThinkingConfigEnabledParam.
408+ ) -> Union [
409+ anthropic_types .ThinkingConfigEnabledParam ,
410+ anthropic_types .ThinkingConfigDisabledParam ,
411+ NotGiven ,
412+ ]:
413+ """Converts ADK ThinkingConfig to an Anthropic thinking parameter.
410414
411- Returns NOT_GIVEN if thinking is not configured or budget is 0.
412- Clamps budget_tokens to max_tokens - 1 to satisfy the API constraint.
415+ Returns NOT_GIVEN if no thinking config is provided.
416+ Explicitly disables thinking when budget is 0 (some models enable it by
417+ default). Clamps budget_tokens to max_tokens - 1 to satisfy the API
418+ constraint.
413419 """
414420 if thinking_config is None :
415421 return NOT_GIVEN
416422 budget = thinking_config .thinking_budget
417- if not budget :
423+ if budget is None :
418424 return NOT_GIVEN
425+ if budget == 0 :
426+ return anthropic_types .ThinkingConfigDisabledParam (type = "disabled" )
419427 return anthropic_types .ThinkingConfigEnabledParam (
420428 type = "enabled" ,
421429 budget_tokens = min (budget , max_tokens - 1 ),
@@ -503,7 +511,9 @@ async def _generate_content_streaming(
503511 tools : Union [Iterable [anthropic_types .ToolUnionParam ], NotGiven ],
504512 tool_choice : Union [anthropic_types .ToolChoiceParam , NotGiven ],
505513 thinking : Union [
506- anthropic_types .ThinkingConfigEnabledParam , NotGiven
514+ anthropic_types .ThinkingConfigEnabledParam ,
515+ anthropic_types .ThinkingConfigDisabledParam ,
516+ NotGiven ,
507517 ] = NOT_GIVEN ,
508518 ) -> AsyncGenerator [LlmResponse , None ]:
509519 """Handles streaming responses from Anthropic models.
0 commit comments