Gemini の思考
Gemini 3 シリーズと 2.5 シリーズのモデルは、 「思考プロセス」を使用して推論能力とマルチステップ プランニング能力を大幅に向上させているため、コーディング、高度な数学、データ分析などの複雑なタスクに非常に効果的です。
思考モデルを使用すると、Gemini はレスポンスを返す前に内部で推論を行います。Interactions API は、この推論を thought ステップで表面化します。これは、steps 配列内の関数呼び出し、ユーザー入力、モデル出力とともに時系列で表示される専用のステップです。
思考ステップには、次の 2 つのフィールドが含まれます。
| フィールド | 必須 | 説明 |
|---|---|---|
signature |
✅ はい | モデルの内部推論状態を暗号化した表現。モデルが最小限の推論を行う場合でも常に存在します。 |
summary |
❌ いいえ | 推論を要約するコンテンツ(テキストや画像)の配列。thinking_summaries 構成、モデルが十分な推論を行ったかどうか、コンテンツ タイプ(画像レイテンシにテキストの要約がない場合など)によって空になることがあります。 |
思考とのインタラクション
思考モデルとのインタラクションを開始する手順は、他のインタラクション リクエストと同様です。model フィールドで、思考をサポートするモデルのいずれかを指定します。
Python
# This will only work for SDK newer than 2.0.0
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="Explain the concept of Occam's Razor and provide a simple, everyday example."
)
print(interaction.steps[-1].content[0].text)
JavaScript
// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: "Explain the concept of Occam's Razor and provide a simple, everyday example."
});
console.log(interaction.steps.at(-1).content[0].text);
REST
# Specifies the API revision to avoid breaking changes when they become default
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3-flash-preview",
"input": "Explain the concept of Occam'\''s Razor and provide a simple example."
}'
思考インタラクションをストリーミングして、生成中に思考の要約とシグネチャを段階的に受け取ることができます。イベントタイプ、デルタタイプ、コード例について詳しくは、ストリーミング インタラクション ガイドをご覧ください。
思考の要約
思考の要約は、モデルの内部推論プロセスに関する分析情報を提供します。
デフォルトでは、最終出力のみが返されます。thinking_summaries を使用して思考の要約を有効にできます。
Python
# This will only work for SDK newer than 2.0.0
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="What is the sum of the first 50 prime numbers?",
generation_config={
"thinking_summaries": "auto"
}
)
for step in interaction.steps:
if step.type == "thought":
print("Thought summary:")
if step.summary:
for content_block in step.summary:
if content_block.type == "text":
print(content_block.text)
print()
elif step.type == "model_output":
for content_block in step.content:
if content_block.type == "text":
print("Answer:")
print(content_block.text)
print()
JavaScript
// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: "What is the sum of the first 50 prime numbers?",
generation_config: {
thinking_summaries: "auto"
}
});
for (const step of interaction.steps) {
if (step.type === "thought") {
console.log("Thought summary:");
if (step.summary) {
for (const contentBlock of step.summary) {
if (contentBlock.type === "text") console.log(contentBlock.text);
}
}
} else if (step.type === "model_output") {
for (const contentBlock of step.content) {
if (contentBlock.type === "text") {
console.log("Answer:");
console.log(contentBlock.text);
}
}
}
}
REST
# Specifies the API revision to avoid breaking changes when they become default
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3-flash-preview",
"input": "What is the sum of the first 50 prime numbers?",
"generation_config": {
"thinking_summaries": "auto"
}
}'
次の場合、思考ブロックには要約のないシグネチャのみ が含まれることがあります。
- モデルが要約を生成するのに十分な推論を行わなかった単純なリクエスト
thinking_summaries: "none": 要約が明示的に無効になっている場合- 画像など、特定の思考コンテンツ タイプにはテキストの要約がない場合がある
コードでは、summary が空または存在しない思考ブロックを常に処理する必要があります。
思考の制御
Gemini モデルはデフォルトで動的思考を行い、リクエストの複雑さに応じて推論の労力を自動的に調整します。この動作は、thinking_level パラメータを使用して制御できます。
| モデル | デフォルトの思考 | サポートされているレベル |
|---|---|---|
| gemini-3.1-pro-preview | オン(高) | 低、中、高 |
| gemini-3-flash-preview | オン(高) | 最小、低、中、高 |
| gemini-3-pro-preview | オン(高) | 低、高 |
| gemini-2.5-pro | オン | 低、中、高 |
| gemini-2.5-flash | オン | 低、中、高 |
| gemini-2.5-flash-lite | オフ | 低、中、高 |
Python
# This will only work for SDK newer than 2.0.0
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="Provide a list of 3 famous physicists and their key contributions",
generation_config={
"thinking_level": "low"
}
)
print(interaction.steps[-1].content[0].text)
JavaScript
// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: "Provide a list of 3 famous physicists and their key contributions",
generation_config: {
thinking_level: "low"
}
});
console.log(interaction.steps.at(-1).content[0].text);
REST
# Specifies the API revision to avoid breaking changes when they become default
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3-flash-preview",
"input": "Provide a list of 3 famous physicists and their key contributions",
"generation_config": {
"thinking_level": "low"
}
}'
思考シグネチャ
思考シグネチャは、モデルの内部推論を暗号化したものです。複数ターンのインタラクションで推論の継続性を維持するために必要です。
Interactions API を使用すると、generateContent API よりも思考シグネチャの処理がはるかに簡単になります。
ステートフル モード(推奨)
デフォルトでは、ステートフル モードで Interactions API を使用する場合(store: true を設定し、後続のターンで previous_interaction_id を渡す場合)、サーバーはすべての思考ブロックとシグネチャを含む会話の状態を自動的に管理します。このモードでは、シグネチャに関して何もする必要はありません。サーバー側で完全に処理されます。
ステートレス モード
会話の状態を自分で管理し(ステートレス モード)、各リクエストで入力と出力の完全な履歴を渡す場合:
- モデルから受信したとおりに、すべての
thoughtブロックを必ず再送信する必要があります 。 - モデルが推論を続行するために必要なシグネチャが含まれているため、履歴から思考ブロックを削除または変更しないでください 。
- セッション内でモデルを切り替える場合は、前のモデルの思考ブロックを再送信する必要があります。バックエンドで互換性が管理されます。
料金
思考がオンの場合、レスポンスの料金は出力トークンと思考トークンの合計です。生成された思考トークンの合計数は、total_thought_tokens フィールドから取得できます。
Python
# This will only work for SDK newer than 2.0.0
# ...
print("Thoughts tokens:", interaction.usage.total_thought_tokens)
print("Output tokens:", interaction.usage.total_output_tokens)
JavaScript
// This will only work for SDK newer than 2.0.0
// ...
console.log(`Thoughts tokens: ${interaction.usage.total_thought_tokens}`);
console.log(`Output tokens: ${interaction.usage.total_output_tokens}`);
思考モデルは、最終的な レスポンスの品質を高めるために完全な思考を生成し、思考プロセスに関する 分析情報を提供するために要約を出力します。料金は、API から出力されるのは要約のみですが、モデルが生成する必要がある完全な思考トークンに基づきます。
トークンについて詳しくは、トークンのカウント ガイドをご覧ください。
ベスト プラクティス
次のガイドラインに沿って、思考モデルを効率的に使用してください。
- 推論を確認する: 思考の要約を分析して、失敗の原因を把握し、プロンプトを改善します。
- 思考予算を管理する: 長い出力の場合は、モデルの思考を減らすようにプロンプトを設定して、トークンを節約します。
- 簡単なタスク: 事実の取得や分類(例: 「DeepMind はどこで設立されましたか?」)には、最小限の思考を使用します。
- 中程度のタスク: 概念の比較や創造的な推論(例: 電気自動車とハイブリッド車の比較)には、デフォルトの思考を使用します。
- 複雑なタスク : 高度なコーディング、数学、マルチステップ プランニング(例: AIME の数学の問題を解く)には、最大限の思考を使用します。
次のステップ
- テキスト生成: 基本的なテキスト レスポンス
- 関数呼び出し: ツールに接続する
- Gemini 3 ガイド: モデル固有の機能