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 万个 token 的上下文窗口、最多 65,000 个输出 token、 思考功能,以及与 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,因此我们建议您迁移到以下某个有效模型:
- Gemini 3.8 Flash:我们最新、最智能的 Flash 模型,适用于复杂的编码和 Agentic Workflows。请参阅 Gemini 3.8 Flash 指南。
- Gemini 3.6 Flash:
gemini-3.5-flash的直接替代品,token 使用量更少,输出价格更低。请参阅 Gemini 3.6 Flash 和 3.5 Flash-Lite 指南。 - Gemini 3.5 Flash-Lite / Gemini 3.1 Flash-Lite:对于不需要完整 Flash 推理深度、低成本、大批量的任务,请使用Gemini 3.5 Flash-Lite或Gemini 3.1 Flash-Lite。
行为更改
新的默认工作量级别: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 中的工具调用。
如需了解如何更新代码,请参阅以下部分。
采样参数(不再推荐)
对于所有 Gemini 3.x 模型,不再推荐使用 temperature、top_p 和 top_k。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
}
减少不必要的工具调用
如果您发现工具调用过多,可以使用以下两种方法来最大限度地减少工具调用:
首先降低思考级别 (
medium、low或minimal):思考级别越高,模型就越会使用更多工具进行探索和验证,因此降低级别可以减少工具调用。添加系统说明: 如果在调整思考级别后,工具调用过多问题仍然存在,请考虑使用限制工具使用的提示。例如:
You have a limited action budget of <n> tool calls. Use them efficiently.
Gemini 3 系列功能
Gemini 3.5 Flash 继承了 Gemini 3 系列的所有功能,包括计算机使用。 Gemini 3 中引入的功能:
- 思考: 加密的 推理上下文在 API 调用之间保留。在 Interactions API 中自动;在 GenerateContent 中隐式。
- 使用工具的结构化输出: 将 JSON 模式与 内置工具(搜索、网址上下文、代码执行、函数调用)相结合。
- 多模态函数响应: 在函数调用结果中返回 图片、音频和其他媒体。
- 使用图片执行代码: 执行 处理和生成图片的代码。
- 组合工具使用: 在同一请求中使用内置工具和 自定义函数调用。
- 媒体分辨率:
对图片、视频和 PDF 输入的 token 分配进行精细控制。
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 并关闭思考功能。
常见问题解答
Gemini 3.5 Flash 的知识截点是什么?Gemini 3.5 Flash 的知识截点为 2025 年 1 月。如需了解最新信息,请使用 搜索接地工具。
上下文窗口有哪些限制?Gemini 3.5 Flash 支持 100 万个 token 输入的上下文窗口,以及最多 65,000 个输出 token。
我的旧
thinking_budget代码是否仍然有效?是的,thinking_budget仍然受支持,以实现向后兼容性,但我们建议您迁移到thinking_level,以获得更可预测的性能。请勿在同一请求中同时使用这两者。Gemini 3.5 Flash 是否支持 Batch API?是的。如需了解详情,请参阅 Batch API 指南。
是否支持上下文缓存?是的, 支持上下文缓存。
支持哪些工具?Gemini 3.5 Flash 支持 Google 搜索、 Grounding with Google Maps、 文件搜索、 代码执行、 网址上下文和 标准函数调用, 包括 组合工具使用和 计算机使用。
其他模型
后续步骤
- 如需详细了解提示设计策略,请参阅 提示工程指南。
- 开始使用Gemini 3 Cookbook
- 了解 Gemini API 优化和推理