feat(providers): opt in to provider-hosted web search per model - #624
Merged
Merged
Conversation
Add a two-state per-model binding that attaches the vendor's hosted web search tool on the anthropic-messages and openai-responses wires. The pi-ai patch attaches the tool, extracts search blocks and citations from the stream, and replays them verbatim on later turns; a pi-agent-core patch forwards the new progress event so each search round renders live as its own transcript activity row. Search state normalizes to UiMessage.hostedSearch (one round per provider call), persists as an additive transcript block without a SQL migration, and degrades honestly on endpoints that accept but never execute the tool. Recorded in ADR 0291.
Owner
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
Adds an opt-in, per-model native web search capability: when enabled in the model's settings (attachment section), the provider's server-side search tool is attached on the wires that define one —
web_search_20250305foranthropic-messages,{type:"web_search"}foropenai-responses/azure-openai-responses— and each search round renders as its own transcript activity row, live while streaming.Unlike an MCP search server, a hosted tool executes inside the provider request and returns structured blocks that must round-trip for multi-turn grounding, so extraction and replay live in the adapters rather than in a plugin (rationale in ADR 0294).
How it works
ModelBinding.nativeWebSearch(two-state opt-in; no catalog baseline since models.dev publishes no hosted-tool capability) flows through the existing model-config channel into pi-ai'sModel.webSearch. One evaluation point,resolveNativeWebSearchin@pi-desktop/shared, keyed on the resolved wire API only — never vendor names or URL hostnames.patches/@earendil-works__pi-ai@0.85.1.patch): attach the tool; ask Responses forweb_search_call.action.sourcesviainclude; extractserver_tool_use/web_search_tool_result/web_search_call/ citation annotations intohostedSearchcontent blocks (raw wire payloads kept verbatim); accumulate streamedinput_json_deltaso the query is visible live; replay both block halves on later turns. The Azure Responses variant gets the same attachment.patches/@earendil-works__pi-agent-core@0.85.1.patch): the agent loop forwards the adapters'hosted_search_updateasmessage_update; without it the events died in the loop's switch and search activity only appeared when the turn finished.hostedSearchFromBlocksnormalizes toUiMessage.hostedSearch.rounds[](one round per provider call, paired by block id, per-round status/query/sources). Each round renders as aHostedSearchRowon the standard tool-row idiom, distinguishing search / open-page / find-in-page. Sources are plain text links — no favicon fetches, so transcripts never leak source hostnames to third parties (fix(desktop): keep hosted-search citations on the source origin #579 rule).hostedSearchtranscript block viaui_to_record/record_to_ui; no SQL migration.Affected docs
docs/spec/03-runtime/11-provider-model-system.md(rule 10a),04-data-storage.md(block vocabulary) — both languagesValidation
pnpm build:js, workspace typecheck (0 errors),pnpm lint(biome + style tokens), architecture checkcargo test -p host-core --locked: 525 passed;cargo fmt --check; clippy clean apart from one pre-existing unrelated warningincludesafe everywhere; Kimi channels only return sources viainclude; DeepSeek's Anthropic wire executes real server-side search; DeepSeek's Responses wire accepts but never executes (no search rows, pseudo-call text logged by the existing pseudo-tool-call detector)Compatibility & risks
@earendil-works/pi-ai/pi-agent-coreand removal once released.pause_turnkeeps pi-ai's existing mapping tostop; a long searching turn on the official Anthropic wire may end early. Known limitation, noted in the ADR.