langchain - ✅(Solved) Fix Support adaptive thinking mode for Anthropic models [1 pull requests, 4 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#36288Fetched 2026-04-08 01:36:07
View on GitHub
Comments
4
Participants
3
Timeline
19
Reactions
0
Timeline (top)
commented ×4mentioned ×4subscribed ×4labeled ×3

Root Cause

In our agentic use cases we have started using Opus 4.6 with adaptive thinking. For example:

llm = init_chat_model(
  model="anthropic:claude-opus-4.6-1m",
  temperature=1,
  max_tokens=128000,
  ...
  thinking={
    "type": "adaptive",
  },
)
...
response = llm.invoke([HumanMessage(content=...)])

We have noticed that in some cases that response.content is malformed and looks like this ['', {'type': 'thinking', ...}, "Actual response..."] and this translates in response.content_blocks only containing reasoning content. This is because the actual response is not a dict of type text.

PR fix notes

PR #36293: feat(anthropic): support adaptive thinking mode

Description (problem / solution / changelog)

Fixes #36288

Anthropic have added support for adaptive thinking for Claude Opus 4.6 and Sonnet 4.6. With this addition, thinking.type: "enabled" and budget_tokens are deprecated in favor of thinking.type: "adaptive".

We update ChatAnthropic to treat "adaptive" the same as "enabled" in all code paths that check the thinking type (structured output, token counting, etc.).

Validation:

  • Added unit tests for adaptive thinking (invoke, streaming, structured output)
  • All existing tests continue to pass

Unit tests were written with AI assistance (Claude Code).

Changed files

  • libs/partners/anthropic/langchain_anthropic/chat_models.py (modified, +6/-3)
  • libs/partners/anthropic/tests/unit_tests/test_chat_models.py (modified, +61/-0)

Code Example

def _thinking_in_params(params: dict) -> bool:
    return params.get("thinking", {}).get("type") == "enabled"

---

def _thinking_in_params(params: dict) -> bool:
    return params.get("thinking", {}).get("type") in ("enabled", "adaptive")

---

llm = init_chat_model(
  model="anthropic:claude-opus-4.6-1m",
  temperature=1,
  max_tokens=128000,
  ...
  thinking={
    "type": "adaptive",
  },
)
...
response = llm.invoke([HumanMessage(content=...)])

---

def _thinking_in_params(params: dict) -> bool:
    return params.get("thinking", {}).get("type") == "enabled"

---

def _thinking_in_params(params: dict) -> bool:
    return params.get("thinking", {}).get("type") in ("enabled", "adaptive")
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a feature request, not a bug report or usage question.
  • I added a clear and descriptive title that summarizes the feature request.
  • I used the GitHub search to find a similar feature request and didn't find it.
  • I checked the LangChain documentation and API reference to see if this feature already exists.
  • This is not related to the langchain-community package.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Feature Description

Hello! Anthropic has added support for adaptive thinking for Claude Opus 4.6 and Sonnet 4.6. I propose we update the chat_models.py file to take into account adaptive thinking wherever there is validation for thinking.

As an example we should change:

def _thinking_in_params(params: dict) -> bool:
    return params.get("thinking", {}).get("type") == "enabled"

to

def _thinking_in_params(params: dict) -> bool:
    return params.get("thinking", {}).get("type") in ("enabled", "adaptive")

This validation should be extended in all places applicable.

Optional: we could also add a comment that enabled is marked for deprecation and will be removed in the future.

Use Case

In our agentic use cases we have started using Opus 4.6 with adaptive thinking. For example:

llm = init_chat_model(
  model="anthropic:claude-opus-4.6-1m",
  temperature=1,
  max_tokens=128000,
  ...
  thinking={
    "type": "adaptive",
  },
)
...
response = llm.invoke([HumanMessage(content=...)])

We have noticed that in some cases that response.content is malformed and looks like this ['', {'type': 'thinking', ...}, "Actual response..."] and this translates in response.content_blocks only containing reasoning content. This is because the actual response is not a dict of type text.

When we change from adaptive thinking back to enabled it works.

We have started investigating this and this has lead us to look into the langchain repository and we found out that the Anthropic chat model only checks that thinking is enabled and not adaptive.

Proposed Solution

Wherever there is validation that thinking is enabled:

def _thinking_in_params(params: dict) -> bool:
    return params.get("thinking", {}).get("type") == "enabled"

we expand the validation to check that thinking is adaptive:

def _thinking_in_params(params: dict) -> bool:
    return params.get("thinking", {}).get("type") in ("enabled", "adaptive")

We also propose to add / extend unit tests where applicable.

Alternatives Considered

Using enabled instead of adaptive works around the issue, but adaptive is the recommended thinking mode going forward. enabled will also be deprecated in the future so it's not a long term solution.

Additional Context

Anthropic API docs on adaptive thinking: https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking

extent analysis

Fix Plan

To fix the issue, we need to update the chat_models.py file to account for adaptive thinking. Here are the steps:

  • Update the _thinking_in_params function to check for both "enabled" and "adaptive" thinking types.
  • Add a comment to mark "enabled" as deprecated and to be removed in the future.
  • Extend unit tests to cover the new thinking type.

Code Changes

def _thinking_in_params(params: dict) -> bool:
    # enabled is marked for deprecation and will be removed in the future
    return params.get("thinking", {}).get("type") in ("enabled", "adaptive")

Additionally, we need to update the response.content parsing to handle the new format returned by the Anthropic API when using adaptive thinking.

Verification

To verify the fix, test the init_chat_model function with the thinking parameter set to "adaptive" and check that the response.content is correctly parsed.

Extra Tips

  • Make sure to update the documentation to reflect the changes and deprecation of the "enabled" thinking type.
  • Consider adding a warning or log message when the "enabled" thinking type is used to encourage users to switch to "adaptive".

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING