feat(web-search): intercept web search tool calls and execute via SearXNG#135
Open
jsboige wants to merge 1 commit into
Open
feat(web-search): intercept web search tool calls and execute via SearXNG#135jsboige wants to merge 1 commit into
jsboige wants to merge 1 commit into
Conversation
…rXNG When providers (Z.AI, GLM, OpenRouter) emit WebSearch/WebFetch tool calls or GLM's <searchWeb> tags, intercept them and execute via a local SearXNG instance instead of letting them fail. This covers three interception points: 1. Sub-agent requests in proxy-server.ts: Claude Code's WebSearch tool fires a sub-agent with a single user message. Intercept before handler selection and return SearXNG results. 2. Structured tool calls in openai-sse.ts: When the OpenAI SSE parser detects a WebSearch/WebFetch tool call, suppress it, execute SearXNG, and inject results as a text block in the stream. 3. GLM <searchWeb> tags: Detect these in accumulated text and execute SearXNG for each query, injecting results as text. Also handles empty responses (no content blocks) with a synthetic error message so downstream doesn't hang. New file: web-search-executor.ts — stream-safe SearXNG client with deadline-based timeout. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
When providers (Z.AI, GLM, OpenRouter models) emit WebSearch/WebFetch tool calls, they fail because the proxy doesn't implement server-side web search. GLM models also emit
<searchWeb>query</searchWeb>tags in their text output, which go unhandled. Additionally, Claude Code's built-in WebSearch tool fires sub-agent requests that get forwarded to the model provider instead of being executed locally.Changes
New file:
packages/cli/src/handlers/shared/web-search-executor.tsA stream-safe SearXNG client that:
SEARXNG_URLenv var, defaults tohttp://search.myia.io)packages/cli/src/proxy-server.tsAdd
interceptWebTools()function that intercepts sub-agent web search/fetch requests BEFORE handler selection. Detects the standard Claude Code WebSearch sub-agent pattern ("Perform a web search for the query: X") and returns SearXNG results as a streaming or non-streaming Anthropic-format response.packages/cli/src/handlers/shared/stream-parsers/openai-sse.tsThree enhancements:
WebSearch tool suppression -- When a structured WebSearch/WebFetch tool call is detected, set
suppressed = trueand buffer arguments. At finalization, execute SearXNG and inject results as a text block.GLM
<searchWeb>tag detection -- Detect<searchWeb>query</searchWeb>tags in accumulated text and execute SearXNG for each query.Empty response handling -- When no text or tool blocks were started, inject a synthetic error message so downstream doesn't hang.
Providers affected
How to test
Sub-agent interception:
GLM tags:
SearXNG URL configuration:
SEARXNG_URL=http://localhost:8080 claudish --model glm-4.7 "search for..."Notes
SEARXNG_URLenv var should be documented in the main README as an optional configuration.