Conversation
Previously _get_backend() picked one backend based on API key presence and tools returned tool_error if that single backend threw at runtime. Now all configured backends are tried in priority order until one succeeds — only then is an error returned to the agent. - Add _get_backend_candidates() returning prioritized list - Add _try_backend_with_fallback() sync dispatch helper - Add _try_backend_with_fallback_async() async dispatch helper - Extract _tavily_search(), _firecrawl_search(), _tavily_extract(), _firecrawl_extract(), _tavily_crawl(), _firecrawl_crawl() helpers - Wire fallback into web_search_tool, web_extract_tool, web_crawl_tool - Keep _get_backend() as backward-compat wrapper for tests/display - Preserve check_web_api_key() semantics (configured-only checking) - Add 15 tests across 4 tiers (callable, HTTP, SDK, async) - Update 2 existing tests to use new _get_backend_candidates mock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This fix was created by DeepSeek V4 Pro and revised by GPT-5.5. I (@mbac) do not have the necessary programming skills to thoroughly verify this bugfix, so I kindly ask reviewers to be extra careful when examining the PR.
Web tools could previously select one configured backend for a request and return an error if that backend hit a runtime failure, even when another configured provider could satisfy the same operation. This made transient failures such as rate limits, timeouts, network errors, and 5xx responses unnecessarily visible to the agent.
The change adds runtime fallback for web backend dispatch. Search, extract, and crawl now build a prioritized candidate list, try the configured provider first when it is available, and move to the next usable provider when the current backend raises a runtime error. Backend-specific helpers keep response normalization in one place, and Firecrawl extraction now lets backend scrape failures reach the fallback dispatcher while still preserving policy-blocked URL rows so blocked URLs are not fetched through another provider.
Related Issue
N/A
Related work: #11331 covers a similar runtime failover idea for search and extract. This PR applies the fallback structure to the current backend-candidate implementation, includes crawl dispatch, and includes a Firecrawl extraction regression fix.
Type of Change
Changes Made
How to Test
web_searchorweb_extractreturns results from the next configured backend instead of immediately returning the first backend error.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qsuite and all tests passDocumentation & Housekeeping
docs/, docstrings) - N/Acli-config.yaml.exampleif I added/changed config keys - N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows - N/AScreenshots / Logs
Focused verification passed locally: