From 1f203a7ac0efad15ec3fc0a4c5b335ad7073a52f Mon Sep 17 00:00:00 2001 From: Claude Sonnet 5 Date: Fri, 3 Jul 2026 22:33:22 +0000 Subject: feat(provider): add native Google Gemini API adapter (Phase 4) Adds internal/provider/google, the second native cloud adapter (following internal/provider/anthropic's pattern) on top of Phase 1's provider-neutral tool-use loop, wired to a Docker-sandboxed NativeRunner under agent.type: "google" -- a separate execution path and budget bucket from the existing CLI-subprocess "gemini" ContainerRunner, which is untouched. Wire-format research (the highest-risk part of this adapter): Gemini's multi-turn function-calling shape was resolved by cross-referencing the REST API reference's own generateContent example against the go-genai SDK's struct tags on GitHub -- both agree on functionCall/functionResponse parts keyed by "name" (with an optional "id" for round-tripping ToolCall.ID), with the response fed back inside a "user"-role Content (Gemini has no tool/function role, mirroring Anthropic's lack of one). A separate fetched source (the function-calling guide page) was deliberately discarded as a reference for this shape -- it documents a different, newer "Interactions API" whose call_id/type:"function_result" structure doesn't fit the contents/parts/candidates shape used everywhere else. - internal/provider/google: request/response translation, systemInstruction handling, role mapping (assistant->model, tool-results->user role), per-model-prefix pricing table (2.5 Pro/Flash/Flash-Lite, 2.0, 1.5 tiers) - internal/retry: IsRateLimitError additively extended for RESOURCE_EXHAUSTED - internal/config: RunnersConfig.Google/GoogleEnabled() - internal/cli/serve.go, run.go: runners["google"] construction mirroring the Anthropic wiring exactly (Docker sandbox default) - docs/api-keys-setup.md: Google marked wired-up, budget-bucket/disable/ verify guidance added matching the Anthropic section go build/vet/test -race all pass. No live Gemini API key available in this environment; verified via fake-httptest-server adapter tests (plain text, tool-use round-trip, multi-turn tool-result, rate-limit error matching) plus a Pool/NativeRunner routing test. Live E2E is a follow-up once a key is configured, same as Phase 2's Anthropic adapter. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01V1moSNCJRcP6kykA4tyUSs --- internal/config/config.go | 9 +++++++++ internal/config/config_test.go | 27 ++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) (limited to 'internal/config') diff --git a/internal/config/config.go b/internal/config/config.go index afbd12e..b9454d1 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -64,6 +64,14 @@ type RunnersConfig struct { // the same Anthropic account. Also requires [providers.anthropic].api_key // to be set; Anthropic = true with no configured key has no effect. Anthropic *bool `toml:"anthropic"` + // Google gates the native provider.Provider-backed NativeRunner + // registered under agent type "google" (internal/provider/google). It is + // distinct from Gemini, which gates the Docker/CLI-subprocess + // ContainerRunner for agent type "gemini" — the two are separate + // execution paths (and separate budget buckets), same reasoning as + // Anthropic vs. Claude above. Also requires [providers.google].api_key to + // be set; Google = true with no configured key has no effect. + Google *bool `toml:"google"` } func (r RunnersConfig) ClaudeEnabled() bool { return r.Claude == nil || *r.Claude } @@ -71,6 +79,7 @@ func (r RunnersConfig) GeminiEnabled() bool { return r.Gemini == nil || *r.Ge func (r RunnersConfig) LocalEnabled() bool { return r.Local == nil || *r.Local } func (r RunnersConfig) ContainerEnabled() bool { return r.Container == nil || *r.Container } func (r RunnersConfig) AnthropicEnabled() bool { return r.Anthropic == nil || *r.Anthropic } +func (r RunnersConfig) GoogleEnabled() bool { return r.Google == nil || *r.Google } // ProviderConfig configures a native (or OpenAI-compatible) LLM provider // backend for the multi-provider harness — see docs/api-keys-setup.md. Phase diff --git a/internal/config/config_test.go b/internal/config/config_test.go index f71b9cc..4167ff7 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -71,11 +71,14 @@ func TestRunnersConfig_DefaultsAllEnabled(t *testing.T) { if !r.AnthropicEnabled() { t.Error("anthropic should be enabled by default (nil)") } + if !r.GoogleEnabled() { + t.Error("google should be enabled by default (nil)") + } } func TestRunnersConfig_ExplicitFalseDisables(t *testing.T) { f := false - r := RunnersConfig{Claude: &f, Gemini: &f, Local: &f, Container: &f, Anthropic: &f} + r := RunnersConfig{Claude: &f, Gemini: &f, Local: &f, Container: &f, Anthropic: &f, Google: &f} if r.ClaudeEnabled() { t.Error("explicit false should disable claude") } @@ -91,12 +94,15 @@ func TestRunnersConfig_ExplicitFalseDisables(t *testing.T) { if r.AnthropicEnabled() { t.Error("explicit false should disable anthropic") } + if r.GoogleEnabled() { + t.Error("explicit false should disable google") + } } func TestRunnersConfig_ExplicitTrueEnables(t *testing.T) { tr := true - r := RunnersConfig{Claude: &tr, Gemini: &tr, Local: &tr, Container: &tr, Anthropic: &tr} - if !r.ClaudeEnabled() || !r.GeminiEnabled() || !r.LocalEnabled() || !r.ContainerEnabled() || !r.AnthropicEnabled() { + r := RunnersConfig{Claude: &tr, Gemini: &tr, Local: &tr, Container: &tr, Anthropic: &tr, Google: &tr} + if !r.ClaudeEnabled() || !r.GeminiEnabled() || !r.LocalEnabled() || !r.ContainerEnabled() || !r.AnthropicEnabled() || !r.GoogleEnabled() { t.Error("explicit true should keep all runners enabled") } } @@ -185,6 +191,10 @@ timeout_seconds = 30 [providers.anthropic] api_key = "sk-ant-xyz" default_model = "claude-sonnet-4-5" + +[providers.google] +api_key = "AIza-abc" +default_model = "gemini-2.5-flash" ` if err := os.WriteFile(path, []byte(toml), 0600); err != nil { t.Fatal(err) @@ -195,8 +205,8 @@ default_model = "claude-sonnet-4-5" if err != nil { t.Fatalf("unexpected error: %v", err) } - if len(cfg.Providers) != 2 { - t.Fatalf("expected 2 providers, got %d: %+v", len(cfg.Providers), cfg.Providers) + if len(cfg.Providers) != 3 { + t.Fatalf("expected 3 providers, got %d: %+v", len(cfg.Providers), cfg.Providers) } groq, ok := cfg.Providers["groq"] if !ok { @@ -213,4 +223,11 @@ default_model = "claude-sonnet-4-5" if anthropic.Endpoint != "" || anthropic.APIKey != "sk-ant-xyz" || anthropic.DefaultModel != "claude-sonnet-4-5" { t.Errorf("anthropic provider config: %+v", anthropic) } + google, ok := cfg.Providers["google"] + if !ok { + t.Fatal("expected [providers.google] table") + } + if google.Endpoint != "" || google.APIKey != "AIza-abc" || google.DefaultModel != "gemini-2.5-flash" { + t.Errorf("google provider config: %+v", google) + } } -- cgit v1.2.3