π OpenHands: AI-Driven Development
fix: _configure_llm now preserves user LLM settings (#14451)
shanemort1982ff9ab1097929
diff --git a/openhands/app_server/app_conversation/live_status_app_conversation_service.py b/openhands/app_server/app_conversation/live_status_app_conversation_service.pyindex f9907df6fd..5b4ae92465 100644--- a/openhands/app_server/app_conversation/live_status_app_conversation_service.py+++ b/openhands/app_server/app_conversation/live_status_app_conversation_service.py@@ -1191,6 +1191,12 @@ class LiveStatusAppConversationService(AppConversationServiceBase):def _configure_llm(self, user: UserInfo, llm_model: str | None) -> LLM:"""Configure LLM settings.+ Starts from the user's saved LLM configuration and overrides only+ the fields that the server needs to resolve (model name, base URL,+ and usage ID). All other user-configured fields (e.g.+ ``reasoning_effort``, ``extended_thinking_budget``, ``drop_params``)+ are preserved so that they reach the agent-server unchanged.+Args:user: User information containing LLM preferencesllm_model: Optional specific model to use, falls back to user default@@ -1210,11 +1216,13 @@ class LiveStatusAppConversationService(AppConversationServiceBase):provider_base_url=self.openhands_provider_base_url,)- return LLM(- model=model,- base_url=base_url,- api_key=user.agent_settings.llm.api_key,- usage_id='agent',+ return user.agent_settings.llm.model_copy(+ update={+ 'model': model,+ 'base_url': base_url,+ 'api_key': user.agent_settings.llm.api_key,+ 'usage_id': 'agent',+ })async def _add_system_mcp_servers(diff --git a/tests/unit/app_server/test_live_status_app_conversation_service.py b/tests/unit/app_server/test_live_status_app_conversation_service.pyindex 46d8918172..a004b216f2 100644--- a/tests/unit/app_server/test_live_status_app_conversation_service.py+++ b/tests/unit/app_server/test_live_status_app_conversation_service.py@@ -636,6 +636,41 @@ class TestLiveStatusAppConversationService:assert llm.model == 'sdk-model'assert llm.base_url == 'https://sdk-llm.example.com'+ @pytest.mark.asyncio+ async def test_configure_llm_preserves_reasoning_effort(self):+ """User-configured reasoning_effort must survive _configure_llm.++ Previously _configure_llm created a bare LLM() which reset every+ field to its Pydantic default (reasoning_effort='high'). Users who+ set reasoning_effort=None (to disable thinking parameters for models+ whose litellm version cannot handle them) had their override silently+ discarded.+ """+ from pydantic import SecretStr as _SecretStr++ user_llm = LLM(+ model='anthropic/claude-opus-4-7',+ api_key=_SecretStr('test-key'),+ reasoning_effort=None,+ extended_thinking_budget=None,+ )+ agent_settings = self.mock_user.agent_settings.model_copy(+ update={'llm': user_llm}+ )+ self.mock_user.agent_settings = agent_settings+ self.mock_user_context.get_mcp_api_key.return_value = None++ llm, _ = await self.service._configure_llm_and_mcp(+ self.mock_user, None, self.conversation_id+ )++ assert llm.model == 'anthropic/claude-opus-4-7'+ assert llm.reasoning_effort is None, (+ '_configure_llm must preserve reasoning_effort=None '+ 'instead of resetting it to the SDK default'+ )+ assert llm.extended_thinking_budget is None+@pytest.mark.asyncioasync def test_configure_llm_and_mcp_openhands_model_uses_user_base_url(self,