feat(tools): add web_search tool (Tavily/Serper) and update to Search Tool mode#7
Merged
Conversation
- replace legacy tool object exports with factory functions - consolidate tool registration through a single tools array
- add web_fetch with HTML-to-Markdown conversion via turndown - add turndown runtime and type dependencies
Implement `web_search` tool (src/tools/WebSearch.ts) that queries the internet and returns titles, URLs, and content snippets. - TavilyWebSearch: calls api.tavily.com/search with configurable max_results (default 5), surfaces answer + result list - SerperWebSearch: calls google.serper.dev/search as fallback, maps organic results to the same shape - WebSearch() factory: picks Tavily when TAVILY_API_KEY is set, Serper when SERPER_API_KEY is set, stubs with an error message when neither is configured - Marks the tool isConcurrencySafe + isReadOnly; caps output at 3000 chars via maxResultChars Register WebSearch() in src/tools/index.ts alongside WebFetch.
Add two optional env-var exports to src/config.ts so the WebSearch tool can read them at runtime without importing dotenv directly. Update .env.example with placeholder values and comments pointing to https://tavily.com/ and https://serper.dev/ for key signup.
Replace the Mini-Apps-oriented SYSTEM prompt in src/index.ts with a concise web-search-focused one: - Describes web_search (returns summaries) and web_fetch (returns full Markdown) and when to use each - Removes the 200-line React/Vibe-Coding scaffolding instructions that are no longer the focus of this branch - Updates startup banner from "Mini Apps" → "Search Tool" - Replaces the three demo suggestions with search-oriented prompts (Vercel AI SDK version, top Agent frameworks, TS 5.8 features)
The real tool was renamed WebFetch (exposed as `web_fetch`), so update the mock model to match: - planResearch: emit `web_fetch` tool calls instead of `fetch_url` - summarizeResearch: filter results by `web_fetch` - Bump version string from v0.4.2 / "Mini Apps" → v0.4.3 / "Search Tool" in both the JSDoc header and the TEXT_RESPONSES.default greeting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a
web_searchtool powered by Tavily / Serper, and update all related configuration, system prompt, mock model, and documentation to match the new Search Tool workflow.Changes
New
src/tools/WebSearch.ts—WebSearch()factory that picks Tavily (TAVILY_API_KEY) over Serper (SERPER_API_KEY); falls back to a stub that prompts the user to configure a key. MarkedisConcurrencySafe+isReadOnly, 3 000-char output cap.Modified
src/tools/index.ts— registerWebSearch()alongsideWebFetch()(12 tools total)src/config.ts— exportTAVILY_API_KEYandSERPER_API_KEYfrom env.env.example— add placeholder entries and signup links for both search APIssrc/index.ts— rewrite system prompt for web-search mode; update startup banner and demo suggestionssrc/mock-model.ts— renamefetch_url→web_fetchinplanResearch/summarizeResearch; bump version string to v0.4.3 / "Search Tool"README.md— sync all sections to current implementation (tool table, env var docs, example prompts, remove Vibe Coding section, add web-search and preview sections)Testing
pnpm run preflight(lint + format) ✅web_searchwithTAVILY_API_KEYset returns results; without any key, returns a descriptive error messageChecklist
.env.exampleupdated for all new env vars