Skip to content

Add web search with Claude's built-in search tool - #32

Open
aikhanjum wants to merge 1 commit into
mainfrom
feat/web-search
Open

aikhanjum wants to merge 1 commit into
mainfrom
feat/web-search

Conversation

@aikhanjum

Copy link
Copy Markdown
Collaborator

At the all-hands we said to skip Exa and do web search with curl in the shell. But the shell is off on purpose (workspaceBash = false, and turndown is stubbed because of that). So this PR uses Claude's own server-side web search instead. It needs no new infra and bills to the Anthropic credits we already have.

Server (src/server/pi.ts)

  • Adds web_search: anthropic.tools.webSearch_20260209({ maxUses: 3, userLocation: Princeton }). It's merged with PI's own tools after the consent filter, so no MCP server can shadow it.
  • Works on both models in the switcher (claude-opus-5, claude-sonnet-5).
  • Cost: $10 per 1,000 searches plus normal tokens. maxUses: 3 caps searches per model call.
  • System prompt: the apps come first for courses, schedules, seats, requirements and listserv events, and the web is the fallback. The model is told to link pages inline as [title](url) and to treat page text as untrusted.

Client

  • lib/tools.ts: extractWebSearch gets the query and deduplicated http(s) results. sourceName credits "The web".
  • ToolCards.tsx: a "From the web · query" card listing up to 5 pages, plus chips for searching, no results, and failure.
  • ChatPage.tsx: the "Worked from" line names "The web" instead of lumping searches in with "PI's desk".
  • tests/web-search.test.ts: parsing, dedupe, unsafe URLs, failed and running searches.

Testing

  • npm run typecheck, npm test (42 passing) and npm run build all pass.
  • I checked offline, with a stubbed fetch, that the request goes out as {"type":"web_search_20260209","name":"web_search","max_uses":3,...}. I also checked that on the next turn, earlier results are replayed as server_tool_use + web_search_tool_result with their encrypted content.
  • Not yet run against the live API. Please try it once on the deploy. If the Anthropic org has web search turned off in the Console, the search will come back as an error chip until an admin enables it.

🤖 Generated with Claude Code

PI can now look things up on the web for questions the TigerApps don't
cover. It uses Anthropic's server-side web_search tool (capped at 3
searches per model call, located in Princeton) instead of re-enabling
the shell. The system prompt keeps the apps first for course data and
asks for inline links. In chat, a search shows as a card listing the
pages it found, and the sources line credits The web.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant