refactor: 统一自建 Tool Search — 移除 tool_reference/defer_loading 依赖,全 provider 通用

- 重命名 ExecuteTool → ExecuteExtraTool,作为一等工具始终可用
- ToolSearchTool 输出改为纯文本(区分 core/deferred),移除 tool_reference blocks
- 移除 modelSupportsToolReference() 及相关 GrowthBook 配置
- 移除 API 侧 defer_loading 字段和 tool search beta header 注入
- 简化 system prompt(工具使用指南从 ~120 行压缩到 ~10 行)
- extractDiscoveredToolNames 支持文本格式解析(向后兼容旧 session 的 tool_reference)
- 更新 promptEngineeringAudit 测试以匹配简化后的 prompt 结构

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-05-09 14:19:31 +08:00
parent 4fc95bd5a7
commit 8c157f0767
17 changed files with 280 additions and 401 deletions

View File

@@ -128,14 +128,14 @@ export const ExecuteTool = buildTool({
async checkPermissions() {
return {
behavior: 'passthrough',
message: 'ExecuteTool delegates permission to the target tool.',
message: 'ExecuteExtraTool delegates permission to the target tool.',
}
},
renderToolUseMessage(input) {
return `Executing ${input.tool_name}...`
},
userFacingName() {
return 'ExecuteTool'
return 'ExecuteExtraTool'
},
mapToolResultToToolResultBlockParam(content, toolUseID) {
return {

View File

@@ -33,7 +33,6 @@ mock.module('src/utils/toolSearch.js', () => ({
isToolSearchEnabledOptimistic: () => true,
getAutoToolSearchCharThreshold: () => 100,
getToolSearchMode: () => 'tst' as const,
modelSupportsToolReference: () => true,
isToolSearchToolAvailable: async () => true,
isToolSearchEnabled: async () => true,
isToolReferenceBlock: () => false,
@@ -43,7 +42,7 @@ mock.module('src/utils/toolSearch.js', () => ({
}))
mock.module('src/constants/tools.js', () => ({
CORE_TOOLS: new Set(['ExecuteTool', 'ToolSearch']),
CORE_TOOLS: new Set(['ExecuteExtraTool', 'ToolSearch']),
}))
// Mock messages module

View File

@@ -1 +1 @@
export const EXECUTE_TOOL_NAME = 'ExecuteTool'
export const EXECUTE_TOOL_NAME = 'ExecuteExtraTool'

View File

@@ -1,10 +1,12 @@
import { EXECUTE_TOOL_NAME } from './constants.js'
export const DESCRIPTION =
'Execute a deferred tool by name with parameters. Use this after discovering a tool via ToolSearch.'
'ExecuteExtraTool — execute a deferred tool by name with parameters. This tool is always available. Use it after discovering a tool via ToolSearch.'
export function getPrompt(): string {
return `Execute a deferred tool by name. This tool accepts a tool_name and params object, looks up the target tool in the global tool registry, and delegates execution to it.
return `ExecuteExtraTool — execute a deferred tool by name. This tool is always available in your tool list. You do NOT need to search for it.
This tool accepts a tool_name and params object, looks up the target tool in the global tool registry, and delegates execution to it.
Use this tool after discovering a deferred tool via ToolSearch. The tool_name must match the exact name returned by ToolSearch (e.g., "CronCreate", "mcp__server__action").