diff options
| author | Claude Sonnet 5 <noreply@anthropic.com> | 2026-07-03 22:33:22 +0000 |
|---|---|---|
| committer | Claude Sonnet 5 <noreply@anthropic.com> | 2026-07-03 22:33:22 +0000 |
| commit | 1f203a7ac0efad15ec3fc0a4c5b335ad7073a52f (patch) | |
| tree | 8047b9f63d0b1e80faf3e549b3ad21b9c1f71f1f /internal/retry/backoff.go | |
| parent | 767ddade57f189827fa956ff8081ca47404a4798 (diff) | |
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V1moSNCJRcP6kykA4tyUSs
Diffstat (limited to 'internal/retry/backoff.go')
| -rw-r--r-- | internal/retry/backoff.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/internal/retry/backoff.go b/internal/retry/backoff.go index a372b37..72b923c 100644 --- a/internal/retry/backoff.go +++ b/internal/retry/backoff.go @@ -22,7 +22,13 @@ const maxBackoffDelay = 5 * time.Minute // OpenAI-compatible error text (internal/llm); "rate_limit_error", // "overloaded_error", and "529" additionally match Anthropic's Messages API // error shape (HTTP 429 with error.type "rate_limit_error", or HTTP 529 -// with error.type "overloaded_error" — see internal/provider/anthropic). +// with error.type "overloaded_error" — see internal/provider/anthropic); +// "resource_exhausted" additionally matches Gemini's generateContent API +// error shape (HTTP 429 with error.status "RESOURCE_EXHAUSTED" — see +// internal/provider/google). The plain "429" check above already covers +// Gemini's HTTP status code, but the status string is matched too for +// parity with how the Anthropic error types are matched by name, not just +// by status code. func IsRateLimitError(err error) bool { if err == nil { return false @@ -34,7 +40,8 @@ func IsRateLimitError(err error) bool { strings.Contains(msg, "overloaded") || strings.Contains(msg, "rate_limit_error") || strings.Contains(msg, "overloaded_error") || - strings.Contains(msg, "529") + strings.Contains(msg, "529") || + strings.Contains(msg, "resource_exhausted") } // ParseRetryAfter extracts a Retry-After duration from an error message. |
