Repository navigation
Closed
Labels
enhancementNew feature or request
Description
Problem statement / motivation
Phase 1 of #291
Scope: Pure refactor (Zero behavior change, byte-identical output)
Currently, crates/agentic-server-core/src/tool/web_search.rs (807 lines) has three architectural limitations that block adding new search providers cleanly:
- Untyped Pass-Through to the LLM:
execute_searchcopies raw You.com JSON (results.web[]/results.news[]) verbatim into the model-facing output string (web_search.rs:230-236).WebSearchProviderResponseuses untypedserde_json::Value(:262-265). - Monolithic File:
A single 800+ line file mixes the OpenAI tool adapter, argument validation, and vendor-specific You.com HTTP request/response handling. - Credential Security Leak:
YouSearchProviderderivesDebugover rawOption<String>, which prints plaintext API keys in debug logs (:267-272).
Proposed solution
This phase establishes the typed contract and modular layout with zero external behavior change, making Phase 2 adding new search provider a pure additive change.
A. Modular File Layout
Split crates/agentic-server-core/src/tool/web_search.rs into:
crates/agentic-server-core/src/tool/web_search/
├── mod.rs # WebSearchHandler, WebSearchProvider trait, typed structs, public output mapping
├── args.rs # WebSearchArguments, typed Freshness, domain post-filter helper
└── you.rs # YouSearchProvider, HTTP request shaping, and response parsing
B. Typed Normalization Contract
Replace serde_json::Value with strongly typed models:
WebSearchResult: Containsurl,title,description,snippets: Vec<String>,page_age: Option<String>,contents: Option<String>(livecrawl). Serialized JSON keys remain unchanged; cosmetic fields (thumbnails, favicons) are dropped.WebSearchProviderMetadata:{ provider, query, latency_ms }.WebSearchProviderResponse:{ web: Vec<WebSearchResult>, news: Vec<WebSearchResult>, metadata: WebSearchProviderMetadata }.
C. Configuration & Extension Wiring
- Add
WebSearchProviderKind(#[non_exhaustive], initiallyYouonly, with#[default]) incrates/agentic-server-core/src/config.rs. - Add
WebSearchProviderConfig.provider. - Add
WebSearchHandler::from_configand hook it intoToolExecutors::from_config(tool/executors.rs:87). - Signature Guarantee: Keep all existing public constructors (
from_env,from_values,with_api_key,spec_only) completely unchanged. - Wrap API credentials in a newtype
ApiKeywith a redactingDebugimpl (ApiKey(<redacted>)).
Decision on #291 made at the moment
| Question | Default Decision | Rationale |
|---|---|---|
Q1 (page_age vs published_at) |
Keep page_age |
Guarantees 100% byte-identical serialized output for You.com in Phase 1. |
| Q4 (Enum Location) | config.rs |
Sits naturally next to SqliteTempStore, matching repository conventions. |
Additional context
Scope Boundaries
| Included in Phase 1 | Explicitly Excluded (Deferred to Phase 2 / Later) |
|---|---|
✅ Module split (mod.rs, args.rs, you.rs) |
❌ No third-party provider code |
✅ Typed WebSearchResult & WebSearchProviderResponse |
❌ No new config.toml keys or environment variables |
✅ Credential redacting Debug |
❌ No default base URL for You.com (#291 Q2) |
✅ WebSearchProviderKind::You and from_config |
❌ WebSearchProvider trait remains private |
| ✅ Byte-identical output assertion test | ❌ No doc updates (except CHANGELOG.md) |
Verification Checklist
- Byte-Identity Test: Serialize handler output for existing mock fixture (
tests/web_search_tool_test.rs:291) and assert exact byte equality with pre-refactor output. - Fixture Test: Add a redacted real You.com response fixture to verify all non-cosmetic fields are preserved.
- Public Output Contract: Verify
sources_from_outputcontinues to generate identicalweb_search_call.action.sources. - Integration Tests: All existing tests pass unmodified across both crates (including all
with_api_keycallers). - Code Hygiene:
cargo clippy --all-targets -- -D warnings(clean)cargo fmt -- --check(clean)pre-commit run --all-files(clean)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
refactor(tool): modularize web search and type result normalization (v…
feat(tool): add Tavily as a selectable web_search provider (#327) (#329)