diff --git a/agent/error_classifier.py b/agent/error_classifier.py index 3489c66c949b1..27311609de669 100644 --- a/agent/error_classifier.py +++ b/agent/error_classifier.py @@ -279,6 +279,15 @@ def is_auth(self) -> bool: "no such model", "unknown model", "unsupported model", + # OpenRouter returns 404 with this message when none of the candidate + # endpoints for the selected model support tool/function calling. + # Classifying this as model_not_found triggers fallback to a different + # model or provider that does support tools. Without this entry the + # pattern falls through to ``unknown`` with ``retryable=True``, the + # retry loop burns all attempts on the same deterministic rejection, + # and the error surfaces as a confusing "model not found" message + # instead of automatically failing over. See PR #58446. + "no endpoints found that support tool use", ] # Request-validation patterns — the request is malformed and will fail diff --git a/tests/agent/test_error_classifier.py b/tests/agent/test_error_classifier.py index 6c533089986ce..7c266a5ad633a 100644 --- a/tests/agent/test_error_classifier.py +++ b/tests/agent/test_error_classifier.py @@ -516,6 +516,21 @@ def test_404_model_not_found(self): assert result.should_fallback is True assert result.retryable is False + def test_404_openrouter_tool_use_not_supported(self): + # OpenRouter returns 404 with this message when none of the + # candidate endpoints for the selected model support tool/function + # calling. Classify as model_not_found so the agent fast-fallbacks + # to a model/provider that does support tools. + e = MockAPIError( + "No endpoints found that support tool use. " + "Try disabling \"browser_back\".", + status_code=404, + ) + result = classify_api_error(e) + assert result.reason == FailoverReason.model_not_found + assert result.should_fallback is True + assert result.retryable is False + def test_404_generic(self): # Generic 404 with no "model not found" signal — common for local # llama.cpp/Ollama/vLLM endpoints with slightly wrong paths. Treat