Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions agent/error_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/agent/test_error_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down