思考モード

思考モデルは、レスポンスの一部としてモデルが行う「思考プロセス」を生成するようにトレーニングされています。そのため、思考モデルは、同等のベースモデルよりもレスポンスの推論能力が強化されています。

思考プロセスはデフォルトで有効になっています。Vertex AI Studio を使用すると、モデルから生成されたレスポンスとともに、思考プロセス全体を表示できます。

サポートされているモデル

思考がサポートされているのは、次のモデルです。

思考モデルを使用する

サポートされているモデルで思考を使用するには、次の操作を行います。

コンソール

  1. [Vertex AI Studio] > [プロンプトを作成] を開きます。
  2. [モデル] パネルで、[モデルの切り替え] をクリックし、メニューからサポート対象のモデルのいずれかを選択します。
    • (Gemini 2.5 Flash のみ)モデルが読み込まれると、[思考予算] はデフォルトで [自動] に設定されます。
  3. (省略可)[システム指示] フィールドで、モデルが返すレスポンスのフォーマットについて、モデルに詳細な指示を与えます。
  4. [プロンプトを入力します…] フィールドにプロンプトを入力します。
  5. [ 実行] をクリックします。

Gemini は、レスポンスが生成されるとそれを返します。レスポンスの複雑さによっては、生成に数秒かかることがあります。

(Gemini 2.5 Flash のみ)思考を無効にするには、[思考予算] を [オフ] に設定します。

Python

インストール

pip install --upgrade google-genai

詳しくは、SDK リファレンス ドキュメントをご覧ください。

Vertex AI で Gen AI SDK を使用するための環境変数を設定します。

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

from google import genai

client = genai.Client()
response = client.models.generate_content(
    model="gemini-2.5-pro",
    contents="solve x^2 + 4x + 4 = 0",
)
print(response.text)
# Example Response:
#     Okay, let's solve the quadratic equation x² + 4x + 4 = 0.
#
#     We can solve this equation by factoring, using the quadratic formula, or by recognizing it as a perfect square trinomial.
#
#     **Method 1: Factoring**
#
#     1.  We need two numbers that multiply to the constant term (4) and add up to the coefficient of the x term (4).
#     2.  The numbers 2 and 2 satisfy these conditions: 2 * 2 = 4 and 2 + 2 = 4.
#     3.  So, we can factor the quadratic as:
#         (x + 2)(x + 2) = 0
#         or
#         (x + 2)² = 0
#     4.  For the product to be zero, the factor must be zero:
#         x + 2 = 0
#     5.  Solve for x:
#         x = -2
#
#     **Method 2: Quadratic Formula**
#
#     The quadratic formula for an equation ax² + bx + c = 0 is:
#     x = [-b ± sqrt(b² - 4ac)] / (2a)
#
#     1.  In our equation x² + 4x + 4 = 0, we have a=1, b=4, and c=4.
#     2.  Substitute these values into the formula:
#         x = [-4 ± sqrt(4² - 4 * 1 * 4)] / (2 * 1)
#         x = [-4 ± sqrt(16 - 16)] / 2
#         x = [-4 ± sqrt(0)] / 2
#         x = [-4 ± 0] / 2
#         x = -4 / 2
#         x = -2
#
#     **Method 3: Perfect Square Trinomial**
#
#     1.  Notice that the expression x² + 4x + 4 fits the pattern of a perfect square trinomial: a² + 2ab + b², where a=x and b=2.
#     2.  We can rewrite the equation as:
#         (x + 2)² = 0
#     3.  Take the square root of both sides:
#         x + 2 = 0
#     4.  Solve for x:
#         x = -2
#
#     All methods lead to the same solution.
#
#     **Answer:**
#     The solution to the equation x² + 4x + 4 = 0 is x = -2. This is a repeated root (or a root with multiplicity 2).

Go

Go をインストールまたは更新する方法について学びます。

詳しくは、SDK リファレンス ドキュメントをご覧ください。

Vertex AI で Gen AI SDK を使用するための環境変数を設定します。

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

import (
	"context"
	"fmt"
	"io"

	"google.golang.org/genai"
)

// generateThinkingWithText shows how to generate thinking using a text prompt.
func generateThinkingWithText(w io.Writer) error {
	ctx := context.Background()

	client, err := genai.NewClient(ctx, &genai.ClientConfig{
		HTTPOptions: genai.HTTPOptions{APIVersion: "v1"},
	})
	if err != nil {
		return fmt.Errorf("failed to create genai client: %w", err)
	}

	resp, err := client.Models.GenerateContent(ctx,
		"gemini-2.5-flash",
		genai.Text("solve x^2 + 4x + 4 = 0"),
		nil,
	)
	if err != nil {
		return fmt.Errorf("failed to generate content: %w", err)
	}

	respText := resp.Text()

	fmt.Fprintln(w, respText)
	// Example response:
	// To solve the quadratic equation $x^2 + 4x + 4 = 0$, we can use a few methods:
	//
	// **Method 1: Factoring (Recognizing a Perfect Square Trinomial)**
	// **1. The Foundation: Data and Algorithms**
	//
	// Notice that the left side of the equation is a perfect square trinomial.
	// ...

	return nil
}

モデルの思考を制御する

モデルがレスポンスを返す前に実行する思考の量を制御できます。思考を制御する方法は、モデルのバージョンによって異なります。

Gemini 3 以降のモデル

Gemini 3 モデルには thinking_level パラメータが導入されています。これにより、思考予算の構成がレベルに簡素化されます。デフォルトでは、Gemini 3 モデルは動的思考(thinking_level.HIGH)を使用してプロンプトを推論します。複雑な推論が必要ない場合に、より高速で低レイテンシのレスポンスを得るには、モデルの thinking_level を制約します。

次の表に、各モデルでサポートされている thinking_level 値をまとめます。

モデル サポートされる thinking_level
Gemini 3.1 Pro LOWMEDIUMHIGH
Gemini 3.1 Flash-Lite MINIMALLOWMEDIUMHIGH
Gemini 3.1 Flash Image MINIMALHIGH
Gemini 3 Flash MINIMALLOWMEDIUMHIGH
Gemini 3 Pro LOWMEDIUMHIGH
Gemini 3 Pro Image HIGH
  • MINIMAL: (Gemini 3 Flash、Gemini 3.1 Flash Image、Gemini 3.1 Flash-Lite のみ)思考にできるだけ少ないトークンを使用するようにモデルを制約します。広範な推論のメリットがない複雑性の低いタスクに最適です。これは Gemini 3.1 Flash-Lite のデフォルトのレベルです。MINIMAL は、思考の予算をゼロにできるだけ近づけながら、思考シグネチャを必要とします。リクエストで思考シグネチャが提供されていない場合、モデルは 400 エラーを返します。詳細については、思考シグネチャをご覧ください。

    from google import genai
    from google.genai import types
    
    client = genai.Client()
    
    response = client.models.generate_content(
        model="gemini-3-flash-preview",
        contents="How does AI work?",
        config=types.GenerateContentConfig(
            thinking_config=types.ThinkingConfig(
                thinking_level=types.ThinkingLevel.MINIMAL
            )
        ),
    )
    print(response.text)
    
  • LOW: モデルが思考に使用するトークン数を制限します。広範な推論を必要としない単純なタスクに適しています。LOW は、速度が不可欠な高スループットのタスクに最適です。

    from google import genai
    from google.genai import types
    
    client = genai.Client()
    
    response = client.models.generate_content(
        model="gemini-3.1-pro-preview",
        contents="How does AI work?",
        config=types.GenerateContentConfig(
            thinking_config=types.ThinkingConfig(
                thinking_level=types.ThinkingLevel.LOW
            )
        ),
    )
    print(response.text)
    
  • MEDIUM: (Gemini 3 Flash、Gemini 3.1 Pro、Gemini 3.1 Flash-Lite のみ) 推論のメリットがありながら、深い多段階の計画を必要としない、中程度の複雑さのタスクに適したバランスの取れたアプローチを提供します。LOW よりも推論能力が高く、HIGH よりもレイテンシが低くなります。

    from google import genai
    from google.genai import types
    
    client = genai.Client()
    
    response = client.models.generate_content(
        model="gemini-3-flash-preview",
        contents="How does AI work?",
        config=types.GenerateContentConfig(
            thinking_config=types.ThinkingConfig(
                thinking_level=types.ThinkingLevel.MEDIUM
            )
        ),
    )
    print(response.text)
    
  • HIGH: モデルが思考に多くのトークンを使用できるようにします。マルチステップの計画、検証済みのコード生成、高度な関数呼び出しシナリオなど、深い推論を必要とする複雑なプロンプトに適しています。これは Gemini 3 Pro モデルと Gemini 3 Flash のデフォルトのレベルです。以前に特殊な推論モデルに依存していたタスクを置き換える場合は、この構成を使用します。

    from google import genai
    from google.genai import types
    
    client = genai.Client()
    
    response = client.models.generate_content(
        model="gemini-3.1-pro-preview",
        contents="Find the race condition in this multi-threaded C++ snippet: [code here]",
        config=types.GenerateContentConfig(
            thinking_config=types.ThinkingConfig(
                thinking_level=types.ThinkingLevel.HIGH
            )
        ),
    )
    print(response.text)
    

Gemini 3 Pro と Gemini 3.1 Pro では思考を無効にできません。

Gemini 3 モデルの同じリクエストで thinking_levelthinking_budget の両方を指定すると、モデルはエラーを返します。

Gemini 2.5 以前のモデル

Gemini 3 より前のモデルでは、thinking_budget パラメータを使用して思考を制御できます。このパラメータは、モデルが思考プロセスで使用できるトークンの数に上限を設定します。デフォルトでは、thinking_budget が設定されていない場合、モデルは最大 8,192 トークンまでの思考を自動的に制御します。API を介して動的予算を使用するには、thinking_budget-1 に設定します。

デフォルトの思考予算よりも多くのトークンが必要になる場合や、トークンが少なくて済む場合は、thinking_budget を手動で設定して、トークン数の上限を緩やかに設定できます。複雑でないタスクにはトークンの上限を低く設定し、複雑なタスクには上限を高く設定できます。これはソフトリミットであるため、合計思考トークンにはばらつきが生じる可能性があります。レイテンシを重視する場合は、予算を減らすか、予算を 0 に設定して、思考コンテンツがレスポンスとともに返されないようにします。

次の表に、サポートされている各モデルの thinking_budget に対して設定可能な最小値と最大値を示します。

モデル 最小トークン量 最大トークン量
Gemini 2.5 Flash 1 24,576
Gemini 2.5 Pro 128 32,768
Gemini 2.5 Flash-Lite 512 24,576

Gemini 2.5 Flash と Gemini 2.5 Flash-Lite を使用する場合、thinking_budget0 に設定すると、レスポンスで思考コンテンツが返されません。ただし、推論スタイルのテキストがモデルの出力に含まれる可能性はあります。Gemini 2.5 Pro では思考モードを無効にできません。

Gemini 3 より前のモデルで thinking_level パラメータを使用すると、モデルはエラーを返します。

コンソール

  1. [Vertex AI Studio] > [プロンプトを作成] を開きます。
  2. [モデル] パネルで、[モデルの切り替え] をクリックし、メニューからサポート対象のモデルのいずれかを選択します。
  3. [思考予算] プルダウン セレクタから [手動] を選択し、スライダーを使用して思考予算の上限を調整します。

Python

インストール

pip install --upgrade google-genai

詳しくは、SDK リファレンス ドキュメントをご覧ください。

Vertex AI で Gen AI SDK を使用するための環境変数を設定します。

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

from google import genai
from google.genai.types import GenerateContentConfig, ThinkingConfig

client = genai.Client()

response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="solve x^2 + 4x + 4 = 0",
    config=GenerateContentConfig(
        thinking_config=ThinkingConfig(
            thinking_budget=1024,  # Use `0` to turn off thinking
        )
    ),
)

print(response.text)
# Example response:
#     To solve the equation $x^2 + 4x + 4 = 0$, you can use several methods:
#     **Method 1: Factoring**
#     1.  Look for two numbers that multiply to the constant term (4) and add up to the coefficient of the $x$ term (4).
#     2.  The numbers are 2 and 2 ($2 \times 2 = 4$ and $2 + 2 = 4$).
#     ...
#     ...
#     All three methods yield the same solution. This quadratic equation has exactly one distinct solution (a repeated root).
#     The solution is **x = -2**.

# Token count for `Thinking`
print(response.usage_metadata.thoughts_token_count)
# Example response:
#     886

# Total token count
print(response.usage_metadata.total_token_count)
# Example response:
#     1525

Node.js

インストール

npm install @google/genai

詳しくは、SDK リファレンス ドキュメントをご覧ください。

Vertex AI で Gen AI SDK を使用するための環境変数を設定します。

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

const {GoogleGenAI} = require('@google/genai');

const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global';

async function generateWithThoughts(
  projectId = GOOGLE_CLOUD_PROJECT,
  location = GOOGLE_CLOUD_LOCATION
) {
  const client = new GoogleGenAI({
    vertexai: true,
    project: projectId,
    location: location,
  });

  const response = await client.models.generateContent({
    model: 'gemini-2.5-flash',
    contents: 'solve x^2 + 4x + 4 = 0',
    config: {
      thinkingConfig: {
        thinkingBudget: 1024,
      },
    },
  });

  console.log(response.text);
  // Example response:
  //  To solve the equation $x^2 + 4x + 4 = 0$, you can use several methods:
  //  **Method 1: Factoring**
  //  1.  Look for two numbers that multiply to the constant term (4) and add up to the coefficient of the $x$ term (4).
  //  2.  The numbers are 2 and 2 ($2 \times 2 = 4$ and $2 + 2 = 4$).
  //  ...
  //  ...
  //  All three methods yield the same solution. This quadratic equation has exactly one distinct solution (a repeated root).
  //  The solution is **x = -2**.

  // Token count for `Thinking`
  console.log(response.usageMetadata.thoughtsTokenCount);
  // Example response:
  //  886

  // Total token count
  console.log(response.usageMetadata.totalTokenCount);
  // Example response:
  //  1525
  return response.text;
}

Go

Go をインストールまたは更新する方法について学びます。

詳しくは、SDK リファレンス ドキュメントをご覧ください。

Vertex AI で Gen AI SDK を使用するための環境変数を設定します。

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

import (
	"context"
	"fmt"
	"io"

	"google.golang.org/genai"
)

// generateThinkingBudgetContentWithText demonstrates how to generate text including the model's thought process.
func generateThinkingBudgetContentWithText(w io.Writer) error {
	ctx := context.Background()

	client, err := genai.NewClient(ctx, &genai.ClientConfig{
		HTTPOptions: genai.HTTPOptions{APIVersion: "v1"},
	})
	if err != nil {
		return fmt.Errorf("failed to create genai client: %w", err)
	}

	modelName := "gemini-2.5-flash"
	thinkingBudget := int32(1024) //Use `0` to turn off thinking
	contents := []*genai.Content{
		{
			Parts: []*genai.Part{
				{Text: "solve x^2 + 4x + 4 = 0"},
			},
			Role: "user",
		},
	}

	resp, err := client.Models.GenerateContent(ctx,
		modelName,
		contents,
		&genai.GenerateContentConfig{
			ThinkingConfig: &genai.ThinkingConfig{
				ThinkingBudget: &thinkingBudget,
			},
		},
	)
	if err != nil {
		return fmt.Errorf("generate content failed: %w", err)
	}

	if resp.UsageMetadata != nil {
		fmt.Fprintf(w, "Thoughts token count: %d\n", resp.UsageMetadata.ThoughtsTokenCount)
		//Example response:
		//  908
		fmt.Fprintf(w, "Total token count: %d\n", resp.UsageMetadata.TotalTokenCount)
		//Example response:
		//  1364
	}

	fmt.Fprintln(w, resp.Text())

	// Example response:
	//    To solve the equation $x^2 + 4x + 4 = 0$, you can use several methods:
	//    **Method 1: Factoring**
	//    1.  Look for two numbers that multiply to the constant term (4) and add up to the coefficient of the $x$ term (4).
	//    2.  The numbers are 2 and 2 ($2 \times 2 = 4$ and $2 + 2 = 4$).
	//    ...
	//    ...
	//    Both methods yield the same result.
	//    The solution to the equation $x^2 + 4x + 4 = 0$ is **$x = -2$**.

	return nil
}

Java

Java をインストールまたは更新します。

詳しくは、SDK リファレンス ドキュメントをご覧ください。

Vertex AI で Gen AI SDK を使用するための環境変数を設定します。

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True


import com.google.genai.Client;
import com.google.genai.types.GenerateContentConfig;
import com.google.genai.types.GenerateContentResponse;
import com.google.genai.types.HttpOptions;
import com.google.genai.types.ThinkingConfig;

public class ThinkingBudgetWithTxt {

  public static void main(String[] args) {
    // TODO(developer): Replace these variables before running the sample.
    String modelId = "gemini-2.5-flash";
    generateContent(modelId);
  }

  // Generates text controlling the thinking budget
  public static String generateContent(String modelId) {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests.
    try (Client client =
        Client.builder()
            .location("global")
            .vertexAI(true)
            .httpOptions(HttpOptions.builder().apiVersion("v1").build())
            .build()) {

      GenerateContentConfig contentConfig =
          GenerateContentConfig.builder()
              .thinkingConfig(ThinkingConfig.builder().thinkingBudget(1024).build())
              .build();

      GenerateContentResponse response =
          client.models.generateContent(modelId, "solve x^2 + 4x + 4 = 0", contentConfig);

      System.out.println(response.text());
      // Example response:
      // To solve the equation $x^2 + 4x + 4 = 0$, we can use several methods:
      //
      // **Method 1: Factoring (Recognizing a Perfect Square Trinomial)**
      //
      // Notice that the left side of the equation is a perfect square trinomial. It fits the form
      // $a^2 + 2ab + b^2 = (a+b)^2$...
      // ...
      // The solution is $x = -2$.

      response
          .usageMetadata()
          .ifPresent(
              metadata -> {
                System.out.println("Token count for thinking: " + metadata.thoughtsTokenCount());
                System.out.println("Total token count: " + metadata.totalTokenCount());
              });
      // Example response:
      // Token count for thinking: Optional[885]
      // Total token count: Optional[1468]
      return response.text();
    }
  }
}

思考の要約を表示する

思考の要約は、モデルがレスポンスを生成したときにたどった思考プロセスを出力したものの短縮版です。Gemini 2.5 以降のモデルでは、思考の要約を表示できます。思考の要約を表示するには、次の操作を行います。

コンソール

思考の要約は、Vertex AI Studio でデフォルトで有効になっています。モデルの要約された思考プロセスを表示するには、[思考プロセス] パネルを開きます。

Python

インストール

pip install --upgrade google-genai

詳しくは、SDK リファレンス ドキュメントをご覧ください。

Vertex AI で Gen AI SDK を使用するための環境変数を設定します。

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

from google import genai
from google.genai.types import GenerateContentConfig, ThinkingConfig

client = genai.Client()
response = client.models.generate_content(
    model="gemini-2.5-pro",
    contents="solve x^2 + 4x + 4 = 0",
    config=GenerateContentConfig(
        thinking_config=ThinkingConfig(include_thoughts=True)
    ),
)

print(response.text)
# Example Response:
#     Okay, let's solve the quadratic equation x² + 4x + 4 = 0.
#     ...
#     **Answer:**
#     The solution to the equation x² + 4x + 4 = 0 is x = -2. This is a repeated root (or a root with multiplicity 2).

for part in response.candidates[0].content.parts:
    if part and part.thought:  # show thoughts
        print(part.text)
# Example Response:
#     **My Thought Process for Solving the Quadratic Equation**
#
#     Alright, let's break down this quadratic, x² + 4x + 4 = 0. First things first:
#     it's a quadratic; the x² term gives it away, and we know the general form is
#     ax² + bx + c = 0.
#
#     So, let's identify the coefficients: a = 1, b = 4, and c = 4. Now, what's the
#     most efficient path to the solution? My gut tells me to try factoring; it's
#     often the fastest route if it works. If that fails, I'll default to the quadratic
#     formula, which is foolproof. Completing the square? It's good for deriving the
#     formula or when factoring is difficult, but not usually my first choice for
#     direct solving, but it can't hurt to keep it as an option.
#
#     Factoring, then. I need to find two numbers that multiply to 'c' (4) and add
#     up to 'b' (4). Let's see... 1 and 4 don't work (add up to 5). 2 and 2? Bingo!
#     They multiply to 4 and add up to 4. This means I can rewrite the equation as
#     (x + 2)(x + 2) = 0, or more concisely, (x + 2)² = 0. Solving for x is now
#     trivial: x + 2 = 0, thus x = -2.
#
#     Okay, just to be absolutely certain, I'll run the quadratic formula just to
#     double-check. x = [-b ± √(b² - 4ac)] / 2a. Plugging in the values, x = [-4 ±
#     √(4² - 4 * 1 * 4)] / (2 * 1). That simplifies to x = [-4 ± √0] / 2. So, x =
#     -2 again – a repeated root. Nice.
#
#     Now, let's check via completing the square. Starting from the same equation,
#     (x² + 4x) = -4. Take half of the b-value (4/2 = 2), square it (2² = 4), and
#     add it to both sides, so x² + 4x + 4 = -4 + 4. Which simplifies into (x + 2)²
#     = 0. The square root on both sides gives us x + 2 = 0, therefore x = -2, as
#      expected.
#
#     Always, *always* confirm! Let's substitute x = -2 back into the original
#     equation: (-2)² + 4(-2) + 4 = 0. That's 4 - 8 + 4 = 0. It checks out.
#
#     Conclusion: the solution is x = -2. Confirmed.

Node.js

インストール

npm install @google/genai

詳しくは、SDK リファレンス ドキュメントをご覧ください。

Vertex AI で Gen AI SDK を使用するための環境変数を設定します。

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

const {GoogleGenAI} = require('@google/genai');

const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global';

async function generateWithThoughts(
  projectId = GOOGLE_CLOUD_PROJECT,
  location = GOOGLE_CLOUD_LOCATION
) {
  const client = new GoogleGenAI({
    vertexai: true,
    project: projectId,
    location: location,
  });

  const response = await client.models.generateContent({
    model: 'gemini-2.5-pro',
    contents: 'solve x^2 + 4x + 4 = 0',
    config: {
      thinkingConfig: {
        includeThoughts: true,
      },
    },
  });

  console.log(response.text);
  // Example Response:
  //  Okay, let's solve the quadratic equation x² + 4x + 4 = 0.
  //  ...
  //  **Answer:**
  //  The solution to the equation x² + 4x + 4 = 0 is x = -2. This is a repeated root (or a root with multiplicity 2).

  for (const part of response.candidates[0].content.parts) {
    if (part && part.thought) {
      console.log(part.text);
    }
  }

  // Example Response:
  // **My Thought Process for Solving the Quadratic Equation**
  //
  // Alright, let's break down this quadratic, x² + 4x + 4 = 0. First things first:
  // it's a quadratic; the x² term gives it away, and we know the general form is
  // ax² + bx + c = 0.
  //
  // So, let's identify the coefficients: a = 1, b = 4, and c = 4. Now, what's the
  // most efficient path to the solution? My gut tells me to try factoring; it's
  // often the fastest route if it works. If that fails, I'll default to the quadratic
  // formula, which is foolproof. Completing the square? It's good for deriving the
  // formula or when factoring is difficult, but not usually my first choice for
  // direct solving, but it can't hurt to keep it as an option.
  //
  // Factoring, then. I need to find two numbers that multiply to 'c' (4) and add
  // up to 'b' (4). Let's see... 1 and 4 don't work (add up to 5). 2 and 2? Bingo!
  // They multiply to 4 and add up to 4. This means I can rewrite the equation as
  // (x + 2)(x + 2) = 0, or more concisely, (x + 2)² = 0. Solving for x is now
  // trivial: x + 2 = 0, thus x = -2.
  //
  // Okay, just to be absolutely certain, I'll run the quadratic formula just to
  // double-check. x = [-b ± √(b² - 4ac)] / 2a. Plugging in the values, x = [-4 ±
  // √(4² - 4 * 1 * 4)] / (2 * 1). That simplifies to x = [-4 ± √0] / 2. So, x =
  // -2 again – a repeated root. Nice.
  //
  // Now, let's check via completing the square. Starting from the same equation,
  // (x² + 4x) = -4. Take half of the b-value (4/2 = 2), square it (2² = 4), and
  // add it to both sides, so x² + 4x + 4 = -4 + 4. Which simplifies into (x + 2)²
  // = 0. The square root on both sides gives us x + 2 = 0, therefore x = -2, as
  //  expected.
  //
  // Always, *always* confirm! Let's substitute x = -2 back into the original
  // equation: (-2)² + 4(-2) + 4 = 0. That's 4 - 8 + 4 = 0. It checks out.
  //
  // Conclusion: the solution is x = -2. Confirmed.

  return response.text;
}

Go

Go をインストールまたは更新する方法について学びます。

詳しくは、SDK リファレンス ドキュメントをご覧ください。

Vertex AI で Gen AI SDK を使用するための環境変数を設定します。

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

import (
	"context"
	"fmt"
	"io"

	"google.golang.org/genai"
)

// generateContentWithThoughts demonstrates how to generate text including the model's thought process.
func generateContentWithThoughts(w io.Writer) error {
	ctx := context.Background()

	client, err := genai.NewClient(ctx, &genai.ClientConfig{
		HTTPOptions: genai.HTTPOptions{APIVersion: "v1"},
	})
	if err != nil {
		return fmt.Errorf("failed to create genai client: %w", err)
	}

	modelName := "gemini-2.5-pro"
	contents := []*genai.Content{
		{
			Parts: []*genai.Part{
				{Text: "solve x^2 + 4x + 4 = 0"},
			},
			Role: "user",
		},
	}

	resp, err := client.Models.GenerateContent(ctx,
		modelName,
		contents,
		&genai.GenerateContentConfig{
			ThinkingConfig: &genai.ThinkingConfig{
				IncludeThoughts: true,
			},
		},
	)
	if err != nil {
		return fmt.Errorf("failed to generate content: %w", err)
	}

	if len(resp.Candidates) == 0 || resp.Candidates[0].Content == nil {
		return fmt.Errorf("no content was generated")
	}

	// The response may contain both the final answer and the model's thoughts.
	// Iterate through the parts to print them separately.
	fmt.Fprintln(w, "Answer:")
	for _, part := range resp.Candidates[0].Content.Parts {
		if part.Text != "" && !part.Thought {
			fmt.Fprintln(w, part.Text)
		}
	}
	fmt.Fprintln(w, "\nThoughts:")
	for _, part := range resp.Candidates[0].Content.Parts {
		if part.Thought {
			fmt.Fprintln(w, part.Text)
		}
	}

	// Example response:
	//  Answer:
	//	Of course! We can solve this quadratic equation in a couple of ways.
	//
	//### Method 1: Factoring (the easiest method for this problem)
	//
	//1.  **Recognize the pattern.** The expression `x² + 4x + 4` is a perfect square trinomial. It fits the pattern `a² + 2ab + b² = (a + b)²`. In this case, `a = x` and `b = 2`.
	//
	//2.  **Factor the equation.**
	//    `x² + 4x + 4 = (x + 2)(x + 2) = (x + 2)²`
	//
	//3.  **Solve for x.** Now set the factored expression to zero:
	//    `(x + 2)² = 0`
	//
	//    Take the square root of both sides:
	//    `x + 2 = 0`
	//
	//    Subtract 2 from both sides:
	//    `x = -2`
	//
	//This type of solution is called a "repeated root" or a "double root" because the factor `(x+2)` appears twice.
	//
	//---
	//
	//### Method 2: Using the Quadratic Formula
	//
	//You can use the quadratic formula for any equation in the form `ax² + bx + c = 0`.
	//
	//The formula is: `x = [-b ± sqrt(b² - 4ac)] / 2a`
	//
	//1.  **Identify a, b, and c.**
	//    *   a = 1
	//    *   b = 4
	//    *   c = 4
	//
	//2.  **Plug the values into the formula.**
	//    `x = [-4 ± sqrt(4² - 4 * 1 * 4)] / (2 * 1)`
	//
	//3.  **Simplify.**
	//    `x = [-4 ± sqrt(16 - 16)] / 2`
	//    `x = [-4 ± sqrt(0)] / 2`
	//    `x = -4 / 2`
	//
	//4.  **Solve for x.**
	//    `x = -2`
	//Alright, the user wants to solve the quadratic equation `x² + 4x + 4 = 0`. My first instinct is to see if I can factor it; that's often the fastest approach if it works.  Looking at the coefficients, I see `a = 1`, `b = 4`, and `c = 4`.  Factoring is clearly the most direct path here. I need to find two numbers that multiply to 4 (c) and add up to 4 (b). Hmm, let's see 1 and 4? Nope, that adds to 5.  2 and 2? Perfect!  2 times 2 is 4, and 2 plus 2 is also 4.
	//
	//So, `x² + 4x + 4` factors nicely into `(x + 2)(x + 2)`.  Ah, a perfect square trinomial! That's useful to note. Now, I can write the equation as `(x + 2)² = 0`.  Taking the square root of both sides gives me `x + 2 = 0`.  And finally, subtracting 2 from both sides, I get `x = -2`.  That's the solution.
	//
	//Just to be thorough, and maybe to offer an alternative explanation, let's verify this using the quadratic formula. It's `x = [-b ± (b² - 4ac)] / 2a`. Plugging in my values:  `x = [-4 ± (4² - 4 * 1 * 4)] / (2 * 1)`.  That simplifies to `x = [-4 ± (16 - 16)] / 2`, or `x = [-4 ± 0] / 2`.  Therefore, `x = -2`. The discriminant being zero tells me I have exactly one real, repeated root.  Great. So, whether I factor or use the quadratic formula, the answer is the same.
	return nil
}

Java

Java をインストールまたは更新します。

詳しくは、SDK リファレンス ドキュメントをご覧ください。

Vertex AI で Gen AI SDK を使用するための環境変数を設定します。

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True


import com.google.genai.Client;
import com.google.genai.types.Candidate;
import com.google.genai.types.Content;
import com.google.genai.types.GenerateContentConfig;
import com.google.genai.types.GenerateContentResponse;
import com.google.genai.types.HttpOptions;
import com.google.genai.types.ThinkingConfig;

public class ThinkingIncludeThoughtsWithTxt {

  public static void main(String[] args) {
    // TODO(developer): Replace these variables before running the sample.
    String modelId = "gemini-2.5-pro";
    generateContent(modelId);
  }

  // Generates text including thoughts in the response
  public static String generateContent(String modelId) {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests.
    try (Client client =
        Client.builder()
            .location("global")
            .vertexAI(true)
            .httpOptions(HttpOptions.builder().apiVersion("v1").build())
            .build()) {

      GenerateContentConfig contentConfig =
          GenerateContentConfig.builder()
              .thinkingConfig(ThinkingConfig.builder().includeThoughts(true).build())
              .build();

      GenerateContentResponse response =
          client.models.generateContent(modelId, "solve x^2 + 4x + 4 = 0", contentConfig);

      System.out.println(response.text());
      // Example response:
      // We can solve the equation x² + 4x + 4 = 0 using a couple of common methods.
      //
      // ### Method 1: Factoring (The Easiest Method for this Problem)
      // **Recognize the pattern:** The pattern for a perfect square trinomial
      // is a² + 2ab + b² = (a + b)².
      // ...
      // ### Final Answer:
      // The solution is **x = -2**.

      // Get parts of the response and print thoughts
      response
          .candidates()
          .flatMap(candidates -> candidates.stream().findFirst())
          .flatMap(Candidate::content)
          .flatMap(Content::parts)
          .ifPresent(
              parts -> {
                parts.forEach(
                    part -> {
                      if (part.thought().orElse(false)) {
                        part.text().ifPresent(System.out::println);
                      }
                    });
              });
      // Example response:
      // Alright, let's break down this quadratic equation, x² + 4x + 4 = 0. My initial thought is,
      // "classic quadratic."  I'll need to find the values of 'x' that make this equation true. The
      // equation is in standard form, and since the coefficients are relatively small, I
      // immediately suspect that factoring might be the easiest route.  It's worth checking.
      //
      // First, I assessed what I had. *a* is 1, *b* is 4, and *c* is 4. I consider my toolkit.
      // Factoring is the likely first choice, then I can use the quadratic formula as a backup,
      // because that ALWAYS works, and I could use graphing. However, for this, factoring seems the
      // cleanest approach.
      //
      // Okay, factoring. I need two numbers that multiply to *c* (which is 4) and add up to *b*
      // (also 4).  I quickly run through the factor pairs of 4: (1, 4), (-1, -4), (2, 2), (-2, -2).
      //  Aha! 2 and 2 fit the bill. They multiply to 4 *and* add up to 4.  Therefore, I can rewrite
      // the equation as (x + 2)(x + 2) = 0.  That simplifies to (x + 2)² = 0. Perfect square
      // trinomial  nice and tidy. Seeing that pattern from the outset can save a step or two. Now,
      // to solve for *x*:  if (x + 2)² = 0, then x + 2 must equal 0.  Therefore, x = -2. Done.
      //
      // But, for the sake of a full explanation, let's use the quadratic formula as a second
      // method. It's a reliable way to double-check the answer, plus it's good practice.  I plug my
      // *a*, *b*, and *c* values into the formula: x = [-b ± (b² - 4ac)] / (2a). That gives me  x
      // = [-4 ± (4² - 4 * 1 * 4)] / (2 * 1). Simplifying under the radical, I get x = [-4 ± (16 -
      // 16)] / 2. So, x = [-4 ± 0] / 2. The square root of 0 is zero, which is very telling!  When
      // the discriminant (b² - 4ac) is zero, you get one real solution, a repeated root. This means
      // x = -4 / 2, which simplifies to x = -2.  Exactly the same as before.
      //
      // Therefore, the answer is x = -2.  Factoring was the most straightforward route.  For
      // completeness, I showed the solution via the quadratic formula, too. Both approaches lead to
      // the same single solution.  This is a repeated root  a double root, if you will.
      //
      // And to be absolutely sure...let's check our answer! Substitute -2 back into the original
      // equation. (-2)² + 4(-2) + 4 = 4 - 8 + 4 = 0.  Yep, 0 = 0. The solution is correct.
      return response.text();
    }
  }
}

思考シグネチャ

思考シグネチャは、モデルの内部的な思考プロセスを暗号化したものです。特に関数呼び出しを使用する場合に、マルチターンの会話で Gemini の推論状態を維持します。

モデルが会話を何度もやり取りしながらコンテキストを維持できるようにするために、使用する思考レベルに関係なく、その後のリクエストで以前のレスポンスの思考シグネチャを返す必要があります。公式の Google Gen AI SDK(Python、Node.js、Go、Java)を使用して、標準のチャット履歴機能を使用している場合、またはモデルの完全なレスポンスを履歴に追加している場合、思考シグネチャは自動的に処理されます。

詳細については、思考シグネチャをご覧ください。

プロンプトの手法

効果的なプロンプトは、Gemini 思考モデルのメリットを最大限に引き出すうえで不可欠です。このセクションでは、思考モデルのプロンプトの実施方法について説明します。

まず、望ましい結果を示す一般的な手順から始めます。複雑度の低いプロンプトから始めて、どのように応答するのか、モデルの最初の思考を観察します。

Describe the most unusual or striking architectural feature you've ever seen in a building or structure.
  
<...>
The most unusual architectural feature that has truly stayed with me is the "floating roof" of the
  Heydar Aliyev Center in Baku, Azerbaijan, designed by Zaha Hadid Architects.

Visually, it's breathtaking. Imagine a vast, undulating landscape of pure white, seemingly draped
over the building. It's not just a roof in the traditional sense; it's an extension of the ground,
flowing seamlessly upwards and over the building's various spaces before curving back down to meet
the earth again. There are no sharp angles, no rigid lines. Instead, everything is fluid, organic,
and continuous. It resembles a giant, pristine white wave frozen in motion, or perhaps a sand dune
sculpted by an unseen wind.
<...>
  

詳しい手順を説明する

最初の試みで予想される結果が得られなかった場合は、より明確な手順を段階的に指定して Gemini を問題解決プロセスに導き、より的を絞ったアプローチでプロンプトを調整します。これにより、明示的な提案やガイダンスを通じて、モデルがタスクを初期段階で理解できるよう導くことができます。

Now imagine that architectural feature is not just for looks, but has a specific function or
purpose related to the building's environment or the people who use it. Explain what that
function could be and how it enhances the building's overall design and usability.
  
<...>
Let's imagine that the "floating roof" of the Heydar Aliyev Center is not purely aesthetic but
serves a crucial environmental and user-centric function: it's designed as a sophisticated climate
moderator and natural ventilation system for the Baku environment.

Here's how this function would work and enhance the building:

Function: Passive Climate Control and Natural Ventilation System

Shading and Solar Heat Mitigation: The undulating curves of the white GFRC roof are strategically
shaped and oriented to provide optimal shading throughout the day, year-round. Baku experiences
intense sun, especially during the summer. The overhanging curves, acting like giant brise-soleils,
would block direct sunlight from hitting the building's glass facade, significantly reducing solar
heat gain. The varying heights and depths of the curves would create dynamic shade patterns, ensuring
that different parts of the building are shaded at different times of the day, optimizing comfort
and reducing the need for excessive air conditioning. The white color of the GFRC further enhances
this by reflecting a large portion of the solar radiation.
<...>
  

思考を伴うマルチショット プロンプト

思考とマルチショット プロンプトを組み合わせると、Gemini の理解度がさらに高まり回答の精度が向上します。プロンプトで、希望する動作と出力形式を示す入出力ペアの例をいくつか提供します。

Example 1:
User: What is the tallest mountain in the world?
Assistant: Mount Everest

Example 2:
User: What is the largest ocean?
Assistant: Pacific Ocean

User: What is the longest river in the world?
Assistant:
  
Amazon River
  

出力と動作の定義

ユーザーがモデルと直接やり取りするアプリケーションを構築する場合は、Gemini の出力やレスポンスがどのように聞こえ、どのような形式になるのかについてのガイダンスを提供することをおすすめします。

システム指示

システム指示は、モデルがプロンプトを処理する前に処理する一連の指示です。システム指示は、モデルがプロンプトを受け取るたびに呼び出され、モデルの動作と応答方法を指示します。たとえば、ロールやペルソナ、コンテキスト情報、フォーマット手順などを指定できます。

System Instruction: You are a helpful and concise coding tutor. Always provide code examples and explain them briefly.

User Prompt: Explain what is a closure in Javascript and give an example.
  
    function outerFunction(outerVar) {
      function innerFunction(innerVar) {
        console.log(outerVar); // Accessing outerVar from outerFunction's scope
        console.log(innerVar);
      }
      return innerFunction;
    }

    const closureExample = outerFunction('I am from outer');
    closureExample('I am from inner');

Explanation:

A closure is created when a function (innerFunction in this example) is defined inside another function
(outerFunction) and the inner function remembers and has access to the variables from the outer
function's scope, even after the outer function has finished executing.

In the example:

outerFunction is called with 'I am from outer' and returns innerFunction.

closureExample now holds a reference to innerFunction.

When closureExample('I am from inner') is called, innerFunction executes.

Even though outerFunction has already finished, innerFunction can still access and use outerVar
(which is 'I am from outer') because of the closure.

In essence, the innerFunction "closes over" the variables of its outer function's scope, creating
a closure.
  

検証と振り返り

システム指示またはプロンプトに、具体的な検証手順を直接含めます。たとえば、Gemini にソースの確認、推論のレビュー、潜在的なエラーの特定、最終的な回答の確認を依頼します。

    Verify the following statement and provide your sources: The capital of Brazil is Rio de Janeiro.
  
The statement "The capital of Brazil is Rio de Janeiro" is incorrect.

The current capital of Brazil is Brasília.

Rio de Janeiro was the capital of Brazil for a significant period, from 1763 to 1960. However, the
capital was moved to Brasília in 1960 as part of a plan to develop the country's interior and create
a more centrally located capital.

Verification and Sources:

You can easily verify this information from numerous reliable sources:

Encyclopedias:

Britannica: Searching for "Brazil" on Britannica will clearly state Brasília as the capital.

https://www.britannica.com/place/Brazil (Look for the "Capital" information in the introductory summary or "Geography" section)

Wikipedia: The Wikipedia article for "Brazil" also states Brasília as the capital.

https://en.wikipedia.org/wiki/Brazil (Look in the infobox or introductory section)

Government and Official Sources:

CIA World Factbook: This is a highly reliable source for country information. Searching for "Brazil"
will list Brasília as the capital.

https://www.cia.gov/the-world-factbook/countries/brazil/ (Look under "Government" > "Capital")

Official Website of the Brazilian Government (if accessible and in English): While navigating official
government websites can sometimes be complex, they would definitively list Brasília as the capital.

Geographic Resources:

National Geographic: Their website and publications will confirm Brasília as the capital of Brazil.

Atlases and Geography Textbooks: Any modern atlas or geography textbook will list Brasília as the capital.

Why the confusion?

The confusion might arise because:

Rio de Janeiro is a very famous Brazilian city: It's a major tourist destination, known for its
beaches, Carnival, and iconic landmarks like Christ the Redeemer. Its past status as capital adds
to its historical significance and public recognition.

Historical context: Rio de Janeiro was the capital for a long time. People who learned about Brazil
in the past might remember it as the capital.

In conclusion, the statement is false. The capital of Brazil is Brasília, not Rio de Janeiro. Rio
de Janeiro was the former capital but is no longer the current capital.

You can confidently use the sources listed above to verify this information.
  

デバッグとステアリング

Vertex AI Studio では、デベロッパーが UI でモデルの思考にアクセスできます。これは、デバッグ時にプロンプトを確認するデベロッパーにとって便利です。

思考プロセスを分析する

Gemini の思考プロセスを注意深く検証し、逸脱している可能性のある箇所を特定します。この分析は、プロンプトを改善し、アプリケーションで期待どおりのレスポンスを常に得るための貴重な手がかりとなります。

シナリオ例: Gemini の思考プロセスで、複雑な指示のステップを誤解していることがわかった場合は、その特定のステップを明確にするようにプロンプトを改善できます。

Step 1: Summarize the following article about quantum physics.
Step 2: Translate the summary into Spanish.
Step 3: Extract the key entities from the Spanish summary.

Article: ... [Article Text] ...
The user wants me to process an article about Google's new quantum chip called Willow in three steps:
Step 1: Summarize the article.
Step 2: Translate the summary into Spanish.
Step 3: Extract the key entities from the Spanish summary.

Let's break down each step.

Step 1: Summarize the article.
I need to read the article and identify the main points. The article is about Google's new quantum
chip, Willow, and its achievements. The key achievements are:

Exponential error reduction as qubits scale up.

Outperforming supercomputers in a benchmark computation (RCS).

Willow is a step towards commercially relevant quantum computing.

It's the first system below threshold for quantum error correction.

It achieved a benchmark computation in under 5 minutes that would take a supercomputer 10 septillion years.

It was fabricated in a new facility.

It has state-of-the-art performance and high quality qubits.

Google is looking towards real-world applications with Willow.

Quantum computing will benefit AI.

I will synthesize these points into a concise summary.

Step 2: Translate the summary into Spanish.
Once I have the summary in English, I will translate it into Spanish. I need to ensure the translation
is accurate and natural-sounding in Spanish.

Step 3: Extract the key entities from the Spanish summary.
After translating the summary, I will identify and extract the key entities. Key entities are typically
nouns or noun phrases that represent important objects, concepts, or actors. In this context, they
will likely include:

Names of chips (Willow, Sycamore)

Companies/Organizations (Google Quantum AI, Google Research)

Technologies (quantum chip, quantum computer, qubits, quantum error correction, superconducting
quantum system, classical computers, supercomputers, AI)

Benchmarks (random circuit sampling, RCS)

People (Julian Kelly, Peter Shor, David Deutsch, Sergio Boixo, Hartmut Neven, John Preskill)

Concepts (exponential error reduction, below threshold, beyond breakeven, state-of-the-art performance,
commercially relevant applications, quantum mechanics, multiverse, T1 times, system benchmarks,
algorithmic benchmarks)

I will need to carefully review the Spanish summary to identify these entities and list them out.

Provide corrective feedback

If you observe errors or inconsistencies in Gemini's reasoning, provide corrective feedback in your prompt and the system instructions to anticipate where the model's response may deviate from your desired outcome.

You are an expert in botany. When asked to identify a plant, focus on leaf shape, flower structure, and stem characteristics.

Identify this plant based on these characteristics: ... [Plant Characteristics Description] ...

Previous incorrect response focused on habitat only. Please disregard habitat and focus on morphology.
Previous incorrect response focused on habitat only. Please disregard habitat and focus on morphology.
Tabebuia vellosoi

長い出力と長文の思考を最大限に活用する

思考は、Gemini の詳細な推論を示すトークン出力の一部として「思考」を生成します。これらの出力を最大限に活用するには:

推論を検証する

Gemini の推論プロセス(Vertex AI Studio UI で利用可能)、タスクの分解方法、出力の選択に細心の注意を払ってください。そうすることで、結論に至った経緯を把握できます。

推論のガイダンスを提供する

特に長い出力が必要な場合は、プロンプトでより多くのガイダンスを指定して、プロンプトで提示されたタスクを完了するために必要な思考量を制限することをおすすめします。これにより、レスポンス用にトークン出力をより多く予約できます。

*例: 詳細なレポートを作成する場合は、プロンプトでセクションとサブセクションを指定して、Gemini の思考を導き、出力を効率的に構造化します。

Generate a detailed report on the impact of climate change on coastal ecosystems.

Report Structure:

Introduction

Rising Sea Levels
2.1. Impact on Mangroves
2.2. Impact on Coral Reefs

Ocean Acidification
3.1. Impact on Shellfish
3.2. Impact on Plankton

Extreme Weather Events
4.1. Increased Storm Intensity
4.2. Coastal Erosion

Conclusion

Provide detailed analysis within each section.
<...>
Climate Change Impact on Coastal Ecosystems: A Detailed Report

1.  Introduction

Coastal ecosystems, the dynamic interface between land and sea, are among the most productive and
biodiverse environments on Earth. They provide crucial ecosystem services, including coastal protection,
fisheries, carbon sequestration, and support for a vast array of species. However, these vital
ecosystems are increasingly threatened by the multifaceted impacts of climate change. Driven by
anthropogenic greenhouse gas emissions, climate change is manifesting in several interconnected ways
that are profoundly altering the physical and chemical conditions of coastal environments. This report
will delve into the key impacts of climate change on coastal ecosystems, focusing on rising sea levels,
ocean acidification, and extreme weather events, and their specific consequences for critical habitats
like mangroves and coral reefs, and key organisms like shellfish and plankton. Understanding these
impacts is crucial for developing effective conservation and management strategies to mitigate the
damage and enhance the resilience of these invaluable ecosystems.

2.  Rising Sea Levels

Rising sea levels are a direct and significant consequence of global warming, driven by thermal
expansion of seawater and the melting of land ice (glaciers and ice sheets). This phenomenon poses a
direct threat to low-lying coastal ecosystems by inundating habitats, altering salinity regimes, and
increasing erosion rates. The rate of sea level rise is accelerating, and projections for the 21st
century indicate a continued upward trend, with potentially devastating consequences for coastal
environments.

2.1. Impact on Mangroves

Mangrove forests are unique coastal ecosystems found in tropical and subtropical intertidal zones.
They provide numerous benefits, including coastal protection against storms, nursery grounds for
fish and invertebrates, and significant carbon sequestration...
<...>

料金

モデルの思考プロセス中に生成されたトークンに対して課金されます。Gemini 3 Pro や Gemini 2.5 Pro などの一部のモデルでは、思考がデフォルトで有効になっており、これらのトークンに対して課金されます。

詳細については、Agent Platform の料金をご覧ください。費用の管理方法については、思考予算を制御するをご覧ください。

次のステップ

ノートブック

この Colab ノートブックで Gemini 2.5 Flash を使用して、Thinking、トークン化、コード実行などの機能を試してみましょう。

コンソール

Google Cloud コンソールで Gemini のプロンプトを試してみてください。

ガイド

思考シグネチャを使用して、マルチターンとマルチステップの会話中に Gemini の推論状態を保持する方法を学びます。