GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Changing ThinkingConfig (thinking_level / thinking_budget) mid-conversation invalidates implicit prompt cache prefix · Issue #3412 · googleapis/python-genai

Changing ThinkingConfig (thinking_level / thinking_budget) mid-conversation invalidates implicit prompt cache prefix #3412

New issue
Copy link
New issue
Copy link
Open
Open
Changing ThinkingConfig (thinking_level / thinking_budget) mid-conversation invalidates implicit prompt cache prefix#3412
Copy link
Assignees
Venkaiahbabuneelam
Labels
priority: p3Desirable enhancement or fix. May not be included in next release.status:awaiting user responsetype: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Description

@DUCKJAIII
DUCKJAIII
opened on Nov 23, 2026
Issue body actions

Environment

  • SDK: google-genai (Vertex AI backend, vertexai=True)
  • Feature: Implicit Context Caching + GenerateContentConfig.thinking_config (thinking_level / thinking_budget)

Description

In multi-turn agentic conversations using implicit context caching on Vertex AI, changing thinking_config.thinking_level (for example from "MEDIUM" to "LOW" and back) between turns on the exact same conversation prefix invalidates the active implicit prompt cache bucket:

  1. Turns 1–2 (thinking_level="MEDIUM"): cached_content_token_count = 26,655, uncached prompt_token_count = 3,441 (warm "MEDIUM" cache prefix).
  2. Turn 3 (switch to thinking_level="LOW", identical system instruction, tools, and message history prefix): cached_content_token_count = 0, uncached prompt_token_count = 32,871 (100% cache miss).
  3. Turns 4–19 (staying on thinking_level="LOW"): cached_content_token_count grows monotonically from 30,822 to 72,541 (prompt_token_count ~2,300–4,600 per turn).
  4. Turn 20 (switch back to thinking_level="MEDIUM"): cached_content_token_count = 30,097, uncached prompt_token_count = 47,828 (misses the entire 42.4k-token "LOW" prefix accumulated across Turns 3–19 and falls back to the older "MEDIUM" prefix from Turn 2).
  5. Turn 21 (switch back to thinking_level="LOW"): cached_content_token_count = 75,469, uncached prompt_token_count = 7,076 (re-attaches to the "LOW" cache bucket).

Expected vs. Actual Behavior

  • Actual: thinking_config appears to be injected/hashed ahead of system_instruction, tools, and contents in the implicit KV-cache key, partitioning the implicit cache into separate buckets per thinking_level / thinking_budget. Dynamically routing simpler turns to "LOW" thinking and complex turns to "MEDIUM"/"HIGH" thinking within one session therefore costs more in uncached input tokens than keeping thinking fixed at the higher level.
  • Requested:
    1. Document in the google-genai ThinkingConfig docstring and Vertex AI / Gemini API implicit-caching documentation that thinking_config must remain constant across turns to preserve implicit cache hits on the conversation history prefix.
    2. If feasible on the serving side, apply thinking_config at the generation boundary (after the shared system_instruction + tools + historical contents prefix) so changing thinking_level for the current turn can still reuse the cached historical KV prefix.

Activity

  1. Venkaiahbabuneelam
    self-assigned this
    on Nov 23, 2026
  2. Venkaiahbabuneelam
    added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    priority: p3Desirable enhancement or fix. May not be included in next release.
    on Nov 23, 2026
  3. Venkaiahbabuneelam commented on Nov 23, 2026

    @Venkaiahbabuneelam
    Venkaiahbabuneelam
    on Nov 23, 2026
    More actions

    Hi @DUCKJAIII,

    In Vertex AI and Gemini implicit prompt caching, generation configurations (including thinking_config parameters like thinking_level and thinking_budget) are incorporated into the prefix cache key and internal prompt prefill framing, which isolates the KV cache per configuration.

    To maintain high cache hit rates across multi-turn sessions under the current serving architecture, keep thinking_config constant throughout the conversation:

    from google import genai
    from google.genai import types
    
    client = genai.Client(vertexai=True, project="YOUR_PROJECT_ID", location="us-central1")
    
    # Keep thinking_config fixed across the conversation session
    session_config = types.GenerateContentConfig(
        thinking_config=types.ThinkingConfig(thinking_level="MEDIUM"),
        system_instruction="You are a helpful coding assistant.",
    )
    
    chat = client.chats.create(model="gemini-3.5-flash", config=session_config)
    response1 = chat.send_message("First turn prompt")
    response2 = chat.send_message("Second turn prompt")

    For more details on prefix matching requirements, see the Vertex AI Context Caching documentation.

    Thanks

  4. Venkaiahbabuneelam
    added
    status:awaiting user response
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @Venkaiahbabuneelam
    Venkaiahbabuneelam

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.status:awaiting user responsetype: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.