Skip to main content

Crate harness_websearch

Crate harness_websearch 

Source
Expand description

WebSearch tool — Rust port of @agent-sh/harness-websearch.

Conforms to agent-knowledge/design/websearch.md. Same contract as the TS package: declarative web search via a session-configured SearXNG backend, with tool-layer SSRF defense on the backend URL, a permission hook, a result-count cap, and a discriminated ok/empty/error result surface. WebSearch finds; WebFetch reads — there is no HTML extraction and no spill-to-file (a result list is bounded by count).

Structs§

BraveEngine
EngineBaseUrls
Per-engine base-URL overrides (tests point these at local fixture servers).
FallbackEngine
MarginaliaEngine
MojeekEngine
ReqwestEngine
ResolvedEngine
The resolved engine plus its chain (for diagnostics) and whether it’s the bare keyless default.
SearchError
SearchMetadata
TavilyEngine
WebSearchEmpty
WebSearchEngineInput
WebSearchEngineResult
WebSearchError
WebSearchOk
WebSearchParams
WebSearchPermissionPolicy
Session permission policy plus the autonomous escape hatch for tests.
WebSearchResultItem
WebSearchSessionConfig
WikipediaEngine

Enums§

BlockClass
EngineClass
Engine coverage class. A “general” engine’s empty is a trustworthy “the web had nothing” signal; a niche/vertical empty says far less, so the fallback chain treats a niche/vertical-only empty while a general engine ERRORED as a degraded failure rather than a clean empty. Mirrors TS EngineClass.
SafeSearch
SearchErrorCode
Engine-local error code, distinct from harness_core::ToolErrorCode. The orchestrator translates these into a ToolError reusing the existing core code set.
SsrfDecision
WebSearchParseError
WebSearchResult
WebSearchTimeRange

Constants§

DEFAULT_CATEGORIES
DEFAULT_COUNT
DEFAULT_LANGUAGE
DEFAULT_TIMEOUT_MS
DEFAULT_USER_AGENT
Default User-Agent. Harnesses can override via session.default_headers. Identifies as an agent tool with a contact URL — verified accepted (no anti-bot challenge) by Mojeek and the MediaWiki API.
MAX_COUNT
MAX_QUERY_LENGTH
MAX_SNIPPET_CAP
MIN_COUNT
MIN_SNIPPET_CAP
MIN_TIMEOUT_MS
SESSION_BACKSTOP_MS
SNIPPET_CAP
WEBSEARCH_TOOL_DESCRIPTION
WEBSEARCH_TOOL_NAME

Traits§

WebSearchEngine

Functions§

classify_host
Resolve the host and run the IP classifier against each result. Returns Blocked if any resolved IP lands in a range not opted into.
classify_ip
Synchronous helper — reads the input string as an IP if possible, classifies. Used by tests + by the host-resolver path (each resolved address is fed in here).
default_engine
format_empty_text
format_ok_text
render_search_block
Back-compat: the old <search>…</search> block renderer now returns the compact header line (kept as a public export).
resolve_engine
Build the engine to run for this session — the Rust twin of TS resolveEngine. Priority: explicit override → Brave/Tavily (keyed) → SearXNG (searxng_url) → keyless chain (Mojeek → Marginalia → Wikipedia).
safe_parse_websearch_params
websearch