π OpenHands: AI-Driven Development
Fix issue #9655: [Bug]: CodeActAgent is incompatible with xAI Grok-4 due to hardcoded stop parameter (#9666)
OpenHands8937b3fbfc83
diff --git a/openhands/llm/llm.py b/openhands/llm/llm.pyindex 4463241dcc..13786739d8 100644--- a/openhands/llm/llm.py+++ b/openhands/llm/llm.py@@ -104,6 +104,7 @@ MODELS_WITHOUT_STOP_WORDS = ['o1-preview','o1','o1-2024-12-17',+ 'xai/grok-4-0709',]diff --git a/tests/unit/test_llm.py b/tests/unit/test_llm.pyindex 8b5e106ce3..c5a1c7f48a 100644--- a/tests/unit/test_llm.py+++ b/tests/unit/test_llm.py@@ -264,6 +264,45 @@ def test_llm_init_with_openrouter_model(mock_get_model_info, default_config):mock_get_model_info.assert_called_once_with('openrouter:gpt-4o-mini')+@patch('openhands.llm.llm.litellm_completion')+def test_stop_parameter_handling(mock_litellm_completion, default_config):+ """Test that stop parameter is only added for supported models."""+ from litellm.types.utils import ModelResponse++ mock_response = ModelResponse(+ id='test-id',+ choices=[{'message': {'content': 'Test response'}}],+ model='test-model',+ )+ mock_litellm_completion.return_value = mock_response++ # Test with a model that supports stop parameter+ default_config.model = (+ 'custom-model' # Use a model not in FUNCTION_CALLING_SUPPORTED_MODELS+ )+ llm = LLM(default_config)+ llm.completion(+ messages=[{'role': 'user', 'content': 'Hello!'}],+ tools=[+ {'type': 'function', 'function': {'name': 'test', 'description': 'test'}}+ ],+ )+ # Verify stop parameter was included+ assert 'stop' in mock_litellm_completion.call_args[1]++ # Test with Grok-4 model that doesn't support stop parameter+ default_config.model = 'xai/grok-4-0709'+ llm = LLM(default_config)+ llm.completion(+ messages=[{'role': 'user', 'content': 'Hello!'}],+ tools=[+ {'type': 'function', 'function': {'name': 'test', 'description': 'test'}}+ ],+ )+ # Verify stop parameter was not included+ assert 'stop' not in mock_litellm_completion.call_args[1]++# Tests involving completion and retries