Skip to content

feat(tool): add Tavily as a selectable web_search provider (#327) - #329

Merged
haoshan98 merged 2 commits into
vllm-project:mainfrom
Zheng-Lu:feat/327-tavily-provider
Sep 28, 2026
Merged

haoshan98 merged 2 commits into
vllm-project:mainfrom
Zheng-Lu:feat/327-tavily-provider

Conversation

@Zheng-Lu

@Zheng-Lu Zheng-Lu commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes #327 (Part of #291).

Summary

Adds Tavily as the third backend for the gateway-owned web_search tool (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 endpoint https://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 and WebSearchProviderConfig are #[non_exhaustive], and WebSearchHandler::from_config gains a match arm. WebSearchProviderKind::ALL is now a &'static [Self] slice so adding a provider no longer changes its type.
  • tool/web_search/tavily.rs (new, 391 production lines): TavilySearchProvider posts a typed TavilySearchBody to POST {base_url}/search with Content-Type: application/json, Accept: application/json, and Authorization: Bearer <key>. The key is never placed in the body and Accept-Encoding is never sent (core reqwest has no gzip). Request shaping:
    • count / search_context_size → max_results, clamped to 20 with a debug log;
    • freshness day/week/month/year → time_range; YYYY-MM-DDtoYYYY-MM-DD → start_date / end_date widened by one day on each side (checked pred_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's include_domains / exclude_domains → native include_domains / exclude_domains, and re-applied client-side through DomainFilter as defense in depth; the shared include+exclude/boost conflict rule is preserved;
    • language keeps Tavily's documented compound tags lowercased (zh-CN → zh-cn) and otherwise reduces to the primary subtag (en-GB → en); safesearch → boolean safe_search (off → omitted);
    • include_published_date: true so page_age is populated for the general topic;
    • country (Tavily wants full country names, not ISO codes) and the You.com-specific livecrawl*, crawl_timeout, boost_domains are dropped with one debug log.
    • One topic: "general" request per query: every hit lands in results.web, results.news stays empty. A second news request per query would double credit spend; this is documented.
  • Response mapping: forward-compatible #[serde(default)] structs read results[] { title, url, content, published_date } plus response_time and request_id; content → description, published_date → page_age. metadata[] carries "provider": "tavily", request_id as search_uuid, and response_time as latency (existing skip_serializing_if rules, You.com output unchanged).
  • Failures (credential-free): 401/403 name TAVILY_API_KEY without reading the body; 429 is not retried and surfaces Retry-After verbatim (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.rs size: adding the module pushed mod.rs to 507 production lines, so the shared null_as_default and read_response_limited helpers moved to provider.rs (where the provider contract lives). Both were and remain crate-private, so no public API changed. mod.rs is now 476 lines; no other file changed behavior.
  • Server plumbing: web_search_config.rs / config_file.rs are provider-generic already; only doc comments and tests changed.
  • Docs: README.md (feature bullet, quick start, config.toml comments, 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_json rather than enabling reqwest's json feature.

Deliberately kept in parity with brave.rs / you.rs rather 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-After is whitespace-trimmed, and the caller-supplied reqwest::Client contract is gateway-wide.

Test Plan

  • cargo fmt -- --check
  • cargo clippy --all-targets -- -D warnings
  • cargo 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.rs 476, tavily.rs 391, provider.rs 144)
  • New hermetic integration suite crates/agentic-server-core/tests/web_search_tavily_test.rs (12 tests, Axum mock on 127.0.0.1:0, nothing reaches the network):
    • 200 search: exact JSON body (clamped max_results, time_range, language, safe_search, exclude_domains, no country/livecrawl/api_key), Bearer auth, Content-Type, no Accept-Encoding, byte-exact model-facing output with "provider":"tavily" + search_uuid + latency, web_search_call public sources
    • date-range freshness → start_date/end_date widened by one day each side, no max_results when count unset
    • empty results → {"web":[],"news":[]} with no invented sources
    • domain filters: request-level allowlist wins and is forwarded natively; off-list results from a mock that ignores the filter are dropped client-side; exclude_domains forwarded and enforced
    • 401/403: names TAVILY_API_KEY, never echoes the key or the upstream body
    • 429: Retry-After integer and HTTP-date surfaced verbatim, absence reported, exactly one request (no retry)
    • 432/433: plan-limit message, no retry
    • 500: status + body; non-JSON body → "invalid JSON"
    • concurrency: 5 batched queries overlap by default (gateway ceiling 5); max_concurrent_queries = 1 serializes
  • Inline unit tests in tavily.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 filtering
  • config.rs, web_search_config.rs, config_file.rs tests extended for the third provider (labels, parsing, env/file resolution, api_key_env override, provider switching without pinned credentials, TOML round trip)

…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]>

@haoshan98 haoshan98 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@Zheng-Lu

Copy link
Copy Markdown
Contributor Author

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.

filter_by_published_date is now sent whenever freshness is set. Without freshness no date window is sent, so the flag is omitted entirely and nothing changes for those searches.

Worth mention that the trade-off the Tavily docs call out: setting filter_by_published_date: true also drops results with no detectable publication date. I think that's the behavior you asked for, and it matches how the gateway already treats domain allowlists — a requested filter is a hard contract, so a filtered search can return fewer than count results. I documented that in the README alongside the allowlist note.

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.

@haoshan98
haoshan98 merged commit 340ba40 into vllm-project:main Sep 28, 2026
19 checks passed
@Zheng-Lu
Zheng-Lu deleted the feat/327-tavily-provider branch October 9, 2026 13:17
maralbahari added a commit that referenced this pull request Oct 20, 2026
## 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]>
maralbahari pushed a commit that referenced this pull request Nov 10, 2026
## 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add Tavily as a selectable web_search provider

2 participants