From eb2f432e16fb576419bbfe171c0909024de873bb Mon Sep 17 00:00:00 2001 From: Tyler Zhang Date: Sat, 6 Dec 2025 18:41:10 +0800 Subject: [PATCH 1/2] Fix GPT-5 models to respect reasoning_effort config setting Previously, GPT-5 models had reasoning_effort hardcoded to 'minimal', which caused two issues: 1. 'minimal' is not supported by some models (e.g., gpt-5.1-codex) 2. User's config.reasoning_effort setting was completely ignored This fix: - Reads and respects user's reasoning_effort config value - Uses valid defaults: 'none' for non-thinking models, 'low' for thinking - Adds logging to show which value is being used Fixes #2120 --- .../algo/ai_handlers/litellm_ai_handler.py | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/pr_agent/algo/ai_handlers/litellm_ai_handler.py b/pr_agent/algo/ai_handlers/litellm_ai_handler.py index dd04591e..82f7c9f1 100644 --- a/pr_agent/algo/ai_handlers/litellm_ai_handler.py +++ b/pr_agent/algo/ai_handlers/litellm_ai_handler.py @@ -292,16 +292,25 @@ class LiteLLMAIHandler(BaseAiHandler): thinking_kwargs_gpt5 = None if model.startswith('gpt-5'): + # Respect user's reasoning_effort config setting + # Supported values: 'none', 'low', 'medium', 'high' + # Note: gpt-5.1 supports 'none', but gpt-5.1-codex does not + config_effort = get_settings().config.reasoning_effort + supported_efforts = ['none', 'low', 'medium', 'high'] + if model.endswith('_thinking'): - thinking_kwargs_gpt5 = { - "reasoning_effort": 'low', - "allowed_openai_params": ["reasoning_effort"], - } + # For thinking models, use config value or default to 'low' + effort = config_effort if config_effort in supported_efforts else 'low' else: - thinking_kwargs_gpt5 = { - "reasoning_effort": 'minimal', - "allowed_openai_params": ["reasoning_effort"], - } + # For non-thinking models, use config value or default to 'none' + # If 'none' fails for specific models (e.g., codex), they should set config to 'low' + effort = config_effort if config_effort in supported_efforts else 'none' + + thinking_kwargs_gpt5 = { + "reasoning_effort": effort, + "allowed_openai_params": ["reasoning_effort"], + } + get_logger().info(f"Using reasoning_effort={effort} for GPT-5 model (from {'config' if config_effort in supported_efforts else 'default'})") model = 'openai/'+model.replace('_thinking', '') # remove _thinking suffix From 956f3660f294cdf74bff4c01d1a81cb6b11cfa4d Mon Sep 17 00:00:00 2001 From: Tyler Zhang Date: Mon, 8 Dec 2025 09:37:55 +0800 Subject: [PATCH 2/2] Refactor reasoning_effort logic for better readability - Store validation result in variable to avoid redundant checks - Add warning log when invalid reasoning_effort value is configured - Improve source tracking in info log - Makes code more maintainable and easier to debug --- .../algo/ai_handlers/litellm_ai_handler.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pr_agent/algo/ai_handlers/litellm_ai_handler.py b/pr_agent/algo/ai_handlers/litellm_ai_handler.py index 82f7c9f1..931a9474 100644 --- a/pr_agent/algo/ai_handlers/litellm_ai_handler.py +++ b/pr_agent/algo/ai_handlers/litellm_ai_handler.py @@ -297,20 +297,28 @@ class LiteLLMAIHandler(BaseAiHandler): # Note: gpt-5.1 supports 'none', but gpt-5.1-codex does not config_effort = get_settings().config.reasoning_effort supported_efforts = ['none', 'low', 'medium', 'high'] + is_config_valid = config_effort in supported_efforts + source = "config" - if model.endswith('_thinking'): - # For thinking models, use config value or default to 'low' - effort = config_effort if config_effort in supported_efforts else 'low' + if is_config_valid: + effort = config_effort else: - # For non-thinking models, use config value or default to 'none' - # If 'none' fails for specific models (e.g., codex), they should set config to 'low' - effort = config_effort if config_effort in supported_efforts else 'none' + source = "default" + if config_effort is not None: + get_logger().warning( + f"Invalid reasoning_effort '{config_effort}' in config. " + f"Using default. Supported values: {supported_efforts}" + ) + if model.endswith('_thinking'): + effort = 'low' + else: + effort = 'none' thinking_kwargs_gpt5 = { "reasoning_effort": effort, "allowed_openai_params": ["reasoning_effort"], } - get_logger().info(f"Using reasoning_effort={effort} for GPT-5 model (from {'config' if config_effort in supported_efforts else 'default'})") + get_logger().info(f"Using reasoning_effort='{effort}' for GPT-5 model (from {source})") model = 'openai/'+model.replace('_thinking', '') # remove _thinking suffix