Gemini-Denken

Die Modelle der Gemini 3- und 2.5-Serie verwenden einen „Denkprozess“, der ihre Fähigkeiten zum logischen Schlussfolgern und zur mehrstufigen Planung erheblich verbessert. Dadurch sind sie sehr effektiv für komplexe Aufgaben wie Programmieren, fortgeschrittene Mathematik und Datenanalyse.

Wenn Sie ein Thinking Model verwenden, führt Gemini intern einen Denkprozess durch, bevor es antwortet. Die Interactions API stellt diesen Denkprozess über thought-Schritte dar. Das sind spezielle Schritte, die chronologisch neben Funktionsaufrufen, Nutzereingaben oder Modellausgaben im steps-Array angezeigt werden.

Jeder Denkprozessschritt enthält zwei Felder:

Feld Erforderlich? Beschreibung
signature ✅ Ja Eine verschlüsselte Darstellung des internen Denkprozesses des Modells. Immer vorhanden, auch wenn das Modell nur minimal logisch schlussfolgert.
summary ❌ Nein Ein Array mit Inhalten (Text und/oder Bilder), in dem der Denkprozess zusammengefasst wird. Je nach thinking_summaries-Konfiguration, ob das Modell ausreichend logisch schlussgefolgert hat oder nicht, oder dem Inhaltstyp kann es leer sein. Für Bild-Latents gibt es beispielsweise keine Textzusammenfassungen.

Interaktionen mit Thinking

Das Initiieren einer Interaktion mit einem Thinking Model ähnelt jeder anderen Interaktionsanfrage. Geben Sie im model Feld eines der Modelle mit Thinking-Unterstützung an:

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.6-flash",
    input="Explain the concept of Occam's Razor and provide a simple, everyday example."
)
print(interaction.output_text)

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: "gemini-3.6-flash",
    input: "Explain the concept of Occam's Razor and provide a simple, everyday example."
});
console.log(interaction.output_text);

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.6-flash",
    "input": "Explain the concept of Occam'\''s Razor and provide a simple example."
  }'

Zusammenfassungen der Gedanken

Zusammenfassungen der Gedanken geben Einblicke in den internen Denkprozess des Modells. Standardmäßig wird nur die endgültige Ausgabe zurückgegeben. Sie können Zusammenfassungen der Gedanken mit thinking_summaries aktivieren:

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.6-flash",
    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

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: "gemini-3.6-flash",
    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

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.6-flash",
    "input": "What is the sum of the first 50 prime numbers?",
    "generation_config": {
      "thinking_summaries": "auto"
    }
  }'

Ein Denkprozessblock kann in den folgenden Fällen nur eine Signatur ohne Zusammenfassung enthalten:

  • Einfache Anfragen, bei denen das Modell nicht ausreichend logisch schlussgefolgert hat, um eine Zusammenfassung zu erstellen
  • thinking_summaries: "none", wobei Zusammenfassungen explizit deaktiviert sind
  • Bestimmte Arten von Denkprozessinhalten, z. B. Bilder, haben möglicherweise keine Textzusammenfassungen

Ihr Code sollte immer Denkprozessblöcke verarbeiten können, bei denen summary leer oder nicht vorhanden ist.

Streaming mit Thinking

Verwenden Sie Streaming, um während der Generierung schrittweise Zusammenfassungen der Gedanken zu erhalten. Denkprozessblöcke werden mit vom Server gesendeten Ereignissen (SSE) mit zwei verschiedenen Deltatyps geliefert:

Deltatyp Enthält Wann werden die Daten gesendet?
thought_summary Text- oder Bildzusammenfassung Ein oder mehrere Deltas mit schrittweiser Zusammenfassung
thought_signature Die kryptografische Signatur Das letzte Delta vor step.stop

Python

from google import genai

client = genai.Client()

prompt = """
Alice, Bob, and Carol each live in a different house on the same street: red, green, and blue.
Alice does not live in the red house.
Bob does not live in the green house.
Carol does not live in the red or green house.
Which house does each person live in?
"""

thoughts = ""
answer = ""

stream = client.interactions.create(
    model="gemini-3.6-flash",
    input=prompt,
    generation_config={
        "thinking_summaries": "auto"
    },
    stream=True
)

for event in stream:
    if event.event_type == "step.delta":
        if event.delta.type == "thought_summary":
            if not thoughts:
                print("Thinking...")
            summary_text = event.delta.content.text
            print(f"[Thought] {summary_text}", end="")
            thoughts += summary_text
        elif event.delta.type == "text" and event.delta.text:
            if not answer:
                print("\nAnswer:")
            print(event.delta.text, end="")
            answer += event.delta.text

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const prompt = `Alice, Bob, and Carol each live in a different house on the same
street: red, green, and blue. Alice does not live in the red house.
Bob does not live in the green house.
Carol does not live in the red or green house.
Which house does each person live in?`;

let thoughts = "";
let answer = "";

const stream = await client.interactions.create({
    model: "gemini-3.6-flash",
    input: prompt,
    generation_config: {
        thinking_summaries: "auto"
    },
    stream: true
});

for await (const event of stream) {
    if (event.event_type === "step.delta") {
        if (event.delta.type === "thought_summary") {
            if (!thoughts) console.log("Thinking...");
            const text = event.delta.content?.text || "";
            process.stdout.write(`[Thought] ${text}`);
            thoughts += text;
        } else if (event.