Repository navigation
feat(tool): add Tavily as a selectable web_search provider (#327) - #329
Conversation
3952199 to
0b6b9e3
Compare
…ect#327) Add Tavily as the third backend for the gateway-owned web_search tool (Phase 3 of vllm-project#291). Each query is one typed POST /search with a bearer token; domain filters are forwarded natively and re-checked client-side, count is clamped to 20, freshness maps to time_range or a date range widened by one day on each side because Tavily's bounds are exclusive, language keeps Tavily's documented compound tags and otherwise reduces to the primary subtag, and 401/403/429/432/433 fail the web_search_call without retry or credential leakage. Move the shared response helpers into provider.rs to keep mod.rs within the file-size policy, and make WebSearchProviderKind::ALL a static slice so new providers do not change its type. Signed-off-by: Zheng Lu <[email protected]>
0b6b9e3 to
de362fe
Compare
haoshan98
left a comment
There was a problem hiding this comment.
Thanks for adding support for Tavily web search. Non-blocking suggestion: could we include the filter_by_published_date parameter and set it to true whenever freshness is configured? This would ensure that results without a detectable publication date do not bypass the requested recency filter.
Send filter_by_published_date alongside the date window whenever freshness is set, so Tavily drops results published outside the window and results with no detectable publication date instead of letting them bypass the requested recency filter. Without freshness no date window is sent and the flag stays off. Signed-off-by: Zheng Lu <[email protected]>
Worth mention that the trade-off the Tavily docs call out: setting Added three test assertions: time_range search sends the flag, an explicit date range sends it with the widened bounds, and a search without freshness omits it. |
## Summary Adds Serply as a fourth selectable `web_search` provider beside You.com, Brave Search and Tavily, following the shape of the Tavily provider (#329). Closes #381. - `WebSearchProviderKind::Serply` (`serply`), key from `SERPLY_API_KEY`, base URL `https://api.serply.io`, no provider-imposed concurrency ceiling (per-request metering, like Tavily). - `tool/web_search/serply.rs` calls `GET /v1/search` with the `X-Api-Key` header and maps the model's arguments onto Google parameters: `count` to `num` (clamped to 10), `country` to `gl`, `language` to `hl`, `safesearch: strict` to `safe=active`, and `freshness` day/week/month/year to `tbs=qdr:*`. - Domain allowlists and blocklists (tool filters first, then arguments, same precedence as the other providers) are sent as `site:a OR site:b` / `-site:x` query operators, and explicit date ranges as `after:` / `before:`, so the 10-result page is spent on matching hosts. The shared `DomainFilter` still re-checks every result on the way back. - Google redirect links (`https://www.google.com/url?q=<real>`) that appear with time filters are unwrapped before filtering, so sources point at the real page. - 401/403 names `SERPLY_API_KEY` without echoing the key; 429 is surfaced with `Retry-After` and never retried; other statuses include the upstream body. - Docs: README provider section and tables, CHANGELOG, ARCHITECTURE, deploying guide and Kubernetes notes. - `.rust-file-sizes.json`: `config.rs` goes from 637 to 642. The five lines are the exhaustive `match` arms for the new variant, so I raised the reviewed exception rather than splitting the enum out; happy to split instead if you prefer. ## Test Plan - `cargo fmt -- --check`, `cargo clippy --all-targets -- -D warnings`, `cargo test` (93 suites, 0 failed), and `pre-commit run --from-ref upstream/main --to-ref HEAD` all pass. - 12 unit tests in `serply.rs` cover parameter mapping, filter precedence, operator building, date-range handling, redirect unwrapping and null/missing response fields. - `tests/web_search_serply_test.rs` runs the handler against a local Axum mock: exact query parameters and output JSON, public `sources`, `site:` / `-site:` plus `after:` / `before:` with client-side filtering, rejected credentials without leaking the key, 429 without retry, and 422 with its body. - `web_search_config_selects_serply_from_environment` plus the provider-switch loop in `agentic-server`. - Live run against `api.serply.io` through `WebSearchHandler` (temporary test, not committed): a plain query, a two-query batch restricted to `docs.rs` / `github.com`, `freshness: week` + `language: en` (redirects unwrapped, `page_age` filled), a `2026-01-01to2026-03-01` range (`latency: 1.25`), and a bad key returning the `SERPLY_API_KEY` message. Note: #417 also touches `tool/web_search/`. I'm glad to rebase onto it if it lands first. 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. --------- Signed-off-by: serply <[email protected]> Co-authored-by: Hao Shan <[email protected]> Co-authored-by: Maral <[email protected]>
## Summary Adds [Keenable](https://keenable.ai), an independent web index built for agents, as a selectable `web_search` provider beside You.com, Brave Search, Tavily, SearXNG and Serply. It follows the shape of the Tavily and Serply providers (#329, #420). - `WebSearchProviderKind::Keenable` (`keenable`): - Key from `KEENABLE_API_KEY`. - Base URL `https://api.keenable.ai`. - No provider-imposed concurrency ceiling (per-request metering), so it inherits `max_concurrent_gateway_calls`. - **Works without an API key.** `tool/web_search/keenable.rs`: - With no key (or a blank one), it calls Keenable's public `POST /v1/search/public` with an `X-Keenable-Title: vLLM Agentic API` header. `AGENTIC_WEB_SEARCH_PROVIDER=keenable` alone is a working configuration. - With `KEENABLE_API_KEY` it calls `POST /v1/search` with the key in `X-API-Key`, and `Debug` stays redacted through the shared `ApiKey`. - Request body is `{query, max_results}`; `count` (or `search_context_size`) is clamped to 20. - Keenable has no server-side domain, freshness, locale or safe-search parameters: - Tool and argument domain filters keep the usual precedence and conflict check, and the shared `DomainFilter` applies them on the response. - The rest are logged as ignored at debug level, like the other providers do. - Response mapping: - The description is `snippet`, falling back to `description` (often empty upstream). `page_age` comes from `published_at`. - Blank URLs are dropped, and a `null` `results` is treated as empty. Everything lands in `web`, so `news` stays empty. - Errors: 401/403 name `KEENABLE_API_KEY` without echoing anything secret. 429 is surfaced with `Retry-After` and never retried. Other statuses include the upstream body. - Docs: README provider section and tables, CHANGELOG, ARCHITECTURE, and the deploying guide. ## Test Plan - 5 unit tests in `keenable.rs` cover: - Redacted `Debug` and default/override base URL. - Public vs keyed endpoint and headers. - Body shape and clamping, with ignored arguments not sent. - Client-side config domain filters. - Response mapping, including the snippet→description fallback, `published_at`, blank URLs and `null` results. - `config.rs` kind assertions and the unknown-provider message now include `keenable`. - `web_search_config_selects_keenable_with_or_without_a_key`, plus a `serply → keenable` case in the provider-switch loop. - `cargo fmt --all -- --check` passes. `scripts/check_rust_file_sizes.py` passes (341 files): all touched production files stay within their limits, so no exception changes were needed. - I couldn't run `cargo test` / `clippy` in my sandbox because `openssl-sys` has no system OpenSSL/pkg-config here. Please let CI run them, and I'll fix anything it flags. - The request and response shape (both endpoints, `max_results`, the `snippet`/`description` fields) is the same one I verified live against `api.keenable.ai` in other integrations today. Disclosure: I work with the Keenable team. Happy to adjust scope, naming, or the key-free default, or to drop this if it isn't a direction you want for the project. Signed-off-by: KGKallasmaa <[email protected]> Co-authored-by: KGKallasmaa <[email protected]>
Closes #327 (Part of #291).
Summary
Adds Tavily as the third backend for the gateway-owned
web_searchtool (Phase 3 of #291, closes #327), following the typed provider contract from #293/#294 and the Brave pattern from #324.WebSearchProviderKind::Tavily(config.rs):config_name = "tavily",TAVILY_API_KEY, default endpointhttps://api.tavily.com, no provider-specific concurrency ceiling (Tavily plans are metered per minute, so it inherits the gateway limit).ALL,FromStr, and the "expected one of" message list all three providers. No public signature changes: the enum andWebSearchProviderConfigare#[non_exhaustive], andWebSearchHandler::from_configgains a match arm.WebSearchProviderKind::ALLis now a&'static [Self]slice so adding a provider no longer changes its type.tool/web_search/tavily.rs(new, 391 production lines):TavilySearchProviderposts a typedTavilySearchBodytoPOST {base_url}/searchwithContent-Type: application/json,Accept: application/json, andAuthorization: Bearer <key>. The key is never placed in the body andAccept-Encodingis never sent (corereqwesthas no gzip). Request shaping:count/search_context_size→max_results, clamped to 20 with a debug log;freshnessday/week/month/year →time_range;YYYY-MM-DDtoYYYY-MM-DD→start_date/end_datewidened by one day on each side (checkedpred_opt/succ_opt), because the gateway's range is inclusive while Tavily documents its bounds as "after" / "before";allowed_domains/blocked_domains(request config wins) or the model'sinclude_domains/exclude_domains→ nativeinclude_domains/exclude_domains, and re-applied client-side throughDomainFilteras defense in depth; the shared include+exclude/boost conflict rule is preserved;languagekeeps Tavily's documented compound tags lowercased (zh-CN→zh-cn) and otherwise reduces to the primary subtag (en-GB→en);safesearch→ booleansafe_search(off→ omitted);include_published_date: truesopage_ageis populated for thegeneraltopic;country(Tavily wants full country names, not ISO codes) and the You.com-specificlivecrawl*,crawl_timeout,boost_domainsare dropped with one debug log.topic: "general"request per query: every hit lands inresults.web,results.newsstays empty. A secondnewsrequest per query would double credit spend; this is documented.#[serde(default)]structs readresults[] { title, url, content, published_date }plusresponse_timeandrequest_id;content→description,published_date→page_age.metadata[]carries"provider": "tavily",request_idassearch_uuid, andresponse_timeaslatency(existingskip_serializing_ifrules, You.com output unchanged).TAVILY_API_KEYwithout reading the body; 429 is not retried and surfacesRetry-Afterverbatim (or says none was provided); Tavily's non-standard 432/433 plan-limit statuses are reported without retry; anything else reports status + size-bounded body.mod.rssize: adding the module pushedmod.rsto 507 production lines, so the sharednull_as_defaultandread_response_limitedhelpers moved toprovider.rs(where the provider contract lives). Both were and remain crate-private, so no public API changed.mod.rsis now 476 lines; no other file changed behavior.web_search_config.rs/config_file.rsare provider-generic already; only doc comments and tests changed.README.md(feature bullet, quick start,config.tomlcomments, provider table, Tavily section),docs/deploying/README.md,docs/deploying/kubernetes.md,ARCHITECTURE.md,CHANGELOG.md.No new dependencies; the request body is serialized with the existing
serde_jsonrather than enablingreqwest'sjsonfeature.Deliberately kept in parity with
brave.rs/you.rsrather than changed here (candidates for a cross-provider follow-up): generic non-2xx failures echo the size-bounded upstream body (401/403/429/432/433 never do),Retry-Afteris whitespace-trimmed, and the caller-suppliedreqwest::Clientcontract is gateway-wide.Test Plan
cargo fmt -- --checkcargo clippy --all-targets -- -D warningscargo test— 1606 passed, 0 failed (You.com and Brave suites untouched and green)pre-commit run --all-files— all hooks pass, including the Rust production file-size policy (mod.rs476,tavily.rs391,provider.rs144)crates/agentic-server-core/tests/web_search_tavily_test.rs(12 tests, Axum mock on127.0.0.1:0, nothing reaches the network):max_results,time_range,language,safe_search,exclude_domains, nocountry/livecrawl/api_key),Bearerauth,Content-Type, noAccept-Encoding, byte-exact model-facing output with"provider":"tavily"+search_uuid+latency,web_search_callpublic sourcesstart_date/end_datewidened by one day each side, nomax_resultswhen count unsetresults→{"web":[],"news":[]}with no invented sourcesexclude_domainsforwarded and enforcedTAVILY_API_KEY, never echoes the key or the upstream bodyRetry-Afterinteger and HTTP-date surfaced verbatim, absence reported, exactly one request (no retry)max_concurrent_queries = 1serializestavily.rs(13 tests) cover the private request/response types: payload rendering and omission of unset fields, clamping, freshness mapping including month/year boundary widening, language (zh-CN→zh-cn,zh-TW→zh,en-GB→en) and safe-search reduction, ignored arguments, config-over-args precedence, conflict rejection, envelope tolerance ({}, nulls, unknown keys), metadata serialization, defense-in-depth filteringconfig.rs,web_search_config.rs,config_file.rstests extended for the third provider (labels, parsing, env/file resolution,api_key_envoverride, provider switching without pinned credentials, TOML round trip)