Gemini 3.5 Flash の新機能

3.6 Flash と 3.5 Flash-Lite このページ

Gemini 3.5 Flash は一般提供(GA)されており、安定していて、スケーリングされた本番環境での使用に対応しています。Google 史上最もインテリジェントな Flash モデルとして、エージェント実行、コーディング、長期的なタスクで持続的な最先端のパフォーマンスを大規模に実現します。

このガイドでは、Gemini 3.5 Flash の改善点、API の変更、移行に関するガイダンスの概要について説明します。

新しいモデル

モデル モデル ID 説明
Gemini 3.5 Flash gemini-3.5-flash エージェント タスクとコーディング タスクで持続的な最先端のパフォーマンスを発揮する、Google 史上最もインテリジェントなモデルです。

Gemini 3.5 Flash は、100 万トークンのコンテキスト ウィンドウ、最大 65,000 トークンの出力トークン、思考、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."
  }'

最新情報

  • 持続的な最先端のパフォーマンス: Google 史上最もインテリジェントな Flash モデル。大規模なエージェント タスクとコーディング タスク向けに最適化されています。
  • エージェントによる実行: サブエージェントのデプロイ、問題解決、大規模なエージェント ループの迅速な実行。
  • コーディング: 反復的なコーディング サイクル、迅速な探索、プロトタイピングにより、代替パスをテストし、ソリューションを動的に探索します。
  • 長期的な展望: 複数のステップからなるワークフローとツールを大規模に活用します。
  • 思考の保持: モデルは、マルチターンの会話全体で中間推論を自動的に維持します。API の変更は不要です。
  • 新しいデフォルトの思考労力レベル: デフォルトの思考労力が high から medium に変更されました。詳細については、新しいデフォルトの取り組みレベルをご覧ください。
  • low の思考が改善されました: low は、手順が少ないコードタスクとエージェント タスクで大幅に改善され、低レイテンシと低コストで高品質を実現します。
  • 一般提供版リリース: スケーリングされた本番環境で使用できる安定版モデル。

適切な Flash モデルの選択

Gemini 3.5 Flash は、Google 史上最も高性能な Flash モデルです。ただし、ユースケースによって費用とレイテンシの要件が異なる場合があります。

  • Gemini 3.1 Flash-Lite: 3.5 Flash の高度な推論の深さを必要としない、低コストで大容量のタスクには、Gemini 3.1 Flash-Lite の使用をおすすめします。効率性を最適化した安定した長期モデルです。詳しくは、Flash-Lite デベロッパー ガイドをご覧ください。
  • Gemini 3 Flash プレビュー版: GA の安定性と推論の改善のために 3.5 Flash への移行をおすすめしますが、プレビュー版モデルでのテストを継続したいデベロッパー向けに Gemini 3 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 サポート対象 サポート対象外 Supported(デフォルト) サポート対象 ほとんどのクエリで「思考なし」の設定と一致します。なお、minimal を設定しても思考がオフになるわけではありません。複雑なタスクでは、モデルが最小限の推論を行うことがあります。
low サポート対象 サポート対象 サポート対象 サポート対象 レイテンシと費用を最小限に抑えます。
medium Supported(デフォルト) サポート対象 サポート対象 サポート対象 ほとんどのタスクでバランスの取れた思考。
high サポート対象(動的) サポート対象(デフォルト、動的) サポート対象(動的) サポート対象(デフォルト、動的) 推論の深さを最大化します。

思考の保持

モデルは、マルチターンの会話全体で中間推論を自動的に維持します。推論コンテキストが会話履歴に存在する場合、推論コンテキストは引き継がれます。これにより、反復デバッグやコードのリファクタリングなどの複雑な複数ステップのタスクのパフォーマンスが向上します。API の変更は不要です。

  • Interactions API: すでに自動的に保存されています。動作に変更はありません。
  • GenerateContent API: Gemini 3.5 Flash 以降、モデルは会話履歴に思考シグネチャが存在する場合、以前のすべてのターンの推論コンテキストを使用します。これを有効にするには、contents で完全な会話履歴(思考シグネチャを含む)をそのまま渡します。SDK はこれを自動的に処理します。

Gemini 3.x のパラメータの更新とベスト プラクティス

Gemini 3.5 Flash を含む すべての Gemini 3.x モデルに、次のことが当てはまります。

  • temperaturetop_ptop_k: デフォルト値を変更しないことを強くおすすめします。Gemini 3 の推論機能は、デフォルト設定用に最適化されています。
  • thinking_budget ではなく thinking_level を使用します。
  • 関数呼び出しレスポンスのマッチング: idname、レスポンス数は、前の呼び出しと一致する必要があります。
  • マルチモーダル関数レスポンス: マルチモーダル コンテンツは、関数レスポンスの外部ではなく、内部に含めます。
  • 関数レスポンスのインライン指示: 個別の部分としてではなく、関数レスポンスのテキストに追加します。
  • 不要なツール呼び出しを減らす: エージェント ワークフローでツール呼び出しを減らすには、思考レベルを下げるか、システム指示を試します。

コードの更新方法については、以下のセクションをご覧ください。

サンプリング パラメータ(非推奨)

temperaturetop_ptop_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"},
}

使用可能な値: minimallowmedium(デフォルト)、high

関数呼び出し: 厳密なレスポンス マッチング

Interactions API は、関数レスポンスが一致しない場合にすでにエラーを返します。GenerateContent API はまだエラーを返しませんが、レスポンスが一致しない場合、ほとんどのケースでモデルは finish_reason: STOP を含む空のレスポンスを返します。常に次の規則に従ってください。

要件 詳細
idを含む すべての FunctionResponse には、対応する FunctionCallid が含まれている必要があります
name 試合 レスポンスの name は、呼び出しの name と一致する必要があります。
一致数 受信した FunctionCall ごとに 1 つの 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 として、関数レスポンスとともに追加の指示を提供することがよくあります。これにより、予期しないモデルの動作(思考の漏洩など)が発生し、出力の品質が低下する可能性があります。代わりに、余分な指示を 2 つの改行で区切って、関数レスポンス テキストの末尾に追加します。

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
}

不要なツール呼び出しを減らす

ツール呼び出しの過剰な使用が発生した場合は、次の 2 つの手法で最小限に抑えることができます。

  1. 思考レベルを下げることから始めますmediumlow、または minimal): 思考レベルが高いほど、モデルは探索と検証に多くのツールを使用する傾向があるため、レベルを下げることでツール呼び出しを減らすことができます。

  2. システム指示を追加する:思考レベルを調整しても過剰な使用が続く場合は、ツールの使用を制限するプロンプトを検討してください。次に例を示します。

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

移行チェックリスト

google-genai SDK v2.0.0 以降に更新することを強くおすすめします。このバージョンでは、Interactions API に互換性を破る変更が導入されています。詳しくは、破壊的変更の移行ガイドをご覧ください。

Gemini 3 Flash プレビューから移行する

  • モデル名を更新: gemini-3-flash-previewgemini-3.5-flash
  • 料金を確認します。Gemini 3.5 Flash は Gemini 3 Flash プレビュー版よりも高価です。ユースケースでコストが重視される場合は、代わりに Gemini 3.1 Flash-Lite への移行を検討してください。詳細については、料金ページをご覧ください。
  • 構成から temperaturetop_ptop_k を削除します(推奨されなくなりました)。
  • thinking_budgetthinking_level に置き換えます。
  • すべての FunctionResponse 部分に id と一致する name を追加します。
  • プロンプトをテストします。デフォルトの労力が highmedium に変更されました。品質、速度、費用を確認します。
  • 思考の保持がデフォルトでオンになりました。推論コンテキストはターン間で引き継がれるため、パフォーマンスは向上しますが、トークンの使用量が増える可能性があります。
  • 不要なツール呼び出しを減らす: まず、思考レベル(mediumlow、または minimal)を下げます。過剰な使用が続く場合は、ツール使用を制限するシステム指示を追加します。
  • コンピュータ使用がサポートされています。

Gemini 2.5 から移行する

上記のすべてに加えて、次の機能があります。

  • プロンプトを簡素化します。Chain-of-Thought プロンプト エンジニアリングを使用して推論を強制した場合は、代わりに thinking_level: "medium" または "high" を使用して、よりシンプルなプロンプトを試してください。
  • PDF とメディアのワークロードをテストします。高密度ドキュメントの解析で特定の動作に依存していた場合は、media_resolution_high 設定をテストして、精度が維持されることを確認してください。Gemini 3 のデフォルトに移行すると、PDF のトークン使用量が増加し、動画のトークン使用量が減少する可能性があります。リクエストがコンテキスト ウィンドウを超える場合は、media_resolution を明示的に減らしてください。詳しくは、メディアの解像度に関するドキュメントをご覧ください。
  • ツールを組み合わせて使用します。Google 検索、URL コンテキスト、コード実行、カスタム関数は、同じリクエストで使用できます。
  • マルチモーダル関数レスポンスを使用する場合は、マルチモーダル コンテンツを関数レスポンス部分の内部に移動します。
  • 関数レスポンスでインライン指示を使用する場合は、別々の部分としてではなく、2 つの改行で区切って関数レスポンス テキストに追加します。
  • Gemini 3.x では、画像セグメンテーションはサポートされていません。セグメンテーション ワークロードでは、思考をオフにした Gemini 2.5 Flash を引き続き使用してください。
  • 構成から candidate_count を削除する(Gemini 3.x ではサポートされていません)

Gemini 3 ファミリーの機能

Gemini 3.5 Flash は、コンピュータの使用など、Gemini 3 ファミリーのすべての機能を継承しています。Gemini 3 で導入され、引き継がれる機能:

  • 思考: 暗号化された推論コンテキストが API 呼び出し間で保持されます。Interactions API では自動。GenerateContent では暗黙的。
  • ツールを使用した構造化出力: JSON モードと組み込みツール(検索、URL コンテキスト、コード実行、関数呼び出し)を組み合わせます。
  • マルチモーダル関数レスポンス: 関数呼び出しの結果で画像、音声、その他のメディアを返します。
  • 画像を使用したコード実行: 画像を処理して生成するコードを実行します。
  • ツールの組み合わせ使用: 同じリクエストで、組み込みツールとカスタム関数呼び出しを使用します。
  • メディアの解像度: 画像、動画、PDF の入力に対するトークン割り当てをきめ細かく制御します。Gemini 3 モデルは、混合忠実度プロンプトのコンテンツ アイテムごとの解像度設定(lowmediumhighultra_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 万トークンの入力コンテキスト ウィンドウと最大 65,000 トークンの出力をサポートしています。

  3. 以前の thinking_budget コードは引き続き機能しますか?はい。下位互換性のために thinking_budget は引き続きサポートされますが、パフォーマンスの予測可能性を高めるために thinking_level への移行をおすすめします。同じリクエストで両方を使用しないでください。

  4. Gemini 3.5 Flash は Batch API をサポートしていますか?はい。詳細については、Batch API ガイドをご覧ください。

  5. コンテキスト キャッシュ保存はサポートされていますか?はい、コンテキスト キャッシュ保存がサポートされています。

  6. どのツールがサポートされていますか?Gemini 3.5 Flash は、Google 検索Google マップによるグラウンディングファイル検索コード実行URL コンテキスト、標準の関数呼び出しツールの組み合わせ使用コンピュータの使用など)をサポートしています。

次のステップ