fix: respect declared claude web search tool names

This commit is contained in:
sususu98
2026-04-29 19:24:53 +08:00
parent 1c0c426b85
commit 0d107dd566
2 changed files with 22 additions and 2 deletions

View File

@@ -377,8 +377,6 @@ func buildClaudeWebSearchToolNameSet(tools gjson.Result) map[string]struct{} {
return true
}
names["web_search"] = struct{}{}
names[toolType] = struct{}{}
if name := tool.Get("name").String(); name != "" {
names[name] = struct{}{}
}

View File

@@ -248,6 +248,28 @@ func TestConvertClaudeRequestToCodex_WebSearchToolMapping(t *testing.T) {
}
}
func TestConvertClaudeRequestToCodex_WebSearchToolChoiceUsesDeclaredTypedToolName(t *testing.T) {
inputJSON := `{
"model": "claude-opus-4-7",
"tools": [
{"type": "web_search_20250305", "name": "browser_search"},
{"name": "web_search", "description": "Local search", "input_schema": {"type":"object","properties":{}}}
],
"tool_choice": {"type":"tool","name":"web_search"},
"messages": [{"role": "user", "content": "hello"}]
}`
result := ConvertClaudeRequestToCodex("test-model", []byte(inputJSON), false)
resultJSON := gjson.ParseBytes(result)
if got := resultJSON.Get("tool_choice.type").String(); got != "function" {
t.Fatalf("tool_choice.type = %q, want function. Output: %s", got, string(result))
}
if got := resultJSON.Get("tool_choice.name").String(); got != "web_search" {
t.Fatalf("tool_choice.name = %q, want web_search. Output: %s", got, string(result))
}
}
func TestConvertClaudeRequestToCodex_AssistantThinkingSignatureToReasoningItem(t *testing.T) {
signature := validCodexReasoningSignature()
inputJSON := `{