Skip to content

feat(tool): add Serply as a selectable web_search provider - #420

Merged
maralbahari merged 5 commits into
vllm-project:mainfrom
googio:feat/serply-search
Oct 20, 2026
Merged

maralbahari merged 5 commits into
vllm-project:mainfrom
googio:feat/serply-search

Conversation

@googio

@googio googio commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

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.

@maralbahari maralbahari 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 contributing Serply support! I left a comment on the language mapping.

Add `serply` beside `you`, `brave`, `tavily` and `searxng` in
WebSearchProviderKind, configured through SERPLY_API_KEY and
https://api.serply.io. The provider calls GET /v1/search with the
X-Api-Key header and maps count, country, language, safesearch and
freshness onto Google's num, gl, hl, safe and tbs parameters. language
also sets the lr=lang_xx result-language restrict for the languages
Google documents one for; other languages are sent as hl only.

Domain allowlists and blocklists are sent as site:/-site: query
operators and explicit date ranges as after:/before: operators, so the
10-result page goes to matching hosts; the shared DomainFilter still
re-checks every result. Google redirect links (/url?q=...) are
unwrapped before filtering.

Closes vllm-project#381

Signed-off-by: serply <[email protected]>
@googio
googio force-pushed the feat/serply-search branch from e921707 to df3ff51 Compare October 11, 2026 15:22
haoshan98 and others added 2 commits October 16, 2026 12:35
Main added a required async_execution field to FunctionToolCall, so the
Serply test stopped compiling after the merge. Match the Tavily fixture.

Signed-off-by: serply <[email protected]>
Google ignores query terms past the 32nd word, so a long allowlist pushed
after:/before: out of range and the date filter was silently dropped.
Domains are re-checked client-side, dates are not.

Signed-off-by: serply <[email protected]>
@maralbahari
maralbahari merged commit 62471db into vllm-project:main Oct 20, 2026
17 checks passed
maralbahari pushed a commit that referenced this pull request Oct 22, 2026
## Summary

Closes #457

The gateway had only global concurrency bounds, so one caller could use
up the upstream's capacity and shared web-search or code-interpreter
quotas for everyone. This PR adds an opt-in, per-caller request rate
limit. It is off by default: no middleware is installed and no headers
change.

**Configuration** (CLI > environment > `[server]` file setting,
following `max_request_body_size_bytes`):

| CLI | Environment | File (`[server]`) |
| --- | --- | --- |
| `--rate-limit-requests-per-minute` |
`AGENTIC_RATE_LIMIT_REQUESTS_PER_MINUTE` |
`rate_limit_requests_per_minute` |
| `--rate-limit-burst` | `AGENTIC_RATE_LIMIT_BURST` | `rate_limit_burst`
(default: the per-minute rate) |

- A burst without a rate, a zero value, or a burst over one hour of
requests fails at startup, and the error names the setting.
- An explicit CLI value outranks a malformed inherited environment
value.

**Caller key** (first match):
1. OIDC issuer and subject;
2. a keyed hash of the bearer token;
3. a keyed hash of `x-api-key`;
4. one shared anonymous bucket.

Raw credentials are never stored. A WebSocket is keyed by its upgrade
request's own credentials, never by the server's `OPENAI_API_KEY`
fallback.

**Algorithm:** GCRA (equivalent to a token bucket). Each caller holds
one theoretical arrival time in a `std::sync::Mutex<HashMap>`, using
`tokio::time::Instant` so tests can pause time. No lock is held across
an await. Memory is bounded at 100,000 callers: idle callers are pruned
first, and new callers share an overflow bucket while every tracked
caller is active, with a `warn` at most once a minute. No new
dependencies.

**HTTP:**
- The middleware is a `route_layer` on the protected routes, layered
before OIDC so that it runs after authentication and sees the principal.
`/health`, `/ready` and Swagger are exempt.
- A limited request never reaches the upstream. It gets `429` in OpenAI
format (`rate_limit_error` / `rate_limit_exceeded`), or in Anthropic
format with `request-id` on `/v1/messages` and `count_tokens`.
- Headers: `retry-after`, `retry-after-ms`,
`x-ratelimit-limit-requests`, `x-ratelimit-remaining-requests: 0`, and
`x-ratelimit-reset-requests`. The last is the time until the full burst
returns, formatted like `1.5s` or `2m3s`.

**WebSocket:**
- The upgrade is charged by the HTTP middleware, which also carries the
caller's bucket into the connection.
- Each client `response.create` is charged before any lane or byte
capacity is reserved. A limited create gets an `error` frame with
`status: 429`, and the connection stays open.
- `response.steer`, `response.inject` and gateway-started continuations
are not charged. The check sits where client messages arrive, not in
`WsMultiplexer::schedule`, which also runs automatic continuations.

**Structure:**
- `rate_limit.rs` holds the limiter, middleware, `429` builder and retry
formatting.
- `server_settings.rs` resolves the `[server]` table. Its first commit
is a pure move of the existing body-size resolution out of `main.rs`,
which was at its 644-line exception (now 616).
- `ServerConfig` gains `rate_limit`, so `AppState` and its 16 test
literals are unchanged.
- `auth.rs` is at its line baseline. Its only change is visibility
(`AuthErrorFormat` and `for_path`, reused for the 429 format), and
`bearer_token` in `auth/api_key.rs` is also now crate-visible.

**Scope:**
- Per process: with N replicas, a caller can send up to N times the
rate. The API, container and Kubernetes docs say so.
- Not in this PR:
  - distributed or token-based quotas (#107, #315);
  - per-IP keying, which needs trusted-proxy configuration;
- `agentic` launcher flags. The launcher's child process inherits the
environment variables, and the configuration file is shared.

Conflicts: a trial merge with #436, #440 and #420 is clean.

## Test Plan

**Unit tests:**
- `rate_limit::tests` (paused time):
- burst, then one request per interval, including exact `retry_after`
and `reset`;
  - steady state;
  - independent callers;
  - pruning before overflow;
- credentials kept only as a hash (no token text in `Debug`; bearer and
`x-api-key` share a key; `Basic` is anonymous);
  - retry rounding and `x-ratelimit-reset-requests` formatting;
  - the burst bound.
- `server_settings::tests`:
  - off by default;
- file, then environment, then CLI, including a CLI value over a
malformed environment value;
  - the burst defaulting to the rate;
  - five invalid inputs, each named in its error;
  - flag parsing;
  - the generated `[server]` table.
- `config_file` tests: the new keys parse, `0` is rejected, and an unset
burst is not written.

**`tests/rate_limit_test.rs`** (one request per minute, so the outcomes
are deterministic):
- `a_caller_over_its_limit_gets_an_openai_429_with_retry_headers`: exact
body and all five headers; the limited request never reaches the
upstream; another bearer is unaffected.
- `callers_without_credentials_share_one_bucket`
- `health_endpoints_are_never_limited`
- `messages_routes_answer_in_the_anthropic_format_and_key_by_api_key`:
exact body; the `request-id` header matches the body.
- `rate_limiting_is_off_by_default`: 10 requests and no rate-limit
headers.
-
`websocket_creates_are_charged_and_a_limited_create_keeps_the_connection`:
the upgrade and two creates use a burst of 3; the next create gets the
exact `429` frame; then `response.steer` is answered on the same
connection.
- `http_and_websocket_share_a_bucket_and_the_upgrade_is_charged`: a
limited upgrade gets HTTP `429` before switching protocols.
- `a_websocket_without_credentials_is_not_charged_to_the_server_key`


**`oidc_auth_test::rate_limits_key_oidc_callers_by_subject_not_token`:**
two tokens for one subject share a bucket, and another subject has its
own.

**Negative controls** (each applied to the finished code):

| Change | Result |
| --- | --- |
| Never install the HTTP layer | 6 of the 8 integration tests fail;
health and off-by-default pass |
| Drop the WebSocket charge | Both WebSocket charging tests fail |
| Layer the limiter outside OIDC | The OIDC subject test fails |
| Off-by-one in the GCRA comparison | 4 unit tests fail |
| Disable pruning | The pruning test fails |

**Binary smoke test** at 1 request per minute:
- `--help` lists both flags.
- `AGENTIC_RATE_LIMIT_BURST` without a rate fails at startup:
`AGENTIC_RATE_LIMIT_BURST requires
AGENTIC_RATE_LIMIT_REQUESTS_PER_MINUTE`.
- The first `/v1/models` request reaches the upstream; the second gets
`429` with all headers; `/health` still returns `200`.

**Gate:**
- `cargo fmt -- --check`
- `cargo clippy --workspace --all-targets -- -D warnings`
- Feature clippy (`--features embedded-code-interpreter`) for both
crates
- The Rust file-size ratchet
- `pre-commit run --all-files`
- `mkdocs build --strict`
- `cargo test --workspace --no-fail-fast`: 2530 passed, 1 failed. The
failure is
`tool::web_fetch::http::tests::the_deadline_bounds_a_slow_origin`, which
also fails on unmodified `main` when the whole lib suite runs in
parallel.

---------

Signed-off-by: Zheng Lu <[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 Serply as a selectable web_search provider

4 participants