Skip to content

tool_web_search

Crate: tool_web_search · Path: crates/llm_tools/tool_web_search
Description (Cargo.toml): Reusable LLM tool: web search via Tavily API. Returns a ToolSpec for any agent’s ToolRegistry.

Reusable LLM tool that performs web search via the Tavily Search API. Returns an agent_sdk::agent::ToolSpec ready to register with any agent’s ToolRegistry. WASM-compatible: uses spin_sdk::http::send on wasm32, reqwest on native for testing.

Dependency note: this crate lives under llm_tools/ but depends on agent_sdk (not llm_tools itself). The layering is tool_web_searchagent_sdkllm_tools.

From crates/llm_tools/tool_web_search/Cargo.toml:

No feature flags declared.

Platform-specific dependencies are activated via target gates:

  • wasm32: spin-sdk for outbound HTTP
  • native: reqwest + tokio for testing

Constants:

  • NAME"web_search"
  • DESCRIPTION — tool description string for the LLM

Types:

  • WebSearchArgsquery, max_results (1–10, default 5), search_depth ("basic" or "advanced")

Functions:

  • tool_spec(api_key, api_url) -> ToolSpec — factory that creates a ready-to-register ToolSpec
  • parameters_schema() -> Value — JSON Schema for the tool parameters (via schemars)
  • execute(api_key, api_url, args) -> Result<Value, String> — core async execution against Tavily API
use tool_web_search::tool_spec;
let search_tool = tool_spec(
std::env::var("TAVILY_API_KEY").unwrap(),
"https://api.tavily.com".to_string(),
);
// Register with an agent's tool registry
sdk_registry.register(search_tool);

Full API reference: cargo doc -p tool_web_search --no-deps