fix: honor required search tools across providers - #887
Open
dengkai666666 wants to merge 3 commits into
Open
Conversation
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.
中文说明
修复内容
tool_choice: "required",避免模型自行跳过搜索。web_search/x_search的required语义,不再错误降级为auto。grok-4.5搜索请求优先选择 Console,因为实测 Build 即使收到required仍可能只返回文本、不执行搜索。x_keyword_search、x_semantic_search等内部实现细节,但合成只读的标准x_search_call状态节点,让客户端确认搜索确实执行过。问题原因
Creative Console 原先只声明搜索工具,没有指定
tool_choice,模型可以选择不调用。Console 归一化又没有把 Hosted Search 视为保留下来的客户端工具,导致required被改回auto。此外,原有 Provider 回退顺序不感知工具能力,X 搜索可能进入 Web,而grok-4.5强制搜索也可能先落到当前不会执行搜索的 Build。Build 响应过滤器会隐藏内部 X 搜索调用。该设计避免泄漏上游实现细节,但也让客户端无法区分“执行过搜索”和“没有搜索”。因此本 PR 只合成通用状态节点,不暴露关键词、用户搜索或线程抓取等内部数据。
路由行为
Build → Console → Web。grok-4.5强制 Web/X 搜索:Console → Build → Web。grok-4.5的顺序是根据实际兼容性测试增加的处理。长期方案更适合建立 Provider/模型级工具能力元数据,替代模型名特判。验证
go test -run TestConversationToolRequirementsRouteByProviderCapability ./internal/application/gatewaygo test -run 'TestFilterBuildPromptCacheResponse(JSON|Stream)' ./internal/infra/provider/cligo test -run TestNormalizeRequestAppliesConsoleCompatibilityBoundary ./internal/infra/provider/console实测同等
required请求下,Build 的grok-4.5没有产生搜索调用;Console 可以完成原生 Web/X 搜索。Web Provider 不能执行 X Search,因此路由层会将其排除。Summary
tool_choice: "required"when Creative Console search switches are enabledweb_searchandx_searchtools in Console request normalizationgrok-4.5search requests because Build currently ignores required hosted searchx_search_callafter filtering Build internal search implementation detailsProblem
Creative Console previously declared search tools without a
tool_choice, so the upstream model could skip them. Console normalization also treated hosted search tools as if no client tool had survived and downgradedrequiredtoauto. In addition, provider fallback was not capability-aware: Web cannot execute X search, and a requiredgrok-4.5search could land on Build even though that route currently returns plain text without a search call.The Build response filter intentionally hides internal calls such as
x_keyword_searchandx_semantic_search, but that also made a successful X search indistinguishable from no search. This change retains the filtering and emits only a provider-neutral, read-onlyx_search_callstatus item.Routing behavior
grok-4.5with required Web or X search prefers Console, then Build, then Web.The
grok-4.5ordering is an observed compatibility workaround. A longer-term model/provider capability registry would be preferable to a model-name special case.Verification
go test -run TestConversationToolRequirementsRouteByProviderCapability ./internal/application/gatewaygo test -run 'TestFilterBuildPromptCacheResponse(JSON|Stream)' ./internal/infra/provider/cligo test -run TestNormalizeRequestAppliesConsoleCompatibilityBoundary ./internal/infra/provider/consoleUpstream validation with equivalent required requests showed Build
grok-4.5returning no search calls, while Console completed native Web and X searches. Web remains excluded from X search because it cannot execute that hosted tool.