# Gemini 3.5 Flash 新特性

{% callout type="caution" %}
**已弃用：** Gemini 3.5 Flash (`gemini-3.5-flash`) 已弃用并已替换为 [Gemini 3.6 Flash (`gemini-3.6-flash`)](/docs/whats-new-gemini-3.6)。 Google AI Studio 中不再可供选择，API 请求 `gemini-3.5-flash` 自动路由到 `gemini-3.6-flash`。将您的模型字符串更新为 `gemini-3.6-flash` （或 [Gemini 3.8 Flash](/docs/latest-model)）并审查 [Gemini 3.6 Flash指南](/docs/whats-new-gemini-3.6).
{% /callout %}

Gemini 3.5 Flash (`gemini-3.5-flash`）是 Gemini 3 系列中的较早一代 Flash 模型，现已弃用并自动路由到 [Gemini 3.6 Flash](/docs/whats-new-gemini-3.6).

本指南保留供参考，并记录了 Gemini 3.5 Flash 中引入的功能和基线 Gemini 3.x 参数更新。

## 型号概览  {% #new-model %}

| 模型                    | 型号编号               | 说明                                                                         |
| --------------------- | ------------------ | -------------------------------------------------------------------------- |
| Gemini 3.5 Flash（已弃用） | `gemini-3.5-flash` | 用于智能体和编码任务的早期 Flash 模型。替换为 [Gemini 3.6 Flash](/docs/whats-new-gemini-3.6). |

Gemini 3.5 Flash支持1M token 上下文窗口，最大65k输出token，思维，以及与Gemini 3 Flash相同的工具集和平台功能，包括 [电脑使用](/docs/computer-use).

有关完整规格，请参阅 [型号概览](/docs/models/gemini-3.5-flash).

## 快速入门  {% #quickstart %}

本指南中的所有示例均使用 Interactions API。还支持GenerateContent API；相同的配置选项和建议适用。

{% tabs %}
{% tab filename="quickstart.py" label="Python" %}
```python
from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.6-flash",
    input="Explain how parallel agentic execution works in three sentences."
)
print(interaction.output_text)
```
{% /tab %}

{% tab filename="quickstart.js" label="JavaScript" %}
```javascript
import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

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

await main();
```
{% /tab %}

{% tab label="REST" %}
```bash
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  -d '{
    "model": "gemini-3.6-flash",
    "input": "Explain how parallel agentic execution works in three sentences."
  }'
```
{% /tab %}

{% tab label="Java" %}
```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(""));
```
{% /tab %}

{% tab label="Go" %}
```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)
    }
}
```
{% /tab %}
{% /tabs %}

## 有什么新消息  {% #whats-new %}

* **持续前沿表现：** 我们最智能的 Flash 模型，针对大规模智能体和编码任务进行了优化。
* **智能体执行：** Sub-智能体部署、问题解决和大规模快速智能体循环。
* **编码：** 迭代编码周期、快速探索和原型设计，以测试替代路径并动态探索解决方案。
* **长远视野：** 多步骤工作流程和大规模工具使用。
* **思想保存：** 该模型自动维护多轮对话的中间推理。无需 API 更改。
* **新的默认努力水平：** 默认思维努力从 `high` 到 `medium`。参见 [新的默认努力水平](/docs/whats-new-gemini-3.5#default-effort-level) 了解详情。
* **改进 `low` 思考：** `low` 现在，对于需要更少步骤的代码和智能体任务有了显着改进，以更低的延迟和成本提供了强大的质量。
* **正式发布：** 用于规模化生产的稳定模型。

### 选择正确的 Flash 型号  {% #choose-model %}

Gemini 3.5 Flash 已弃用并自动路由到 [Gemini 3.6 Flash](/docs/whats-new-gemini-3.6)。根据您的成本、延迟和功能要求，我们推荐以下型号：

* **Gemini 3.8 Flash**：我们最新、最智能的 Flash 模型，适用于复杂的编码和智能体工作流程。请参阅 [Gemini 3.8 Flash指南](/docs/latest-model).
* **Gemini 3.6 Flash**：直接替换 Gemini 3.5 Flash，减少 token 的使用量并降低输出价格。请参阅 [Gemini 3.6 Flash 和 3.5 Flash-Lite 指南](/docs/whats-new-gemini-3.6).
* **Gemini 3.5 Flash-Lite / Gemini 3.1 Flash-Lite**：对于不需要完整 Flash 推理深度的低成本、大批量任务，请使用 [Gemini 3.5 Flash-Lite](/docs/models/gemini-3.5-flash-lite) 或 [Gemini 3.1 Flash-Lite](/docs/models/gemini-3.1-flash-lite).

## 行为改变  {% #behavioral-changes %}

### 新的默认努力水平： `medium` {% #default-effort-level %}

默认的思考努力是现在 **`medium`**，改变自 `high` 在 Gemini 3 Flash Preview 中。 `medium` 在各种任务中都能产生非常好的结果，同时速度更快、更具成本效益。对于复杂的问题， `high`
鼓励模型更深入地思考。

| 努力程度              | 何时使用                                                        |
| ----------------- | ----------------------------------------------------------- |
| `minimal`         | 优化响应速度。类似聊天的用例、快速的事实答案、更简单的工具调用。                            |
| `low`             | 需要更低延迟和更少步骤的代码和智能体任务。也适用于需要一些思考的分析和写作任务。                    |
| **`medium` （默认）** | **大多数任务的最佳质量。推荐用于复杂代码和智能体用例。**                              |
| `high`            | 最大限度地提高模型思考和使用工具的能力。最适合复杂推理、困难数学和最困难的代码或智能体任务。允许扩展的想法和函数调用。 |

要覆盖默认值，请设置 `thinking_level` 在你的配置中：

{% tabs %}
{% tab filename="thinking_level.py" label="Python" %}
```python
from google import genai

client = genai.Client()

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

{% tab filename="thinking_level.js" label="JavaScript" %}
```javascript
import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

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

await main();
```
{% /tab %}

{% tab label="REST" %}
```bash
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  -d '{
    "model": "gemini-3.6-flash",
    "input": "Prove that the square root of 2 is irrational.",
    "generation_config": {"thinking_level": "high"}
  }'
```
{% /tab %}

{% tab label="Java" %}
```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(""));
```
{% /tab %}

{% tab label="Go" %}
```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)
    }
}
```
{% /tab %}
{% /tabs %}

{% callout type="note" %}
开始于 `medium`，它为绝大多数任务提供了最好的质量。尝试一下 `low` 以获得更快、更便宜的体验和强大的品质。切换到 `high` 用于复杂的推理、困难的数学或困难的编码挑战。使用 `minimal` 优化简单查询的速度。
{% /callout %}

下表显示了每个模型支持的思维级别：

{% doc-table %}
{% doc-row header="true" %}
{% doc-cell %}
思维层面
{% /doc-cell %}

{% doc-cell %}
Gemini 3.5 Flash
{% /doc-cell %}

{% doc-cell %}
Gemini 3.1 Pro
{% /doc-cell %}

{% doc-cell %}
Gemini 3.1 Flash-Lite
{% /doc-cell %}

{% doc-cell %}
Gemini 3 Flash
{% /doc-cell %}

{% doc-cell %}
说明
{% /doc-cell %}
{% /doc-row %}

{% doc-row header="false" %}
{% doc-cell %}
**`minimal`**
{% /doc-cell %}

{% doc-cell %}
支持
{% /doc-cell %}

{% doc-cell %}
不支持
{% /doc-cell %}

{% doc-cell %}
支持（默认）
{% /doc-cell %}

{% doc-cell %}
支持
{% /doc-cell %}

{% doc-cell %}
匹配大多数查询的“不思考”设置。注意， `minimal` 并不能保证思维是关闭的，该模型可能对复杂任务进行非常简单的推理。
{% /doc-cell %}
{% /doc-row %}

{% doc-row header="false" %}
{% doc-cell %}
**`low`**
{% /doc-cell %}

{% doc-cell %}
支持
{% /doc-cell %}

{% doc-cell %}
支持
{% /doc-cell %}

{% doc-cell %}
支持
{% /doc-cell %}

{% doc-cell %}
支持
{% /doc-cell %}

{% doc-cell %}
最大限度地减少延迟和成本。
{% /doc-cell %}
{% /doc-row %}

{% doc-row header="false" %}
{% doc-cell %}
**`medium`**
{% /doc-cell %}

{% doc-cell %}
支持（默认）
{% /doc-cell %}

{% doc-cell %}
支持
{% /doc-cell %}

{% doc-cell %}
支持
{% /doc-cell %}

{% doc-cell %}
支持
{% /doc-cell %}

{% doc-cell %}
对大多数任务的平衡思考。
{% /doc-cell %}
{% /doc-row %}

{% doc-row header="false" %}
{% doc-cell %}
**`high`**
{% /doc-cell %}

{% doc-cell %}
支持（动态）
{% /doc-cell %}

{% doc-cell %}
支持（默认、动态）
{% /doc-cell %}

{% doc-cell %}
支持（动态）
{% /doc-cell %}

{% doc-cell %}
支持（默认、动态）
{% /doc-cell %}

{% doc-cell %}
最大化推理深度。
{% /doc-cell %}
{% /doc-row %}
{% /doc-table %}

{% callout type="caution" %}
您不能同时使用两者 `thinking_level` 和遗产 `thinking_budget` 同一请求中的参数。这样做将返回 400 错误。
{% /callout %}

### 思想保存  {% #thought-preservation %}

该模型自动维护多轮对话的中间推理。当存在于对话历史记录中时，推理上下文会继续下去，从而提高复杂的多步骤任务（例如迭代调试和代码重构）的性能。无需 API 更改：

* **Interactions API**：思想已经自动保存。行为没有改变。
* **生成内容 API**：从 Gemini 3.5 Flash 开始，当对话历史记录中存在思想签名时，模型会使用之前所有回合的推理上下文。要启用此功能，请传递完整的、未经修改的对话历史记录（包括 [思想签名](/docs/thinking#signatures)) 在 `contents`。 SDK 会自动处理这个问题。

## Gemini 3.x 中的参数更新和最佳实践  {% #parameter-updates %}

以下内容适用于 **所有 Gemini 3.x 型号**，包括 Gemini 3.5 Flash。

* **`temperature`, `top_p`, `top_k`**：我们强烈建议不要更改默认值。 Gemini 3 的推理能力针对默认设置进行了优化。
* 使用 `thinking_level` 而不是 `thinking_budget`.
* **函数调用响应匹配**: `id`, `name`，并且响应计数必须与前面的调用匹配。
* **多模态功能响应**：将多模态内容包含在函数响应内部，而不是外部。
* **函数响应中的内联指令**：附加到函数响应文本，而不是作为单独的部分。
* **减少不必要的工具调用**：使用较低的思维水平或尝试系统指令来减少智能体工作流程中的工具调用。

有关如何更新代码的信息，请参阅以下部分。

### 采样参数（不再推荐）  {% #sampling-parameters %}

`temperature`, `top_p`, 和 `top_k` 不再推荐用于所有 Gemini 3.x 型号。 Gemini 3 的推理功能针对默认设置进行了优化。 **从所有请求中删除这些参数。**

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

为了确保确定性，我们建议为您的特定用例定义具有明确规则的系统指令。

### `thinking_budget` （不再推荐）  {% #thinking-budget %}

原始数字 `thinking_budget` 不再建议在所有 Gemini 3.x 型号中使用该参数。使用 `thinking_level` 改为字符串枚举。

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

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

可用值： `minimal`, `low`, `medium` （默认），以及 `high`.

### 函数调用：严格响应匹配  {% #function-calling %}

Interactions API 已经因不匹配的函数响应而出错。 GenerateContent API 尚未出错，但不匹配的响应会导致模型返回空响应 `finish_reason: STOP` 在大多数情况下。始终遵循以下约定：

| 要求        | 详情                                                  |
| --------- | --------------------------------------------------- |
| 包括 `id`   | 每个 `FunctionResponse` 必须包括 `id` 从相应的 `FunctionCall` |
| 比赛 `name` | 该 `name` 响应中必须匹配 `name` 在通话中                        |
| 比赛计数      | 返回正好 1 `FunctionResponse` 对于每个 `FunctionCall` 收到    |

{% tabs %}
{% tab filename="function_calling_match.py" label="Python" %}
```python
# ✅ Include matching call_id and name in the function_result
final_interaction = client.interactions.create(
    model="gemini-3.6-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)}],
    }],
)
```
{% /tab %}

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

{% tab label="REST" %}
```bash
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Api-Revision: 2026-05-20" \
  -d '{
    "model": "gemini-3.6-flash",
    "previous_interaction_id": "<INTERACTION_ID>",
    "tools": [...],
    "input": [{
      "type": "function_result",
      "name": "my_function",
      "call_id": "<CALL_ID>",
      "result": [{"type": "text", "text": "..."}]
    }]
  }'
```
{% /tab %}

{% tab label="Java" %}
```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();
```
{% /tab %}

{% tab label="Go" %}
```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
}
```
{% /tab %}
{% /tabs %}

### 多模态功能响应  {% #multimodal-function-responses %}

我们经常看到客户提供功能响应之外的图像。这可能会导致意外的模型行为（例如思想泄漏）并导致输出质量较低。按照中的建议进行操作 [多模态函数响应 API 文档](/docs/function-calling?example=meeting#multimodal) 相反，并在发送到模型的函数响应部分中包含多模态内容。该模型可以在下一轮处理这种多模态内容，以产生更明智的响应。

{% tabs %}
{% tab filename="multimodal_function.py" label="Python" %}
```python
# ✅ Include multimodal content in the function response
final_interaction = client.interactions.create(
    model="gemini-3.6-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,
                },
            ],
        }
    ],
)
```
{% /tab %}

{% tab filename="multimodal_function.js" label="JavaScript" %}
```javascript
// ✅ Include multimodal content in the function response
const finalInteraction = await client.interactions.create({
  model: "gemini-3.6-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,
      },
    ],
  }],
});
```
{% /tab %}

{% tab label="Java" %}
```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();
```
{% /tab %}

{% tab label="Go" %}
```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
}
```
{% /tab %}
{% /tabs %}

### 函数响应中的内联指令  {% #inline-instructions %}

我们经常看到客户提供附加说明以及后续的功能响应 `Parts`。这可能会导致意外的模型行为（例如思想泄漏）并导致输出质量较低。相反，请将任何额外的指令附加到由两个换行符分隔的函数响应文本的末尾。

{% tabs %}
{% tab filename="inline_instructions.py" label="Python" %}
```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.6-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}],
    }],
)
```
{% /tab %}

{% tab filename="inline_instructions.js" label="JavaScript" %}
```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.6-flash",
  previousInteractionId: interaction.id,
  tools: [myTool],
  input: [{
    type: "function_result",
    name: fcStep.name,
    call_id: fcStep.id,
    result: [{ type: "text", text: resultText }],
  }],
});
```
{% /tab %}

{% tab label="Java" %}
```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();
```
{% /tab %}

{% tab label="Go" %}
```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
}
```
{% /tab %}
{% /tabs %}

### 减少不必要的工具调用  {% #reducing-tool-calls %}

如果您过度使用工具调用，有两种技术可以帮助您最大程度地减少这种情况：

1. **从降低思维层次开始** (`medium`, `low`, 或 `minimal`): 较高的思维水平鼓励模型使用更多的工具来探索和验证，因此降低水平可以减少工具调用。

1. **添加系统指令：** 如果调整思维水平后仍然存在过度使用，请考虑限制工具使用的提示。例如：

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

{% callout type="caution" %}
**我们强烈建议更新至 `google-genai`
SDK v2.0.0 或更高版本。** 此版本对 Interactions API 进行了重大更改。请参阅 [重大变更迁移指南](/docs/interactions-breaking-changes-may-2026)
了解详情。
{% /callout %}

## Gemini 3系列特性  {% #gemini-3-features %}

Gemini 3.5 Flash 继承了 Gemini 3 系列的所有功能，包括计算机使用。 Gemini 3 中引入的功能继承了：

* [**思考**](/docs/thinking)**:** 在 API 调用中保留加密的推理上下文。 Interactions API 自动；隐含在GenerateContent中。
* [**使用工具进行结构化输出**](/docs/structured-output)**:** 将 JSON 模式与内置工具（搜索、URL 上下文、代码执行、函数调用）相结合。
* [**多模态功能响应**](/docs/function-calling#multimodal)**:** 在函数调用结果中返回图像、音频和其他媒体。
* [**使用图像执行代码**](/docs/code-execution#images)**:** 执行处理和生成图像的代码。
* [**组合工具使用**](/docs/tool-combination)**:** 在同一请求中使用内置工具和自定义函数调用。
* [**媒体分辨率**](/docs/media-resolution)**:** 对图像、视频和 PDF 输入的 token 分配进行细粒度控制。 Gemini 3 型号支持每个内容项的分辨率设置（`low`, `medium`, `high`, `ultra_high`）用于混合保真度提示。
* [**思考签名**](/docs/thinking#signatures)**:** 模型内部推理的加密表示。无状态模式下多轮函数调用需要；由 Interactions API 和官方 SDK 自动管理。

## 提示最佳实践  {% #prompting-best-practices %}

Gemini 3.x 模型是推理模型，它改变了您应该如何提示。

* **准确说明：** 保持简洁。 Gemini 3.x 对直接、清晰的指令反应最好。为旧模型设计的冗长或复杂的提示工程技术可能会导致模型过度分析。
* **输出详细程度：** 默认情况下，Gemini 3 和 3.1 不太冗长，更喜欢直接、高效的答案。如果您的用例需要对话语气，请在提示中明确引导模型（例如，“将其解释为友好、健谈的助手”）。
* **上下文管理：** 处理大型数据集（例如整本书、代码库或长视频）时，请将具体说明或问题放在提示末尾的数据上下文之后。通过用“基于前面的信息......”之类的短语开始你的问题来锚定模型的推理。

了解有关提示设计策略的更多信息 [及时的工程指南](/docs/prompting-strategies).

## 限制  {% #limitations %}

* Gemini 3.x 不支持图像分割。对于分段工作负载，请继续使用 Gemini 2.5 Flash 并进行思考，或者 [Gemini Robotics-ER 1.6](/docs/robotics-overview).

## FAQ  {% #faq %}

1. **Gemini 3.5 Flash 的知识截止点是多少？** Gemini 3.5 Flash 的知识截止日期为 1 月 2025. 有关更多最新信息，请使用 [搜索事实依据](/docs/google-search) 工具。
1. **上下文窗口限制是什么？** Gemini 3.5 Flash支持1百万个token输入上下文窗口和最多65k输出token。
1. **我的老 `thinking_budget` 代码还能用吗？** 是的， `thinking_budget` 仍然支持向后兼容，但我们建议迁移到 `thinking_level` 以获得更可预测的性能。不要在同一请求中同时使用两者。
1. **Gemini 3.5 Flash是否支持Batch API？** 是的。请参阅 [Batch API](/docs/batch-api) 指南了解详细信息。
1. **是否支持上下文缓存？** 是的， [上下文缓存](/docs/caching) 是支持的。
1. **支持哪些工具？** Gemini 3.5 Flash 支持 [Google 搜索](/docs/google-search), [使用 Google 地图提供事实依据](/docs/maps-grounding), [文件搜索](/docs/file-search), [代码执行](/docs/code-execution), [URL上下文](/docs/url-context)，和标准 [函数调用](/docs/function-calling)，包括 [组合工具使用](/docs/tool-combination), 和 [电脑使用](/docs/computer-use).

## 其他型号  {% #other-models %}

* [最新 Gemini 模型](/docs/latest-model)
* [Gemini 4 Hydrogen](/docs/whats-new-gemini-4-hydrogen)
* [Gemini 4 Carbon](/docs/whats-new-gemini-4-carbon)
* [Gemini 4 Argon](/docs/whats-new-gemini-4-argon)
* [Gemini 3.8 Flash](/docs/whats-new-gemini-3.8)
* [Gemini 3.6 Flash 和 3.5 Flash-Lite](/docs/whats-new-gemini-3.6)
* [查看所有型号](/docs/models)

## 后续步骤  {% #whats-next %}

* 了解有关提示设计策略的更多信息 [及时的工程指南](/docs/prompting-strategies).
* 开始使用 [Gemini 3 Cookbook](https://github.com/google-gemini/cookbook)
* 了解 [Gemini API 优化与推理](/docs/optimization)
