Gemini 3.5 Flash 最新消息

最新模型 其他模型

Gemini 3.5 Flash (gemini-3.5-flash) 是 Gemini 3 系列中已淘汰的早期 Flash 模型。傳送至 gemini-3.5-flash 的要求會自動轉送至 Gemini 3.6 Flash。如要瞭解最新 Flash 模型,請參閱 Gemini 3.8 Flash。

本指南僅供參考,記錄了 Gemini 3.x API 的基本變更和參數建議。

款式簡介

模型 模型 ID 狀態
Gemini 3.5 Flash gemini-3.5-flash 已淘汰 (會自動轉送至 gemini-3.6-flash)。

Gemini 3.5 Flash 支援 100 萬個詞元的脈絡窗口、最多 6.5 萬個輸出詞元、思考功能,以及與 Gemini 3 Flash 相同的工具和平台功能,包括電腦使用 (預先發布版)。

如要查看完整規格,請參閱「型號總覽」。

快速入門導覽課程

本指南中的所有範例都使用 Interactions API。GenerateContent API 也支援這項功能,適用相同的設定選項和建議。

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.5-flash",
    input="Explain how parallel agentic execution works in three sentences."
)
print(interaction.output_text)

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

async function main() {
  const interaction = await client.interactions.create({
    model: "gemini-3.5-flash",
    input: "Explain how parallel agentic execution works in three sentences.",
  });
  console.log(interaction.output_text);
}

main();

Java

import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;

Client client = new Client();

CreateModelInteraction params =
    CreateModelInteraction.builder()
        .model(Model.of("gemini-3.5-flash"))
        .input(
            InteractionsInput.of(
                "Explain how parallel agentic execution works in three sentences."))
        .build();

Interaction interaction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

System.out.println(interaction.outputText().orElse(""));

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.5-flash"),
            Input: interactions.NewInteractionsInput("Explain how parallel agentic execution works in three sentences."),
        }),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Interaction.OutputText != nil {
        fmt.Println(*res.Interaction.OutputText)
    }
}

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gemini-3.5-flash",
    "input": "Explain how parallel agentic execution works in three sentences."
  }'

最新資訊

  • 持續效能:大規模最佳化代理式和程式設計工作。
  • 代理執行:大規模部署子代理、解決問題,以及快速代理迴圈。
  • 程式設計:反覆進行程式設計、快速探索及製作原型,測試替代路徑並動態探索解決方案。
  • 長程:多步驟工作流程和大規模工具使用。
  • 思維保留:模型會自動在多輪對話中保留中間推理步驟。不需要變更 API。
  • 新的預設努力程度:預設思考努力程度已從 high 變更為 medium。詳情請參閱「新的預設努力程度」。
  • low 推論能力更強: low 顯著提升,能以更少步驟處理程式碼和代理任務,在更短時間內以更低成本提供優異品質。

選擇合適的 Flash 模型

由於 gemini-3.5-flash 已淘汰,且會自動轉送至 gemini-3.6-flash,建議您改用下列其中一個有效模型:

行為異動

新的預設努力程度:medium

預設思考深度現為 medium,而非 Gemini 3 Flash 預先發布版的 high。medium 在各種工作上都能取得極佳成果,而且速度更快、成本效益更高。遇到複雜問題時,high 會鼓勵模型深入思考。

努力程度 使用時機
minimal 回應速度經過最佳化調整。類似聊天的用途、快速的事實性答案、較簡單的工具呼叫。
low 需要較低延遲時間和較少步驟的程式碼和代理工作。也適合用於需要思考的分析和寫作工作。
medium (預設) 最適合大多數工作的品質。建議用於複雜程式碼和代理式用途。
high 充分發揮模型的思考和工具使用能力。最適合處理複雜的推論、困難的數學問題,以及最難的程式碼或代理程式工作。允許延伸思考和函式呼叫。

如要覆寫預設值,請在設定中設定 thinking_level:

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.5-flash",
    input="Prove that the square root of 2 is irrational.",
    generation_config={"thinking_level": "high"},
)
print(interaction.output_text)

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

async function main() {
  const interaction = await client.interactions.create({
    model: "gemini-3.5-flash",
    input: "Prove that the square root of 2 is irrational.",
    generationConfig: { thinkingLevel: "high" },
  });
  console.log(interaction.output_text);
}

main();

Java

import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.GenerationConfig;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ThinkingLevel;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;

Client client = new Client();

CreateModelInteraction params =
    CreateModelInteraction.builder()
        .model(Model.of("gemini-3.5-flash"))
        .input(InteractionsInput.of("Prove that the square root of 2 is irrational."))
        .generationConfig(GenerationConfig.builder().thinkingLevel(ThinkingLevel.HIGH).build())
        .build();

Interaction interaction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

System.out.println(interaction.outputText().orElse(""));

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.5-flash"),
            Input: interactions.NewInteractionsInput("Prove that the square root of 2 is irrational."),
            GenerationConfig: &interactions.GenerationConfig{
                ThinkingLevel: interactions.ThinkingLevelHigh.ToPointer(),
            },
        }),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Interaction.OutputText != nil {
        fmt.Println(*res.Interaction.OutputText)
    }
}

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gemini-3.5-flash",
    "input": "Prove that the square root of 2 is irrational.",
    "generation_config": {"thinking_level": "high"}
  }'

下表列出各模型支援的思考等級:

思考程度 Gemini 3.5 Flash Gemini 3.1 Pro Gemini 3.1 Flash-Lite Gemini 3 Flash 說明
minimal 支援 不支援 支援 (預設) 支援 對於大多數查詢,這項設定與「不思考」相同。請注意,minimal 不保證會關閉思考功能,模型可能會針對複雜工作進行極少量的推論。
low 支援 支援 支援 支援 盡可能降低延遲時間和成本。
medium 支援 (預設) 支援 支援 支援 思考方式較為均衡,適合處理多數工作。
high 支援 (動態) 支援 (預設、動態) 支援 (動態) 支援 (預設、動態) 盡可能深入推論。

保留想法

模型會自動在多輪對話中保留中間推論。如果對話記錄中包含推論脈絡,系統會沿用這些資訊,進而提升複雜多步驟工作的效能,例如反覆偵錯和程式碼重構。不需變更 API:

  • Interactions API:系統會自動保留思考過程。行為沒有改變。
  • GenerateContent API:從 Gemini 3.5 Flash 開始,如果對話記錄中包含思維簽章,模型就會在所有先前的對話輪次中,使用推論脈絡。如要啟用這項功能,請在 contents 中傳遞完整且未經修改的對話記錄 (包括想法簽章)。SDK 會自動處理這項作業。

Gemini 3.x 中的參數更新和最佳做法

以下適用於所有 Gemini 3.x 模型,包括 Gemini 3.5 Flash。

  • temperature、top_p、top_k:強烈建議不要變更預設值。Gemini 3 的推論能力已針對預設設定完成最佳化。
  • 使用 thinking_level,而不要使用 thinking_budget。
  • 函式呼叫回應比對:id、name 和回應數量必須與先前的呼叫相符。
  • 多模態函式回覆:在函式回覆中加入多模態內容,而非在函式回覆外。
  • 函式回應中的內嵌指令:附加至函式回應文字,而非做為獨立部分。
  • 減少不必要的工具呼叫:降低思考等級,或嘗試調整系統指令,減少 Agentic Workflows 中的工具呼叫。

請參閱以下各節,瞭解如何更新程式碼。

取樣參數 (不再建議使用)

temperature、top_p 和 top_k 不再適用於所有 Gemini 3.x 模型。Gemini 3 的推論功能已針對預設設定進行最佳化。從所有要求中移除這些參數。

# ⚠️ Remove these parameters (not recommended)
generation_config = {
    "temperature": 0.7,
    "top_p": 0.9,
    "top_k": 40,
}

為確保確定性,建議您根據特定用途,定義具有明確規則的系統指令。

thinking_budget (不再建議使用)

我們不再建議在所有 Gemini 3.x 模型中使用原始數字 thinking_budget 參數。請改用 thinking_level 字串列舉。

# ⚠️ Before (not recommended)
generation_config = {
    "thinking": {"thinking_budget": 7500},
}

# ✅ After
generation_config = {
    "thinking": {"thinking_level": "medium"},
}

可用值:minimal、low、medium (預設值) 和 high。

函式呼叫:嚴格比對回覆

如果函式回應不相符,Interactions API 會發生錯誤。GenerateContent API 尚未發生錯誤,但回應不相符會導致模型在多數情況下傳回空白回應,並顯示 finish_reason: STOP。請務必遵循下列慣例:

規定 詳細資料
納入id 每個 FunctionResponse 都必須包含對應 FunctionCall 的 id
第 name 場 回應中的 name 必須與呼叫中的 name 相符
相符項目數 針對收到的每個 FunctionCall,傳回正好一個 FunctionResponse

Python

# ✅ Include matching call_id and name in the function_result
final_interaction = client.interactions.create(
    model="gemini-3.5-flash",
    previous_interaction_id=interaction.id,
    tools=[my_tool],
    input=[{
        "type": "function_result",
        "name": fc_step.name,
        "call_id": fc_step.id,
        "result": [{"type": "text", "text": json.dumps(result)}],
    }],
)

JavaScript

// ✅ Include matching call_id and name in the function_result
const finalInteraction = await client.interactions.create({
  model: "gemini-3.5-flash",
  previousInteractionId: interaction.id,
  tools: [myTool],
  input: [{
    type: "function_result",
    name: fcStep.name,
    call_id: fcStep.id,
    result: [{ type: "text", text: JSON.stringify(result) }],
  }],
});

Java

import java.util.Arrays;
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Function;
import com.google.genai.gaos.models.interactions.FunctionResultStep;
import com.google.genai.gaos.models.interactions.FunctionResultStepResultUnion;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.TextContent;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;

Client client = new Client();

// Assumes interactionId, callId, functionName, myTool, and resultJson from previous step
String interactionId = "interaction-id-123";
String callId = "call-id-123";
String functionName = "get_weather";
Function myTool = Function.builder().name(functionName).build();
String resultJson = "{\"temperature\": \"72F\"}";

// ✅ Include matching callId and name in the FunctionResultStep
FunctionResultStep functionResult =
    FunctionResultStep.builder()
        .name(functionName)
        .callId(callId)
        .result(
            FunctionResultStepResultUnion.of(
                Arrays.asList(TextContent.builder().text(resultJson).build())))
        .build();

CreateModelInteraction params =
    CreateModelInteraction.builder()
        .model(Model.of("gemini-3.5-flash"))
        .previousInteractionId(interactionId)
        .tools(Arrays.asList(myTool))
        .input(InteractionsInput.ofStep(Arrays.asList(functionResult)))
        .build();

Interaction finalInteraction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

Go

package main

import (
    "context"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    // Assumes interactionID, callID, functionName, myTool, and resultJSON from previous step
    interactionID := "interaction-id-123"
    callID := "call-id-123"
    functionName := "get_weather"
    myTool := interactions.NewTool(interactions.Function{Name: genai.Ptr(functionName)})
    resultJSON := `{"temperature": "72F"}`

    // ✅ Include matching CallID and Name in the FunctionResultStep
    functionResult := interactions.NewStep(interactions.FunctionResultStep{
        Name:   genai.Ptr(functionName),
        CallID: callID,
        Result: interactions.NewFunctionResultStepResultUnion([]interactions.FunctionResultSubcontent{
            interactions.NewFunctionResultSubcontent(interactions.TextContent{Text: resultJSON}),
        }),
    })

    finalRes, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model:                 interactions.Model("gemini-3.5-flash"),
            PreviousInteractionID: genai.Ptr(interactionID),
            Tools:                 []interactions.Tool{myTool},
            Input:                 interactions.NewInteractionsInput([]interactions.Step{functionResult}),
        }),
    })
    if err != nil {
        log.Fatal(err)
    }
    _ = finalRes
}

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gemini-3.5-flash",
    "previous_interaction_id": "<INTERACTION_ID>",
    "tools": [...],
    "input": [{
      "type": "function_result",
      "name": "my_function",
      "call_id": "<CALL_ID>",
      "result": [{"type": "text", "text": "..."}]
    }]
  }'

多模態函式回覆

我們經常看到用戶端在函式回應之外提供圖片。這可能導致模型行為不符合預期 (例如洩漏思考過程),並降低輸出內容品質。請改為按照多模態函式回覆 API 文件中的建議操作,並在傳送給模型的回覆部分中加入多模態內容。模型可以在下一個回合處理這類多模態內容,進而生成更實用的回覆。

Python

# ✅ Include multimodal content in the function response
final_interaction = client.interactions.create(
    model="gemini-3.5-flash",
    previous_interaction_id=interaction.id,
    input=[
        {
            "type": "function_result",
            "name": tool_call.name,
            "call_id": tool_call.id,
            "result": [
                {"type": "text", "text": "instrument.jpg"},
                {
                    "type": "image",
                    "mime_type": "image/jpeg",
                    "data": base64_image_data,
                },
            ],
        }
    ],
)

JavaScript

// ✅ Include multimodal content in the function response
const finalInteraction = await client.interactions.create({
  model: "gemini-3.5-flash",
  previousInteractionId: interaction.id,
  input: [{
    type: "function_result",
    name: toolCall.name,
    call_id: toolCall.id,
    result: [
      { type: "text", text: "instrument.jpg" },
      {
        type: "image",
        mime_type: "image/jpeg",
        data: base64ImageData,
      },
    ],
  }],
});

Java

import java.util.Arrays;
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.FunctionResultStep;
import com.google.genai.gaos.models.interactions.FunctionResultStepResultUnion;
import com.google.genai.gaos.models.interactions.ImageContent;
import com.google.genai.gaos.models.interactions.ImageContentMimeType;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.TextContent;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;

Client client = new Client();

// Assumes interactionId, callId, functionName, and base64ImageData from previous step
String interactionId = "interaction-id-123";
String callId = "call-id-123";
String functionName = "get_instrument_image";
String base64ImageData = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=";

// ✅ Include multimodal content in the function response
FunctionResultStep functionResult =
    FunctionResultStep.builder()
        .name(functionName)
        .callId(callId)
        .result(
            FunctionResultStepResultUnion.of(
                Arrays.asList(
                    TextContent.builder().text("instrument.jpg").build(),
                    ImageContent.builder()
                        .mimeType(ImageContentMimeType.IMAGE_JPEG)
                        .data(base64ImageData)
                        .build())))
        .build();

CreateModelInteraction params =
    CreateModelInteraction.builder()
        .model(Model.of("gemini-3.5-flash"))
        .previousInteractionId(interactionId)
        .input(InteractionsInput.ofStep(Arrays.asList(functionResult)))
        .build();

Interaction finalInteraction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

Go

package main

import (
    "context"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    // Assumes interactionID, callID, functionName, and base64ImageData from previous step
    interactionID := "interaction-id-123"
    callID := "call-id-123"
    functionName := "get_instrument_image"
    base64ImageData := "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="

    // ✅ Include multimodal content in the function response
    functionResult := interactions.NewStep(interactions.FunctionResultStep{
        Name:   genai.Ptr(functionName),
        CallID: callID,
        Result: interactions.NewFunctionResultStepResultUnion([]interactions.FunctionResultSubcontent{
            interactions.NewFunctionResultSubcontent(interactions.TextContent{
                Text: "instrument.jpg",
            }),
            interactions.NewFunctionResultSubcontent(interactions.ImageContent{
                MimeType: interactions.ImageContentMimeType("image/jpeg").ToPointer(),
                Data:     genai.Ptr(base64ImageData),
            }),
        }),
    })

    finalRes, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model:                 interactions.Model("gemini-3.5-flash"),
            PreviousInteractionID: genai.Ptr(interactionID),
            Input:                 interactions.NewInteractionsInput([]interactions.Step{functionResult}),
        }),
    })
    if err != nil {
        log.Fatal(err)
    }
    _ = finalRes
}

函式回應中的內嵌指令

我們經常看到客戶在函式回應中提供額外指令,做為後續的 Parts。這可能導致模型出現非預期行為 (例如思考洩漏),並降低輸出內容品質。請改為在函式回覆文字結尾附加任何額外指示,並以兩個換行符號分隔。

Python

# ✅ Append inline instructions to the end of the function response separated by two newlines
result_text = f"{json.dumps(result)}\n\n<your inline instructions>"

final_interaction = client.interactions.create(
    model="gemini-3.5-flash",
    previous_interaction_id=interaction.id,
    tools=[my_tool],
    input=[{
        "type": "function_result",
        "name": fc_step.name,
        "call_id": fc_step.id,
        "result": [{"type": "text", "text": result_text}],
    }],
)

JavaScript

// ✅ Append inline instructions to the end of the function response separated by two newlines
const resultText = `${JSON.stringify(result)}\n\n<your inline instructions>`;

const finalInteraction = await client.interactions.create({
  model: "gemini-3.5-flash",
  previousInteractionId: interaction.id,
  tools: [myTool],
  input: [{
    type: "function_result",
    name: fcStep.name,
    call_id: fcStep.id,
    result: [{ type: "text", text: resultText }],
  }],
});

Java

import java.util.Arrays;
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Function;
import com.google.genai.gaos.models.interactions.FunctionResultStep;
import com.google.genai.gaos.models.interactions.FunctionResultStepResultUnion;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.TextContent;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;

Client client = new Client();

// Assumes interactionId, callId, functionName, myTool, and resultJson from previous step
String interactionId = "interaction-id-123";
String callId = "call-id-123";
String functionName = "get_weather";
Function myTool = Function.builder().name(functionName).build();
String resultJson = "{\"temperature\": \"72F\"}";

// ✅ Append inline instructions to the end of the function response separated by two newlines
String resultText = resultJson + "\n\n<your inline instructions>";

FunctionResultStep functionResult =
    FunctionResultStep.builder()
        .name(functionName)
        .callId(callId)
        .result(
            FunctionResultStepResultUnion.of(
                Arrays.asList(TextContent.builder().text(resultText).build())))
        .build();

CreateModelInteraction params =
    CreateModelInteraction.builder()
        .model(Model.of("gemini-3.5-flash"))
        .previousInteractionId(interactionId)
        .tools(Arrays.asList(myTool))
        .input(InteractionsInput.ofStep(Arrays.asList(functionResult)))
        .build();

Interaction finalInteraction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

Go

package main

import (
    "context"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    // Assumes interactionID, callID, functionName, myTool, and resultJSON from previous step
    interactionID := "interaction-id-123"
    callID := "call-id-123"
    functionName := "get_weather"
    myTool := interactions.NewTool(interactions.Function{Name: genai.Ptr(functionName)})
    resultJSON := `{"temperature": "72F"}`

    // ✅ Append inline instructions to the end of the function response separated by two newlines
    resultText := resultJSON + "\n\n<your inline instructions>"

    functionResult := interactions.NewStep(interactions.FunctionResultStep{
        Name:   genai.Ptr(functionName),
        CallID: callID,
        Result: interactions.NewFunctionResultStepResultUnion([]interactions.FunctionResultSubcontent{
            interactions.NewFunctionResultSubcontent(interactions.TextContent{Text: resultText}),
        }),
    })

    finalRes, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model:                 interactions.Model("gemini-3.5-flash"),
            PreviousInteractionID: genai.Ptr(interactionID),
            Tools:                 []interactions.Tool{myTool},
            Input:                 interactions.NewInteractionsInput([]interactions.Step{functionResult}),
        }),
    })
    if err != nil {
        log.Fatal(err)
    }
    _ = finalRes
}

減少不必要的工具呼叫

如果工具呼叫次數過多,可以採取以下兩種方法盡量減少:

  1. 首先,請降低思考等級 (medium、low 或 minimal):思考等級越高,模型就會使用越多工具來探索及驗證,因此降低等級可減少工具呼叫。

  2. 新增系統指令:如果調整思考等級後,模型仍過度使用工具,請考慮使用提示詞限制工具用量。例如:

    You have a limited action budget of <n> tool calls. Use them efficiently.
    

Gemini 3 系列功能

Gemini 3.5 Flash 繼承 Gemini 3 系列的所有功能,包括 Computer Use。Gemini 3 推出後沿用至今的功能:

  • 思考:在 API 呼叫之間保留加密的推論脈絡。在 Interactions API 中自動執行;在 GenerateContent 中隱含執行。
  • 搭配工具使用結構化輸出內容:結合 JSON 模式與內建工具 (搜尋、網址背景資訊、執行程式碼、呼叫函式)。
  • 多模態函式回覆:在函式呼叫結果中傳回圖片、音訊和其他媒體。
  • 執行程式碼並處理圖片:執行程式碼來處理及生成圖片。
  • 合併使用工具:在同一項要求中,使用內建工具和自訂函式呼叫。
  • 媒體解析度: 精細控管圖片、影片和 PDF 輸入內容的權杖分配。 Gemini 3 模型支援混合保真度提示的每個內容項目解析度設定 (low、 medium、high、ultra_high)。
  • 想法簽章: 模型內部推論過程的已加密表示法。在無狀態模式中進行多輪函式呼叫時,這是必要參數;由 Interactions API 和官方 SDK 自動管理。

提示最佳做法

Gemini 3.x 模型是推論模型,因此提示方式會有所不同。

  • 精確的指示:保持精簡。Gemini 3.x 最適合直接且清楚的指令。如果使用專為舊模型設計的冗長或複雜提示工程技術,可能會導致模型過度分析。
  • 輸出內容詳細程度:根據預設,Gemini 3 和 3.1 較不冗長,偏好直接提供有效率的答案。如果您的用途需要對話語氣,請在提示中明確引導模型 (例如「請以友善、健談的助理身分說明這項內容」)。
  • 脈絡管理:處理大型資料集 (例如整本書、程式碼集或長影片) 時,請將具體指示或問題放在提示結尾,也就是資料脈絡之後。在問題開頭使用「根據上述資訊...」等詞組,引導模型進行推論。

如要進一步瞭解提示設計策略,請參閱提示工程指南。

限制

  • Gemini 3.x 不支援影像分割。如要執行區隔工作負載,請繼續使用 Gemini 2.5 Flash,並關閉思考功能。

常見問題

  1. Gemini 3.5 Flash 的知識截點為何?Gemini 3.5 Flash 的知識截點為 2025 年 1 月。如需最新資訊,請使用「搜尋基礎」工具。

  2. 脈絡窗口的限制為何?Gemini 3.5 Flash 支援 100 萬個詞元的輸入脈絡窗口,以及最多 6.5 萬個輸出詞元。

  3. 舊的 thinking_budget 程式碼是否仍可運作?是的,我們仍支援 thinking_budget 以確保回溯相容性,但建議您改用 thinking_level,以獲得更可預測的效能。請勿在同一要求中同時使用這兩者。

  4. Gemini 3.5 Flash 是否支援 Batch API?可以。詳情請參閱 Batch API 指南。

  5. 是否支援脈絡快取?是,支援脈絡快取。

  6. 支援哪些工具?Gemini 3.5 Flash 支援 Google 搜尋、利用 Google 地圖建立基準、檔案搜尋、執行程式碼、網址背景資訊和標準函式呼叫,包括合併使用工具和電腦使用。

其他模型

後續步驟