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_search → agent_sdk → llm_tools.
Feature flags
Section titled “Feature flags”From crates/llm_tools/tool_web_search/Cargo.toml:
No feature flags declared.
Platform-specific dependencies are activated via target gates:
- wasm32:
spin-sdkfor outbound HTTP - native:
reqwest+tokiofor testing
Public API (from src/lib.rs)
Section titled “Public API (from src/lib.rs)”Constants:
NAME—"web_search"DESCRIPTION— tool description string for the LLM
Types:
WebSearchArgs—query,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-registerToolSpecparameters_schema() -> Value— JSON Schema for the tool parameters (viaschemars)execute(api_key, api_url, args) -> Result<Value, String>— core async execution against Tavily API
Example sketch
Section titled “Example sketch”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 registrysdk_registry.register(search_tool);Full API reference: cargo doc -p tool_web_search --no-deps