Gemini 4 Argon 開發人員指南

Gemini 4 Argon 是 Google 的前沿模型,擅長處理複雜的實際任務,包括程式設計、金融、法律、網路安全和科學等領域。這是 Gemini 4 系列的第一個模型。

本文將介紹 4 Argon 的新功能、強制執行的 API 慣例、遷移方式,以及快速入門指南。如要概略瞭解 Gemini 4 系列,請參閱「開始使用 Gemini 4」。

Gemini 4 Argon 有哪些新功能?

  • 統一輸入和輸出權杖限制:4 Argon 的權杖限制為 1,048,576 個,包括輸入和輸出權杖 (輸出包括思考、函式呼叫和最終回應)。
  • 解碼長度最多 1,048,576 個詞元:在 GenerateContent 上,生成長度可超過單一要求輸出限制 (65,536 個詞元,或非串流直接 HTTP 要求 32,768 個詞元),最多可達 1,048,576 個詞元 (扣除輸入詞元)。Google Gen AI SDK 會在要求中自動處理 continuation_token,您也可以在自己的接續迴圈中管理 continuation_token。
  • 思考等級:LOW、MEDIUM (gemini-4-argon 的預設值) 和 HIGH (gemini-4-argon-cyber-permissive 的預設值)。
  • 使用永久快取的隱含快取:隱含快取會自動套用至 6,144 個權杖以上的共用提示前置字元,且預設會啟用永久快取。不支援明確脈絡快取。
  • 代理式影片解讀:正式發布,預設為關閉。

快速入門導覽課程

開始之前,請先使用應用程式預設憑證 (ADC) 或 API 金鑰,在 Agent Platform 進行驗證。詳情請參閱「開始使用 Gemini Enterprise Agent Platform」。

在下列程式碼區塊中,將 PROJECT_ID 替換為您的專案 ID。

在 Agent Studio 試用

如要在 Agent Studio UI 中測試提示及設定 gemini-4-argon,請按照下列步驟操作:

  1. 在 Cloud de Confiance by S3NS 專案中開啟 Agent Studio,然後選取 Gemini 群組下方的 gemini-4-argon。
  2. 在「模型設定」中,設定下列項目:
    • 思考程度:選擇 Low、Medium (預設) 或 High。
    • 區域:選取 Global、us 或 eu。
    • 輸出詞元限制:設為 32,768 至 1,048,576 之間 (預設值為 1,048,576)。如果回覆超過單一要求限制,Agent Studio 會自動處理接續權杖。

安裝

升級至最新版 Google Gen AI SDK (Python 適用的 google-genai >= 2.30.1、JavaScript 適用的 @google/genai >= 2.29.1、Go 適用的 >= 1.74.0、Java 適用的 >= 1.77.0、.NET 適用的 >= 1.26.0 或 Kotlin 適用的 >= 1.6.0):

pip install --upgrade "google-genai>=2.30.1"

基本要求

Python (GenerateContent)

from google import genai
from google.genai import types

client = genai.Client(enterprise=True, project="PROJECT_ID", location="global")

response = client.models.generate_content(
    model="gemini-4-argon",
    contents="Design a lock-free ring buffer in Rust for multi-producer, single-consumer telemetry ingestion.",
    config=types.GenerateContentConfig(
        thinking_config=types.ThinkingConfig(
            thinking_level="MEDIUM",  # Default: "MEDIUM" (Valid: "LOW", "MEDIUM", "HIGH")
        ),
    ),
)
print(response.text)

Python (Interactions API)

from google import genai

client = genai.Client(enterprise=True, project="PROJECT_ID", location="global")

# Turn 1: Initial request (stored server-side by default)
turn1 = client.interactions.create(
    model="gemini-4-argon",
    input="Design a lock-free ring buffer in Rust for multi-producer, single-consumer telemetry ingestion.",
    store=True,
)
print(turn1.output_text)

# Turn 2: Continue the conversation using previous_interaction_id
turn2 = client.interactions.create(
    model="gemini-4-argon",
    input="Add a bounded backpressure policy and unit tests for concurrent writers.",
    previous_interaction_id=turn1.id,
)
print(turn2.output_text)

REST

curl -X POST \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json" \
"https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/global/publishers/google/models/gemini-4-argon:generateContent" \
-d '{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Provide an architectural review of this Go interface."
        }
      ]
    }
  ],
  "generationConfig": {
    "thinkingConfig": {
      "thinkingLevel": "MEDIUM"
    }
  }
}'

結構化輸出內容

from pydantic import BaseModel, Field
from google import genai
from google.genai import types

class ArchitectureReview(BaseModel):
    component: str = Field(description="Service or module name")
    bottlenecks: list[str] = Field(description="Throughput or latency bottlenecks")
    recommended_changes: list[str] = Field(description="Concrete refactoring steps")

client = genai.Client(enterprise=True, project="PROJECT_ID", location="global")

response = client.models.generate_content(
    model="gemini-4-argon",
    contents="Review a synchronous order-processing pipeline backed by a single primary database at 15,000 writes/sec.",
    config=types.GenerateContentConfig(
        response_mime_type="application/json",
        response_schema=ArchitectureReview,
        thinking_config=types.ThinkingConfig(thinking_level="HIGH"),
    ),
)
print(response.text)

長解碼

根據預設,單一 API 要求最多可生成 65,536 個輸出詞元 (非串流直接 HTTP 要求則為 32,768 個詞元),輸出內容包括思考、函式呼叫和最終回覆。如要在 GenerateContent (v1beta1) 上生成最多 1,048,576 個詞元的補全內容,請將 max_output_tokens 設為大於 65,536 (適用於串流要求) 或大於 32,768 (適用於非串流要求,最多 1,048,576)。當 finish_reason 為 CONTINUATION 時,Google Gen AI SDK 會自動在要求中追蹤 continuation_token (在 GenerateContentConfig 中設定 automatic_continuation=False 即可停用自動接續),您也可以在自訂迴圈中傳遞 continuation_token。

from google import genai
from google.genai import types

client = genai.Client(enterprise=True, project="PROJECT_ID", location="global")

# Automatic continuation is enabled by default in google-genai >= 2.30.1.
# Chunks across all continuation requests are yielded as a single stream.
for chunk in client.models.generate_content_stream(
    model="gemini-4-argon",
    contents="Write a complete formal proof of the prime number theorem.",
    config=types.GenerateContentConfig(
        max_output_tokens=256000,
        thinking_config=types.ThinkingConfig(thinking_level="HIGH"),
    ),
):
    print(chunk.text, end="")

# Set automatic_continuation=False to disable automatic continuation.
for chunk in client.models.generate_content_stream(
    model="gemini-4-argon",
    contents="Write a complete formal proof of the prime number theorem.",
    config=types.GenerateContentConfig(
        thinking_config=types.ThinkingConfig(thinking_level="HIGH"),
        automatic_continuation=False,
    ),
):
    print(chunk.text, end="")

REST (自訂接續迴圈)

# Request 1: Initial request with maxOutputTokens > 32,768
curl -s -X POST \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  -H "Content-Type: application/json" \
  "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/publishers/google/models/gemini-4-argon:generateContent" \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [{"text": "Write a complete formal proof of the prime number theorem."}]
    }],
    "generationConfig": {
      "maxOutputTokens": 131072,
      "thinkingConfig": {"thinkingLevel": "HIGH"}
    }
  }'

# Request 2: Resend the original request with top-level continuationToken
# from Request 1 (candidates[0].continuationToken)
curl -s -X POST \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  -H "Content-Type: application/json" \
  "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/publishers/google/models/gemini-4-argon:generateContent" \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [{"text": "Write a complete formal proof of the prime number theorem."}]
    }],
    "continuationToken": "CONTINUATION_TOKEN_FROM_REQUEST_1",
    "generationConfig": {
      "maxOutputTokens": 131072,
      "thinkingConfig": {"thinkingLevel": "HIGH"}
    }
  }'

強制性 API 規則和行為慣例

Gemini 4 Argon 會強制執行下列慣例:

  • 思考等級:4 Argon 支援三個 thinking_level 值 (thinking_budget 和 MINIMAL 會傳回 HTTP 400 驗證錯誤):

    思考程度 建議的工作負載
    HIGH (gemini-4-argon-cyber-permissive預設) 多檔案軟體工程、正式證明、架構設計和安全漏洞發掘。
    MEDIUM (gemini-4-argon的預設值) 一般程式設計、工具使用、文件問答和影片理解。
    LOW 分類、摘要和中繼資料擷取。
  • 統一的輸入和輸出詞元限制,以及單一要求輸出限制:

    • 1,048,576 是模型的整體詞元限制,包含輸入和輸出詞元 (輸出內容包括思考、函式呼叫和最終回覆)。max_output_tokens 控制生成內容的輸出詞元上限 (最多為 1,048,576 減去輸入詞元);如果將 max_output_tokens 設為大於 1,048,576,則會傳回 HTTP 400 錯誤。
    • 為避免產生過長的回覆,單一要求輸出內容的預設限制 (思考 + 模型回覆) 為 65,536 個權杖 (或非串流直接 HTTP 要求為 32,768 個權杖)。
  • 長解碼:

    • 長解碼的運作方式:長解碼會將生成作業分割成多個 GenerateContent 推論,最多可達 1,048,576 個詞元。舉例來說,如果工作需要 256,000 個輸出權杖 (包括想法、函式呼叫和最終回覆),第一個串流要求最多會產生 65,536 個輸出權杖,並發出 finish_reason=CONTINUATION,其中包含加密的 continuation_token,內有原始提示的雜湊值,以及該時間點的生成狀態。在後續要求中加入 continuation_token 和原始提示,即可從上次中斷的地方繼續生成,直到不再發出 continuation_token 且 finish_reason=STOP 為止。(在 Agent Studio 中,如果將輸出詞元限制設為大於 65,536,最多可達 1,048,576,系統會自動處理接續詞元)。
    • 何時使用長解碼:大多數要求會在單次要求限制內完成 (65,536 個詞元,或非串流 REST 呼叫的 32,768 個詞元)。只有在單一回應需要更多輸出內容時,才使用 long decode。長解碼會給予模型更多推論空間,但不會讓答案變長 (使用 thinking_level 控制推論深度)。
    工作負載 要使用長解碼嗎? 原因
    艱深的數學、科學、研究和正式證明 是 模型可使用超過 65,536 個詞元,探索及檢查推論過程。
    最困難的程式設計和代理工作 是 部分工作需要超過 65,536 個詞元的思考和程式碼,才能完成單一回覆。大多數程式設計和代理型工作會在 65,536 個權杖內完成。
    評估架構會在輸出內容達到上限時停止 是 如果模型將整個 65,536 或 32,768 個詞元的要求用於思考,長解碼功能可避免回覆遭到截斷。
    即時通訊、問與答、摘要、分類和擷取 否 這些工作在 32,768 個詞元內就能完成。
    要求固定長度,例如「寫一本 70 萬字的小說」 否 模型未遵循長度目標。
    代理在多個短對話輪中呼叫工具 否 每回合都很短。每回合的大量輸出內容會快速達到統一的 1,048,576 個權杖輸入和輸出限制。
    提示接近 1,048,576 個詞元的輸入限制 否 輸出內容最多只能使用 1,048,576 個詞元減去輸入內容。
    對延遲時間敏感的要求 否 長時間解碼可能需要幾分鐘。
    • 選擇繼續方式:選擇下列其中一種方式。大多數開發人員會使用選項 1。所有選項在 gemini-4-argon 和 gemini-4-argon-cyber-permissive 的詞元限制皆為 1,048,576 個。
    維度 選項 1:Google Gen AI SDK (建議) 選項 2:您自己的串流迴圈 (streamGenerateContent) 選項 2:自己的非串流迴圈 (generateContent)
    每個區段的開始時間 Google Gen AI SDK:Python (google-genai) 2.30.1、JavaScript (@google/genai) 2.29.1、Go 1.74.0、Java 1.77.0、.NET 1.26.0 和 Kotlin 1.6.0。你設定了 max_output_tokens。 程式碼,在每個檢查點或捨棄串流後 每 32,768 個權杖的程式碼
    每項要求的詞元數 每個區隔最多 65,536 個 每個串流 65,536 個,32,768 個詞元後每 5,000 個詞元設一個檢查點 每個要求 32,768 個
    每個要求的時間限制 20 分鐘 20 分鐘 20 分鐘
    儲存空間 無伺服器儲存空間 (符合 ZDR 規範) 無伺服器儲存空間 (符合 ZDR 規範) 無伺服器儲存空間 (符合 ZDR 規範)
    適用情境 大多數應用程式 串流 REST 呼叫端和自訂測試控管 簡單的評估工具
    • 導入規則和限制:
      • v1beta1 API 需求 (已知問題):GenerateContent (generateContent 和 streamGenerateContent) 的長解碼 (continuation_token) 僅支援 v1beta1 API (不支援 v1)。除非在 http_options 中指定 api_version='v1',否則 Google Gen AI SDK 預設會使用 v1beta1;如果是直接 REST 呼叫,請使用 v1beta1 端點路徑。Interactions API 不支援長解碼。
      • SDK 版本和 OpenAI 相容性:升級至最新版 Google Gen AI SDK (Python google-genai >= 2.30.1、JavaScript @google/genai >= 2.29.1、Go >= 1.74.0、Java >= 1.77.0、.NET >= 1.26.0 或 Kotlin >= 1.6.0)。舊版 SDK 和 OpenAI 相容層無法使用接續符記擷取長篇完成內容。如要自訂用戶端實作,請參閱 Python 和 JavaScript/TypeScript 的 Google Gen AI SDK 參考實作。
      • 使用 continuation_token 重新傳送原始要求:在自訂迴圈中,將 max_output_tokens 設為大於 65,536 (串流) 或 32,768 (一元),最高可達 1,048,576,並在每個後續要求中重新傳送原始 contents、system_instruction 和 tools,以及最新的 continuation_token (REST 中 GenerateContentRequest 的頂層欄位,或 Google Gen AI SDK 中的 GenerateContentConfig)。請勿將部分模型輸出內容附加到 contents,或傳送後續提示要求模型繼續。
      • 繼續處理僅思考要求:當 finish_reason 為 CONTINUATION 且 continuation_token 存在時,即使要求已用盡所有 32,768 或 65,536 個思考詞元 (parts: [{"text": ""}]),仍會繼續迴圈。如果 continuation_token 存在時 finish_reason 為 MAX_TOKENS,表示生成作業已達到要求的 max_output_tokens 上限,請在要求中提高 max_output_tokens。只有在 STOP 之後,才能將累積的部分合併為單一 model,用於多輪對話記錄。
      • 詞元計數、壓縮和 95% 的隱含快取折扣:
        • 在 Python Google Gen AI SDK (generate_content 和 generate_content_stream) 中,最終回覆或區塊的 usage_metadata 會累計所有後續要求中計費的權杖總數。由於每個接續要求都會重新預填先前的部分完成內容,做為輸入詞元,因此 prompt_token_count 會在接續要求中累積增加,請勿使用 prompt_token_count 觸發代理駕馭系統中的內容壓縮。請改為讀取 initial_prompt_token_count (在 GenerateContentResponse 或 usage_metadata 上),並等待 GenerateContent 完成 (沒有 continuation_token),再進行壓縮。
        • 在自訂 REST 迴圈中,usage_metadata 會在每個要求中累計;請將各個要求的最終 prompt_token_count、cached_content_token_count、candidates_token_count 和 thoughts_token_count 相加。
        • 每個接續要求都會重新預先填入提示和先前解碼的詞元,並在 15 到 20 分鐘的快取存留時間內連續執行要求時,自動享有 95% 的隱含脈絡快取折扣 (至少 6,144 個詞元)。
        • streamGenerateContent 和 generateContent 會在每項要求結束時傳回 usage_metadata (65,536 串流/32,768 一元),並在要求結束時計費。
  • 忽略取樣參數 (temperature、top_k、top_p):後端會忽略自訂值。使用 thinking_level 控制推論深度,並使用 response_schema 控制輸出格式。

  • 不支援的參數 (frequency_penalty、presence_penalty、candidate_count):這些參數會傳回 HTTP 400 錯誤。請從要求中移除這些項目。

  • 脈絡快取:系統不支援明確的脈絡快取。隱含快取 (預設啟用永久快取) 會自動套用至 6,144 個以上詞元的共用提示前置字串,因此請將靜態內容放在提示開頭。

  • 代理影片:上傳的影片預設為 media_processing="static"。 media_processing="agentic" 設為啟用代理影片處理。

  • 詞元計數和計費:模型處理的每個詞元都會計入並計費,包括思考詞元、內部工具系統指令,以及使用基準功能時的函式宣告。以 Google 搜尋強化事實基礎的費用仍為每項查詢。

  • 函式呼叫:

    • 對稱旋轉:每個 FunctionResponse 都必須符合前一個 FunctionCall 的 id、name 和順序。
    • 依序執行:偏好在多步驟工具迴圈中依序執行工具。
    • 工具前格式:使用 \n\n 分隔內嵌指令,並避免在工具呼叫前使用非結構化文字。如要在工具呼叫前記錄中繼狀態,請使用專屬的函式宣告:

      {
        "name": "update",
        "description": "Update working notes before tool execution",
        "parameters": {
          "type": "OBJECT",
          "properties": {
            "previous_step": {"type": "STRING"},
            "plan": {"type": "STRING"},
            "next_step": {"type": "STRING"}
          },
          "required": ["previous_step", "plan", "next_step"]
        }
      }
      
  • 對話序列驗證:

    • 歷史記錄酬載結尾不得為 model 角色對話。
    • 不支援預填模型輪次。

從 3.1 Pro 遷移至 4 Argon

以下行為與 gemini-3.1-pro-preview 不同:

  • 4 Argon 的輸入和輸出 (輸出包括思考、函式呼叫和最終回覆) 統一為 1,048,576 個權杖,而非分別設有輸入和輸出限制。單一要求的輸出內容上限為 65,536 個詞元 (非串流直接 HTTP 要求則為 32,768 個詞元),在 GenerateContent 上使用長解碼,最多可擴充至 1,048,576 個詞元 (Google Gen AI SDK 會自動處理,或在自訂迴圈中使用 continuation_token)。
  • thinking_budget 會傳回 HTTP 400 錯誤,而不是對應至思考層級。MINIMAL 也會傳回錯誤。
  • 不支援明確的脈絡快取。
  • 模型處理的每個權杖都會計費,包括使用基礎功能時的內部工具系統指令和函式宣告。

如要並排比較,請參閱「從 Gemini 3.1 Pro 遷移」。

 client = genai.Client(
     enterprise=True,
     project="PROJECT_ID",
     location="global", # Supports "global", "us", and "eu"
 )

 response = client.models.generate_content(
-    model="gemini-3.1-pro-preview",
+    model="gemini-4-argon",
     contents=prompt,
     config=types.GenerateContentConfig(
-        temperature=0.0,
-        cached_content="projects/.../cachedContents/...", # Explicit caching unsupported
         thinking_config=types.ThinkingConfig(
-            thinking_budget=16384, # Returns HTTP 400 instead of mapping silently
-            thinking_level="MINIMAL", # MINIMAL unsupported on Gemini 4 Argon
+            thinking_level="MEDIUM", # Valid: "LOW", "MEDIUM" (default), "HIGH"
         ),
     ),
 )

如要從 gemini-3.1-pro-preview 遷移,請按照下列步驟操作:

  1. 將模型 ID 更新為 gemini-4-argon (或 gemini-4-argon-cyber-permissive,適用於 Fairwind 核准的網路安全工作負載)。
  2. 升級至最新版 Google Gen AI SDK,並考量統一的輸入和輸出權杖限制:升級至 google-genai >= 2.30.1 (Python)、@google/genai >= 2.29.1 (JavaScript) 或同等的最新版 Google Gen AI SDK。輸入和輸出權杖 (包括思考和函式呼叫) 共用 1,048,576 個權杖的統一限制。如果 GenerateContent 的輸出內容超過 65,536 個詞元 (最多 1,048,576 個詞元),請將 max_output_tokens 設為大於 65,536,這樣 Google Gen AI SDK 就會自動繼續處理要求 (或在自己的 REST 迴圈中處理 continuation_token)。
  3. 替換推論預算參數:將 thinking_budget 和 MINIMAL 替換為 thinking_level,並設為 LOW、MEDIUM (gemini-4-argon 的預設值) 或 HIGH (gemini-4-argon-cyber-permissive 的預設值)。
  4. 移除明確快取,並預先載入靜態提示內容 (6,144 個以上詞元),以便自動進行隱含快取。
  5. 移除無效或不支援的參數:
    • 移除 temperature、top_p 和 top_k,系統會忽略這些項目。
    • 移除 candidate_count、frequency_penalty 和 presence_penalty。
    • 從對話記錄中移除所有預填模型輪次。

開發人員摘要檢查清單

已知問題

  • GenerateContent 上的長解碼需要 v1beta1:GenerateContent API (generateContent 和 streamGenerateContent) 僅支援 v1beta1 API (而非 v1) 上的長解碼 (continuation_token)。除非在 http_options 中設定 api_version='v1',否則 Google Gen AI SDK 預設會使用 v1beta1;如要直接進行 REST 呼叫,請使用 v1beta1 端點路徑。

其他資源