Web Tools API¶
web ¶
Pluggable web search + fetch tools for Orqest agents.
Autonomous agents that decide to investigate a question on the open
web need two reliable primitives: a ranked search, and a content-aware
page fetch. web_search and web_fetch provide both as async
functions that agents call directly — no provider-specific SDKs in the
calling code, no hard dependency on any single search vendor.
Provider selection is driven by env vars so ops can swap backends without touching agent code:
ORQEST_WEB_PROVIDER— one of"tavily"(default),"exa","brave","serper", or"none"(disabled).ORQEST_WEB_API_KEY— the API key for the selected provider.
When ORQEST_WEB_API_KEY is unset or the provider is "none" the
tools degrade gracefully: web_search returns an empty result list
with a disabled_reason note, web_fetch still works for public
URLs (no key required for a plain GET). This lets investigation tools
stay functional in offline / CI settings without tripping on missing
credentials.
WebSearchResult
dataclass
¶
One hit returned by :func:web_search.
WebSearchResponse
dataclass
¶
WebSearchResponse(
query: str,
results: list[WebSearchResult] = list(),
provider: str = "none",
disabled_reason: str | None = None,
)
Full response envelope returned by :func:web_search.
WebFetchResult
dataclass
¶
Content fetched by :func:web_fetch.
web_search
async
¶
web_search(
query: str,
*,
k: int = DEFAULT_RESULTS,
provider: str | None = None,
api_key: str | None = None,
timeout_s: float = DEFAULT_TIMEOUT_S,
) -> WebSearchResponse
Search the web and return up to k ranked hits.
Selects the provider from the provider argument, then from
ORQEST_WEB_PROVIDER, then defaults to "tavily". Degrades
gracefully when no API key is available — returns an empty
:class:WebSearchResponse with disabled_reason explaining why.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Free-text search query. |
required |
k
|
int
|
Maximum number of results. |
DEFAULT_RESULTS
|
provider
|
str | None
|
Override of the env-selected provider. |
None
|
api_key
|
str | None
|
Override of the env-supplied API key. |
None
|
timeout_s
|
float
|
HTTP timeout in seconds. |
DEFAULT_TIMEOUT_S
|
Source code in orqest/tools/web.py
web_fetch
async
¶
web_fetch(
url: str,
*,
max_chars: int = MAX_FETCH_CHARS,
timeout_s: float = DEFAULT_TIMEOUT_S,
) -> WebFetchResult
Fetch url and return its (truncated) body as text.
No API key needed — this is a plain GET. The body is truncated to
max_chars to keep LLM context bounded; consumers that need the
full body can pass max_chars=-1 or zero to disable truncation.