diff --git a/internal/gateway/agy_agent_effort_test.go b/internal/gateway/agy_agent_effort_test.go index dfcaa80a5..526d49b8b 100644 --- a/internal/gateway/agy_agent_effort_test.go +++ b/internal/gateway/agy_agent_effort_test.go @@ -4,6 +4,8 @@ import ( "io" "net/http" "net/http/httptest" + "os" + "path/filepath" "strings" "sync" "testing" @@ -120,6 +122,35 @@ func TestAgyAgentEffort(t *testing.T) { } } +// A Gemini that lists a level above high (Gemini 4 Hydrogen's xhigh, as +// Google's model page and models.dev give it) is sent it, and max goes as +// its nearest, xhigh; a Gemini listing high at most (Carbon), or none, is +// still sent high (#6452). +func TestWithGeminiEffortAboveHigh(t *testing.T) { + t.Setenv("XDG_CACHE_HOME", t.TempDir()) + os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755) + if err := os.WriteFile(catalog.CachePath(), []byte(`{"google-vertex":{"models":{ + "gemini-4-hydrogen":{"id":"gemini-4-hydrogen","reasoning":true,"reasoning_options":[{"type":"effort","values":["low","medium","high","xhigh"]}]}, + "gemini-4-carbon":{"id":"gemini-4-carbon","reasoning":true,"reasoning_options":[{"type":"effort","values":["low","medium","high"]}]}}}}`), 0o644); err != nil { + t.Fatal(err) + } + catalog.Reset() + t.Cleanup(catalog.Reset) + for _, c := range []struct{ model, effort, want string }{ + {"gemini-4-hydrogen", "xhigh", "xhigh"}, + {"gemini-4-hydrogen", "max", "xhigh"}, + {"gemini-4-hydrogen", "high", "high"}, + {"gemini-4-carbon", "xhigh", "high"}, + {"gemini-4-carbon", "max", "high"}, + {"gemini-3.9-unlisted", "max", "high"}, + } { + out := withGeminiEffort([]byte(`{"contents":[]}`), c.model, c.effort) + if got := gjson.GetBytes(out, "generationConfig.thinkingConfig.thinkingLevel").String(); got != c.want { + t.Errorf("%s at %s: %s, want %s", c.model, c.effort, got, c.want) + } + } +} + // withGeminiEffort writes a Gemini request's thinkingConfig as the model // takes it, and a Gemini before 2.5, which doesn't think, is left alone. func TestWithGeminiEffort(t *testing.T) { diff --git a/internal/gateway/decide.go b/internal/gateway/decide.go index 4552896f7..ac72ece4b 100644 --- a/internal/gateway/decide.go +++ b/internal/gateway/decide.go @@ -25,6 +25,7 @@ import ( "sync" "time" + "github.com/yetone/magpie/internal/catalog" "github.com/yetone/magpie/internal/provider" "github.com/yetone/magpie/internal/usage" ) @@ -931,7 +932,8 @@ func withModelEffort(proto provider.Protocol, body []byte, model, effort string) // for effort, as model takes it, keeping includeThoughts as asked: a // Gemini 2.5 a budget in its range (vertexBudgets; it turns a level away), // a Gemini 3 a level of low..high (none takes xhigh or max, and it can't -// stop thinking, so none is low), a Gemini before 2.5 nothing, as it +// stop thinking, so none is low; above high only where the catalog lists +// it, Gemini 4 Hydrogen's xhigh), a Gemini before 2.5 nothing, as it // doesn't think. Another model (agy asking an OpenAI one on Gemini's API) // is asked the level itself, which the translation reads, and none as a // budget of 0. Antigravity CLI's own request sends thinkingBudget -1, or @@ -998,7 +1000,15 @@ func withGeminiEffort(body []byte, model, effort string) []byte { level = "low" } case at > slices.Index(effortRank, "high"): - level = "high" + // above high only where the model lists such a level: Gemini + // 4 Hydrogen takes xhigh, every Gemini before it high at most + fit := "high" + if ls := catalog.EffortsOf(m); len(ls) > 0 { + if l := catalog.NearestEffort(level, ls); slices.Index(effortRank, l) > slices.Index(effortRank, "high") { + fit = l + } + } + level = fit } tc["thinkingLevel"] = level case level == "none":