Files
CLIProxyAPI/internal/runtime/executor/helps/claude_tool_choice.go
Luis Pater 1d45a5f332 fix(claude): handle forced tool restrictions in claude 5.5
- Fall back to schema prompts for Antigravity Claude 5.5 while preserving unrelated request settings.
- Normalize unsupported forced tool choices before thinking preparation in direct Claude execution and token-count paths.
- Add regression coverage for schema integrity, model boundaries, retries, and final payload rule precedence.

Closes: #7000
2026-10-26 20:36:51 +08:00

31 lines
1.0 KiB
Go

package helps
import (
"strings"
"github.com/router-for-me/CLIProxyAPI/v8/internal/thinking"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)
// NormalizeClaudeToolChoice downgrades forced tool use on Claude 5.5 to auto.
// Use the routed upstream model, not the payload model, and run before thinking
// preparation so forced-mode cleanup cannot discard thinking or signed history.
// Delegated providers keep their own tool-choice contract. User payload rules
// must run afterwards and remain authoritative.
func NormalizeClaudeToolChoice(provider, model string, payload []byte) []byte {
if provider != "claude" {
return payload
}
model = strings.ToLower(thinking.ParseSuffix(strings.TrimSpace(model)).ModelName)
if !claude55Model.MatchString(model) {
return payload
}
switch gjson.GetBytes(payload, "tool_choice.type").String() {
case "any", "tool":
payload, _ = sjson.SetBytes(payload, "tool_choice.type", "auto")
payload, _ = sjson.DeleteBytes(payload, "tool_choice.name")
}
return payload
}