fix(vertexai): recognize "adaptive" thinking in _thinking_in_params#1820
Open
Humphrey (HumphreySun98) wants to merge 1 commit into
Open
Conversation
`_thinking_in_params` in `_anthropic_utils.py` only matched `thinking.type == "enabled"`, so when callers used `thinking.type = "adaptive"` (Anthropic's recommended thinking mode for Claude 4.6+ and the only mode supported by Claude Opus 4.7) the helper returned `False`. In `model_garden.py` that wired `coerce_content_to_string = True` for both `_generate` and `_stream`, and the response's structured thinking blocks were silently flattened to a plain string. Match `"adaptive"` alongside `"enabled"` so adaptive-thinking responses keep their thinking blocks intact. Adds a regression unit test for the adaptive case next to the existing `enabled` / `disabled` ones. Fixes langchain-ai#1711
This was referenced Jun 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
_thinking_in_paramsinlibs/vertexai/langchain_google_vertexai/_anthropic_utils.pyonly matchedthinking.type == "enabled". When callers setthinking.type = "adaptive"— Anthropic's recommended thinking mode for Claude 4.6+, and the only mode supported by Claude Opus 4.7 — the helper returnsFalse. Inmodel_garden.py(and the streaming counterpart at L520), that flipscoerce_content_to_stringtoTruefor both_generateand_stream, so the response's structured thinking blocks get silently flattened to a plain string. Net effect:ChatAnthropicVertexcannot return thinking blocks for Claude Opus 4.7 at all.The fix is to match
"adaptive"alongside"enabled":Relevant issues
Fixes #1711
Type
🐛 Bug Fix
Changes
libs/vertexai/langchain_google_vertexai/_anthropic_utils.py: accept both"enabled"and"adaptive".libs/vertexai/tests/unit_tests/test_anthropic_utils.py: addtest_thinking_in_params_adaptivenext to the existingenabled/disabledcases.Testing
Reverting only the one-line
_anthropic_utils.pychange while keeping the new test makes that test fail withAssertionError, confirming the regression coverage pins the buggy behavior.ruff checkandruff format --checkpass on both files.Note
The fix is intentionally minimal — a tuple-membership check that mirrors what the issue reporter proposed. No behavior changes for callers using
"enabled"or any other value.Disclaimer: this PR was prepared with the assistance of an AI agent (Claude Code). All code and test changes were reviewed by the author before submission.