fix(provider): generalize Claude adaptive thinking (#38757)

This commit is contained in:
Aiden Cline
2026-07-24 16:44:00 -05:00
committed by GitHub
parent 7840562d1b
commit 2b2aacc939
2 changed files with 145 additions and 20 deletions
@@ -3213,6 +3213,7 @@ describe("ProviderTransform.reasoningVariants", () => {
{ thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
"claude-opus-4-7",
],
["@ai-sdk/anthropic", { thinking: { type: "adaptive", display: "summarized" }, effort: "high" }, "claude-opus-5"],
["@ai-sdk/google", { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } }],
["@ai-sdk/google-vertex", { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } }],
[
@@ -3264,13 +3265,18 @@ describe("ProviderTransform.reasoningVariants", () => {
)
})
test("uses bare effort for Claude Opus 4.5", () => {
test("combines effort with extended thinking for Claude Opus 4.5", () => {
expect(
ProviderTransform.reasoningVariants(
model([{ type: "effort", values: ["high"] }]),
target("@ai-sdk/anthropic", "claude-opus-4-5"),
),
).toEqual({ high: { effort: "high" } })
).toEqual({
high: {
thinking: { type: "enabled", budgetTokens: 16_000 },
effort: "high",
},
})
})
test("uses explicit effort metadata for Anthropic-compatible models", () => {
@@ -3319,6 +3325,38 @@ describe("ProviderTransform.reasoningVariants", () => {
})
})
test("uses adaptive reasoning config for Claude Opus 5 on Bedrock", () => {
const result = ProviderTransform.reasoningVariants(
model([{ type: "effort", values: ["low", "medium", "high", "xhigh", "max"] }]),
target("@ai-sdk/amazon-bedrock", "us.anthropic.claude-opus-5"),
)
expect(Object.keys(result ?? {})).toEqual(["low", "medium", "high", "xhigh", "max"])
expect(result?.high).toEqual({
reasoningConfig: {
type: "adaptive",
maxReasoningEffort: "high",
display: "summarized",
},
})
})
test("combines effort with extended thinking for Claude Opus 4.5 on Bedrock", () => {
expect(
ProviderTransform.reasoningVariants(
model([{ type: "effort", values: ["high"] }]),
target("@ai-sdk/amazon-bedrock", "us.anthropic.claude-opus-4-5-20251101-v1:0"),
),
).toEqual({
high: {
reasoningConfig: {
type: "enabled",
budgetTokens: 16_000,
maxReasoningEffort: "high",
},
},
})
})
test("does not replace unsupported Anthropic Bedrock effort options with token budgets", () => {
expect(
ProviderTransform.reasoningVariants(
@@ -4617,11 +4655,17 @@ describe("ProviderTransform.variants", () => {
describe("@ai-sdk/anthropic", () => {
for (const testCase of [
{
name: "opus 4 dated",
apiIds: ["claude-opus-4-20250514"],
efforts: ["high", "max"],
expectedHigh: { thinking: { type: "enabled", budgetTokens: 16000 } },
},
{
name: "opus 4.5",
apiIds: ["claude-opus-4-5-20251101", "claude-opus-4.5-20251101"],
efforts: ["low", "medium", "high"],
expectedHigh: { effort: "high" },
expectedHigh: { thinking: { type: "enabled", budgetTokens: 16000 }, effort: "high" },
},
{
name: "sonnet 4.6",
@@ -4653,6 +4697,18 @@ describe("ProviderTransform.variants", () => {
efforts: ["low", "medium", "high", "xhigh", "max"],
expectedHigh: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
},
{
name: "opus 5",
apiIds: ["claude-opus-5", "claude-opus-5-20260724"],
efforts: ["low", "medium", "high", "xhigh", "max"],
expectedHigh: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
},
{
name: "unversioned future model",
apiIds: ["claude-future"],
efforts: ["low", "medium", "high", "xhigh", "max"],
expectedHigh: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
},
{
name: "fable 5",
apiIds: ["claude-fable-5"],
@@ -4772,6 +4828,28 @@ describe("ProviderTransform.variants", () => {
effort: "high",
})
})
test("opus 5 uses adaptive reasoning for Vertex model IDs", () => {
const result = ProviderTransform.variants(
createMockModel({
id: "google-vertex-anthropic/claude-opus-5@default",
providerID: "google-vertex-anthropic",
api: {
id: "claude-opus-5@default",
url: "https://us-central1-aiplatform.googleapis.com",
npm: "@ai-sdk/google-vertex/anthropic",
},
}),
)
expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
expect(result.high).toEqual({
thinking: {
type: "adaptive",
display: "summarized",
},
effort: "high",
})
})
})
describe("@ai-sdk/amazon-bedrock", () => {
@@ -4867,6 +4945,28 @@ describe("ProviderTransform.variants", () => {
})
})
test("anthropic opus 5 returns adaptive reasoning options with xhigh", () => {
const result = ProviderTransform.variants(
createMockModel({
id: "bedrock/anthropic-claude-opus-5",
providerID: "bedrock",
api: {
id: "us.anthropic.claude-opus-5-v1:0",
url: "https://bedrock.amazonaws.com",
npm: "@ai-sdk/amazon-bedrock",
},
}),
)
expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
expect(result.high).toEqual({
reasoningConfig: {
type: "adaptive",
maxReasoningEffort: "high",
display: "summarized",
},
})
})
test("returns WIDELY_SUPPORTED_EFFORTS with reasoningConfig", () => {
const model = createMockModel({
id: "bedrock/llama-4",
@@ -5055,6 +5155,12 @@ describe("ProviderTransform.variants", () => {
efforts: ["low", "medium", "high", "xhigh", "max"],
thinking: { type: "adaptive", display: "summarized" },
},
{
name: "opus 5",
apiIds: ["anthropic--claude-opus-5", "anthropic--claude-5-opus"],
efforts: ["low", "medium", "high", "xhigh", "max"],
thinking: { type: "adaptive", display: "summarized" },
},
]) {
for (const apiId of testCase.apiIds) {
test(`${testCase.name} ${apiId} returns adaptive thinking variants under modelParams`, () => {