Conversation
WebSearchTool picks its backend from the environment. Adds a Serply branch between Brave Search and the DuckDuckGo fallback, so it runs only when SERPLY_API_KEY is set and nothing higher in the chain is configured. Existing SearXNG and Brave users see no change. search_serply mirrors search_brave: same client, same error strings, same numbered output shape. Serply returns results[] with title, link and description, and caps a page at 10, which matches the tool's own num_results clamp. Tests cover the formatter against a trimmed real response body, the max cutoff, and the empty and missing array cases. No network.
Owner
|
this looks good, will follow up this weekend ! |
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
Adds Serply as a fourth backend for
WebSearchTool, between Brave Search and the DuckDuckGo fallback.crates/tools/src/web_search.rselse ifinexecute(), gated on a non-emptySERPLY_API_KEYsearch_serply+format_serply_results, mirroringsearch_brave/format_brave_resultsline for line#[cfg(test)] mod testswith three network-free formatter testsdocs/tools.mdneithertononefix now that the list has three configurable entriesNo new dependencies, no schema change, no change to any existing code path.
Why
The backend chain today is SearXNG, Brave, DuckDuckGo. SearXNG needs a self-hosted instance, Brave needs a paid key, and DuckDuckGo's Instant Answer endpoint is not a web search: it returns an abstract and related topics, so a query with no instant answer comes back empty. That leaves no keyed option for someone who does not want to run a SearXNG instance and does not have Brave.
Serply returns ranked web results from a single GET with an
X-Api-Keyheader, so it drops into the existing shape without new plumbing. Response body isresults[]withtitle,link,description, which maps onto the same three fields the Brave and SearXNG formatters already read.Placement is deliberate: after Brave so nobody's current configuration changes behaviour, before DuckDuckGo so a configured key beats the no-results fallback.
Notes
num_resultsis already clamped to1..=10at the top ofexecute(), so the two ceilings agree and no extra guard was needed. The comment insearch_serplyrecords this.search_braverather than runningcargo fmt. The workspace is not currently rustfmt-clean (cargo fmt --all -- --checkreports ~2900 hunks onmain), and formatting only my additions would have made them read differently from the identical Brave code three functions above. Happy to run the formatter over the file if you would rather.spec/13_rust_codebase.mddocumentsWebSearchToolas Brave plus DuckDuckGo only and does not mention SearXNG, so it predates the current chain. I left it alone rather than adding a fourth entry to a list that is already two behind. Glad to bring that section up to date in this PR or a separate one if it is useful.Testing
Backend registration and the whole
claurst-toolssuite:The test fixture is a trimmed copy of a real response. Confirming the field names the formatter reads, against the live endpoint the code calls:
The tests are network-free; the curl above is just evidence that the fixture reflects the real body.
Serply stays entirely optional. With
SERPLY_API_KEYunset the chain is exactly what it is today.Disclosure: I work with Serply. Happy to adjust scope, naming, or drop this entirely if it isn't a direction you want for the project.