Adds gemini-4-argon to the Gemini, Vertex and OpenRouter/Nous catalogs and makes the native Gemini client handle Google's long decode (up to 1M output tokens). - Reasoning effort maps onto Gemini 4's thinkingLevel (low/medium/high). Argon always thinks, rejects "minimal" and rejects thinkingBudget alongside a level (400s, live): none -> low with thoughts hidden, minimal -> low, xhigh/max -> high. - Effort above high buys a long-decode budget on the native endpoints only: xhigh -> 262,144 output tokens, max/ultra -> 1,048,576 (the API caps it at the window minus the input). - generateContent (unary and streaming) follows finishReason CONTINUATION: the same request is resent with the continuationToken, hops are joined into one turn, one final finish chunk is emitted. Without this, a non-streaming Argon call that hit the 32,768-token per-request cap came back truncated and reported as finish=stop. - Usage is summed over hops for cost (matches google-genai and billing), while the first hop's prompt (initial_prompt_tokens) feeds compaction and the context meter, so a long-decode turn does not trigger an early compaction. - Vertex express keys can reach global-only models: a project-scoped .../projects/<p>/locations/global base is now native (only .../endpoints/openapi stays OpenAI-compatible). - 20 min read timeout on the native client and a 600 s stale floor for gemini-4, per Google's long-decode guidance. - Pricing at the introductory $2 / $10 / $0.10 rates.
48 lines
2.1 KiB
Python
48 lines
2.1 KiB
Python
"""Google Gemini (AI Studio) provider profile.
|
|
|
|
Reports api_mode="chat_completions" but runs on GeminiNativeClient; this
|
|
profile carries auth/endpoint metadata and the thinking_config translation hook.
|
|
"""
|
|
|
|
from typing import Any
|
|
|
|
from providers import register_provider
|
|
from providers.base import ProviderProfile
|
|
|
|
|
|
class GeminiProfile(ProviderProfile):
|
|
"""Gemini — translate reasoning_config to thinking_config in extra_body."""
|
|
|
|
def build_extra_body(self, *, session_id: str | None = None, **context: Any) -> dict[str, Any]:
|
|
"""Native: ``thinking_config``; OpenAI-compat /openai subpath:
|
|
``extra_body.google.thinking_config`` (snake_case)."""
|
|
from agent.transports.chat_completions import (
|
|
_build_gemini_thinking_config,
|
|
_is_gemini_openai_compat_base_url,
|
|
_snake_case_gemini_thinking_config,
|
|
)
|
|
|
|
raw = _build_gemini_thinking_config(context.get("model") or "", context.get("reasoning_config"))
|
|
if not raw:
|
|
return {}
|
|
base_url = context.get("base_url") or self.base_url
|
|
if self.name == "gemini" and _is_gemini_openai_compat_base_url(base_url):
|
|
thinking_config = _snake_case_gemini_thinking_config(raw)
|
|
return {"extra_body": {"google": {"thinking_config": thinking_config}}} if thinking_config else {}
|
|
from agent.gemini_long_decode import long_decode_max_output_tokens
|
|
from agent.gemini_native_adapter import is_native_gemini_base_url
|
|
|
|
# Long decode exists only on native generateContent (not /openai, not proxies).
|
|
budget = long_decode_max_output_tokens(context.get("model") or "", context.get("reasoning_config"))
|
|
return {"thinking_config": raw, **({"max_output_tokens": budget} if budget and is_native_gemini_base_url(base_url) else {})}
|
|
|
|
|
|
gemini = GeminiProfile(
|
|
name="gemini", aliases=("google", "google-gemini", "google-ai-studio"), api_mode="chat_completions",
|
|
env_vars=("GOOGLE_API_KEY", "GEMINI_API_KEY"),
|
|
base_url="https://generativelanguage.googleapis.com/v1beta", auth_type="api_key",
|
|
default_aux_model="gemini-3.6-flash",
|
|
)
|
|
|
|
register_provider(gemini)
|