magpie icon indicating copy to clipboard operation
magpie copied to clipboard

search: searcher request is non-streaming, so stream-only upstreams lose web_search_tool_result; add per-agent searcher

Open lixiaoshuang79 opened this issue 1 day ago • 2 comments

Summary

searchWith asks the searcher with stream: false (searchBody in internal/gateway/search.go). Some Anthropic-compatible upstreams only include server_tool_use / web_search_tool_result blocks when the request is streamed; their non-stream response contains only thinking / text, while usage.server_tool_use.web_search_requests still reports the searches. In that case the searcher did search, but searchWith parses zero pages: found is empty, Sources: is not appended, and the client's WebSearch result has no links (Claude Code shows No links found). The answer text still contains URLs, so it is not a total failure, but structured links are lost.

Reproduction

  • magpie 0.1.5456, macOS.

  • A custom provider with an Anthropic-compatible /v1/messages endpoint. The provider is marked searches: true and one of its models runs the hosted web_search_20250305 tool.

  • Settings: searchAll: true, searcher: <provider>/<model>, no search API configured.

  • A client WebSearch (Claude Code) triggers the searcher. The searcher request magpie sends is stream: false.

  • Same query and model, directly:

    • non-stream response content[].type: ["thinking", "text"]
    • stream response content_block_start types: ["thinking", "server_tool_use", "web_search_tool_result", "text"]
    • the stream's web_search_tool_result contains the pages; the non-stream one has none.
    • usage.server_tool_use.web_search_requests is non-zero in both.
  • Result: searchWith returns the text (it contains ://, so it passes the empty check), found is empty, no Sources: list is appended, and the client receives text without structured links.

Proposal

  1. Stream the searcher request. Send searchBody with stream: true and reuse the gateway's existing SSE parsing to collect web_search_tool_result blocks. If streaming every searcher is undesirable, retry once with stream: true when found is empty (optionally only when usage.server_tool_use.web_search_requests > 0, so a model that really did not search is not asked twice).

  2. Optional per-provider/model switch. Add a setting such as searcherStream (auto / on / off) if some upstreams behave differently. auto would do the retry above; on would always stream; off keeps today's behavior.

  3. Per-agent scoping. searchAll and searcher are global settings. It would help to allow per-agent overrides (for example agents.<agent>.searcher and agents.<agent>.searchAll), so one agent can use a specific searcher while other agents keep their provider's own search. This is adjacent to #2286 (let an agent choose the search source) and #7708 (per-agent provider isolation).

  4. Expose searchAll in the CLI. magpie settings list does not include searchAll (it is only in the settings JSON), so scripted configuration has to edit the file directly. Listing it would make this usable from magpie settings.

Workaround

A local SearXNG-compatible search API that streams the same upstream model and returns results works today (magpie search add searxng url=... + searchFirst=api), but it duplicates the searcher path and is not per-agent either.

Notes

No keys, internal hostnames or customer data are included. The provider is a generic self-hosted Anthropic-compatible endpoint.

lixiaoshuang79 avatar Dec 03 '26 04:12 lixiaoshuang79

Fixed in v0.1.5470 (db54f0bc74): magpie's web search now asks the searcher's model with stream: true and gathers the stream into the reply it reads. A relay that writes server_tool_use / web_search_tool_result only into a stream keeps its pages, so Claude Code's WebSearch gets its links and "Sources:" again. A relay that turns stream: false away, or answers it with an empty 200, now searches too. Only magpie's own search asks change; every other Messages request is sent as the client sent it.

Tested with a fake relay built from this report (whole request: thinking and text only, with web_search_requests: 1; streamed: the search blocks). All three cases were red on the old code and pass now. It wasn't tried against your relay itself, so please say if v0.1.5470 still shows "No links found".

Still open on this issue:

  • a searcher, and Search with every model, chosen per agent (today both are one setting for every agent, in Settings › Models › Web search);
  • searchAll in magpie settings list.

magpie's other whole asks on Messages (advisor, review, memory) and image drawing on a chat model have the same gap with a relay that only streams. They don't lose search results, but they fail; filed as #8775.

yetone avatar Dec 03 '26 05:12 yetone

Confirmed on v0.1.5470 (macOS): WebSearch now returns structured links again — the searcher's web_search_tool_result pages come through, and no more "No links found". Tested against a custom Anthropic-compatible relay. Thanks for the quick fix. Per-agent searcher/searchAll remains the open ask.

lixiaoshuang79 avatar Dec 03 '26 05:12 lixiaoshuang79