Skip to content

googleai: Add support for Gemini 3 thought_signature parameter #1464

Open

Description

@ElecTwix

Problem

When using Gemini 3 models (e.g., gemini-3-flash-preview), the API returns an error requiring a thought_signature parameter:

googleapi: Error 400: Thought signature is required for thinking models.
Please set `thought_signature` to a thought signature from a previous response,
or to `INCLUDE_THOUGHTS_NEW_CONVERSATION` to start a new conversation.

Gemini 3 introduced a new "thinking" feature where the model can show its reasoning process. This requires:

  1. Setting thought_signature: "INCLUDE_THOUGHTS_NEW_CONVERSATION" for new conversations
  2. Passing back the thought_signature from previous responses for follow-up messages

Proposed Solution

  1. Add ThoughtSignature option to googleai.Options
  2. Handle thought_signature in request building
  3. Parse and expose thought_signature from responses for multi-turn conversations
  4. Consider auto-handling for agentic loops (tool calling)

References

Workaround

Currently, use gemini-2.5-flash or gemini-2.5-pro which don't require thought signatures.

Activity

  1. ju4nv1e1r4 commented on Jan 23, 2026

    @ju4nv1e1r4

    Hi everyone,

    I started looking into implementing the ThoughtSignature support for Gemini 3.0, but I hit a blocker regarding our current dependency.

    langchaingo is currently using the legacy github.com/google/generative-ai-go SDK. According to Google's official notice, this SDK reached End-of-Life on Nov 30, 2025, and is in "critical bug fixes only" mode. New features like Gemini 3.0's "Thinking" capabilities are exclusively available in the new unified SDK (google.golang.org/genai).

    Conclusion: We cannot implement this feature on the current driver.

    Proposal: instead of refactoring the existing llms/googleai package (which would be a massive breaking change), I propose we create a new provider package (e.g., llms/google_genai or llms/googleai_v2) using the new SDK. This would allow users to access Gemini 3.0 features immediately while keeping backward compatibility for the legacy implementation until we decide to drop it.

    @maintainers, does this approach align with your roadmap? If so, I can start scaffolding the new provider.

  2. ju4nv1e1r4 commented on Jan 23, 2026

    @ju4nv1e1r4

    Guys, I've confirmed it. The legacy SDK doesn't support Gemini 3.0 Thinking mode because it doesn't expose the necessary thinking signatures for multi-turn.

    I created a Proof of Concept (PoC) with the new SDK (google.golang.org/genai) and managed to maintain the context by passing the raw genai.Part objects in the history.

    Minimum code for PoC:

    package main
    
    import (
    	"context"
    	"encoding/json"
    	"fmt"
    	"log"
    	"os"
    
    	"google.golang.org/genai"
    )
    
    const modelName = "gemini-3-pro-preview" 
    
    func main() {
    	ctx := context.Background()
    	apiKey := os.Getenv("GEMINI_API_KEY")
    	if apiKey == "" {
    		log.Fatal("Please, define your Gemini API Key as GEMINI_API_KEY")
    	}
    
    	client, err := genai.NewClient(ctx, &genai.ClientConfig{
    		APIKey:  apiKey,
    		Backend: genai.BackendGeminiAPI,
    	})
    	if err != nil {
    		log.Fatal(err)
    	}
    
    	fmt.Println("Turn #1] Sending question...")
    	
    	prompt := "Explain why sky is blue, but include a detailed thoughts about Rayleigh scattering before."
    
    	resp1, err := client.Models.GenerateContent(ctx, modelName, 
    		genai.Text(prompt), 
    		&genai.GenerateContentConfig{
    			ThinkingConfig: &genai.ThinkingConfig{
    				IncludeThoughts: true,
    			},
    		},
    	)
    	if err != nil {
    		log.Fatalf("Turn #1 error: %v", err)
    	}
    
    	var modelResponseParts []*genai.Part
    	
    	fmt.Println("\n--- Resposta do Modelo (Turno 1) ---")
    	for _, cand := range resp1.Candidates {
    		modelResponseParts = cand.Content.Parts
    		
    		for _, part := range cand.Content.Parts {
    			if part.Thought {
    				fmt.Printf("[THOUGHTS]: %s\n", part.Text)
    			} else {
    				fmt.Printf("[ANSWER]: %s\n", part.Text)
    			}
    			
    		}
    	}
    
    
    	fmt.Println("\n\n[Turn #2] Sending follow-up...")
    	
    	history := []*genai.Content{
    		{Role: "user", Parts: []*genai.Part{{Text: prompt}}},
    		{Role: "model", Parts: modelResponseParts}, // <--- HERE IS  SIGNATURE
    	}
    
            // NEW QUESTION
    	followUp := "And why it gets red at sunsets?"
    
    	reqContent := append(history, &genai.Content{
    		Role: "user", 
    		Parts: []*genai.Part{{Text: followUp}},
    	})
    
    	resp2, err := client.Models.GenerateContent(ctx, modelName, 
    		reqContent, // WHOLE STUFF WITH DIRTY PARTS OF SIGNATURE
    		&genai.GenerateContentConfig{
    			ThinkingConfig: &genai.ThinkingConfig{
    				IncludeThoughts: true,
    			},
    		},
    	)
    
    	if err != nil {
    		log.Fatalf("Turn #2 error (maybe signature absence problem): %v", err)
    	}
    
    	fmt.Println("\n--- Model's Response (Turn #2) ---")
    	for _, cand := range resp2.Candidates {
    		for _, part := range cand.Content.Parts {
    			if part.Thought {
    				fmt.Printf("[THOUGHTS #2]: %s\n", part.Text)
    			} else {
    				fmt.Printf("[ANSWER #2]: %s\n", part.Text)
    			}
    		}
    	}
    	
    	fmt.Println("\nSUCCESS: Conversation keeped without 400 error!")
    }
    
    // Helper to struct debugging
    func debugStruct(v interface{}) {
    	b, _ := json.MarshalIndent(v, "", "  ")
    	fmt.Println(string(b))
    }

    For LangChainGo, we will need to store these Parts in the Metadata field of the LangChain messages, since the content string is not sufficient.

  3. sunyan1120 commented on Feb 28, 2026

    @sunyan1120

    (e.g., llms/google_genai or llms/googleai_v2) Hi, When is this new SDK expected to go live

  4. ju4nv1e1r4 commented on Feb 28, 2026

    @ju4nv1e1r4

    (e.g., llms/google_genai or llms/googleai_v2) Hi, When is this new SDK expected to go live

    I really want to implement it but I think it's more appropriate to wait for maintainers opinion about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions