View a markdown version of this page

适应性思维 - Amazon Bedrock

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

适应性思维

自适应思维可以根据每个请求的复杂性Claude动态决定何时考虑以及考虑多少,而不是需要固定的思维代币预算。Claude Fable 5.1、Claude Mythos 5.1、Claude Opus 5、Claude Sonnet 5 和其他具有思维能力的模型都支持它。与固定思维相比,适应性思维可以可靠地推动更好的表现budget_tokens。不需要测试版标题。

支持的模型如下所示:

模型 模型 ID

Claude Fable 5.1

anthropic.claude-fable-5-1

Claude Mythos 5.1

anthropic.claude-mythos-5-1

Claude Opus 5

anthropic.claude-opus-5

克劳德十四行诗 5

anthropic.claude-sonnet-5

Claude Mythos 5

anthropic.claude-mythos-5

Claude Fable 5

anthropic.claude-fable-5

Claude Opus4.7

anthropic.claude-opus-4-7

Claude Mythos 预览

anthropic.claude-mythos-preview

Claude Opus4.6

anthropic.claude-opus-4-6-v1

克劳德十四行诗 4.6

anthropic.claude-sonnet-4-6

注意

Claude Fable 5.1、Claude Mythos 5.1、Claude Mythos 5、Claude Fable 5 和 Claude Mythos Preview 仅支持自适应思维。 这些模型不支持手动扩展思考(thinking.type: "enabled"使用 budget_tokensthinking.type: "disabled")和禁用思维(),将返回 400 错误。thinking.type: "adaptive"与一起使用output_config.effort可控制思维行为。

Claude Opus4.7 支持适应性思维和残障思维。要关闭思考,请使用thinking.type: "disabled"。不支持手动扩展思考(thinking.type: "enabled"使用budget_tokens),将返回 400 错误。

thinking.type: "enabled"并budget_tokens在 Claude Opus 4.6 和 Claude Sonnet 4.6 中已弃用,并将在未来的模型版本中删除。改为thinking.type: "adaptive"与努力参数一起使用。

较旧的模型(Claude Sonnet 4.5、Claude Opus 4.5 等)不支持自适应思维,需要thinking.type: "enabled"使用budget_tokens。

重要

在 Claude Sonnet 5 和 Claude Opus 5 中,自适应思维默认处于启用状态。省略thinking字段的请求采用自适应思维。这与 Claude Sonnet 4.6 有所不同,后者在没有经过深思熟虑的情况下运行相同的请求,因此,即使请求正文没有更改,从 Claude Sonnet 4.6 迁移的应用程序仍会生成思维输出——并将这些思维令牌作为输出代币计费。

要完全放弃对这些模型的思考,请"thinking": {"type": "disabled"}明确传递。省略该thinking领域并不会关闭思维——它会选择适应性思维。将 “不思考” 表示为零或减少的思维代币预算的客户端设置也不会将其关闭:thinking.type: "enabled"Claude Sonnet 5 不支持 with 并返回 a。budget_tokens ValidationException只有露骨的disabled类型才能阻止思考。

因为max_tokens这是对总输出(思考加回复文本)的硬性限制,请重新审视max_tokens以前不加思索地运行的工作负载。如果你在 Claude Sonnet 4.6 中使用了禁用思维,可以考虑在 Claude Sonnet 5 上使用较低output_config.effort等级的自适应思维,而不是禁用它。

适应性思维是如何运作的

在自适应模式下,Claude评估每个请求的复杂性并决定是否要考虑以及考虑多少。在默认努力级别 (high) 下,几乎总是Claude会思考。在较低的努力水平下,Claude可能会跳过思考更简单的问题。

适应性思维也可以自动启用交替思考(测试版)。这意味着Claude可以在工具调用之间进行思考,使其对代理工作流程特别有效。

"adaptive"在您的 API 请求中设置thinking.type为:

CLI
aws bedrock-runtime invoke-model \ --model-id "us.anthropic.claude-opus-4-6-v1" \ --body '{ "anthropic_version": "bedrock-2023-05-31", "max_tokens": 16000, "thinking": { "type": "adaptive" }, "messages": [ { "role": "user", "content": "Three players A, B, C play a game. Each has a jar with 100 balls numbered 1-100. Simultaneously, each draws one ball. A beats B if As number > Bs number (mod 100, treating 100 as 0 for comparison). Similarly for B vs C and C vs A. The overall winner is determined by majority of pairwise wins (ties broken randomly). Is there a mixed strategy Nash equilibrium where each player draws uniformly? If not, characterize the equilibrium." } ] }' \ --cli-binary-format raw-in-base64-out \ output.json && cat output.json | jq '.content[] | {type, thinking: .thinking[0:200], text}'
Python
import boto3 import json bedrock_runtime = boto3.client( service_name='bedrock-runtime', region_name='us-east-2' ) response = bedrock_runtime.invoke_model( modelId="us.anthropic.claude-opus-4-6-v1", body=json.dumps({ "anthropic_version": "bedrock-2023-05-31", "max_tokens": 16000, "thinking": { "type": "adaptive" }, "messages": [{ "role": "user", "content": "Explain why the sum of two even numbers is always even." }] }) ) response_body = json.loads(response["body"].read()) for block in response_body["content"]: if block["type"] == "thinking": print(f"\nThinking: {block['thinking']}") elif block["type"] == "text": print(f"\nResponse: {block['text']}")
TypeScript
import { BedrockRuntimeClient, InvokeModelCommand } from "@aws-sdk/client-bedrock-runtime"; async function main() { const client = new BedrockRuntimeClient({}); const command = new InvokeModelCommand({ modelId: "us.anthropic.claude-opus-4-6-v1", body: JSON.stringify({ anthropic_version: "bedrock-2023-05-31", max_tokens: 16000, thinking: { type: "adaptive" }, messages: [{ role: "user", content: "Explain why the sum of two even numbers is always even." }] }) }); const response = await client.send(command); const responseBody = JSON.parse(new TextDecoder().decode(response.body)); for (const block of responseBody.content) { if (block.type === "thinking") { console.log(`\nThinking: ${block.thinking}`); } else if (block.type === "text") { console.log(`\nResponse: ${block.text}`); } } } main().catch(console.error);

使用努力参数进行适应性思考

你可以将适应性思维与努力参数相结合,以指导思考的Claude效果。努力水平可作为思维分配Claude的软指导:

工作量级别 思维行为
max Claude始终不受思维深度限制地思考。Claude Opus支持 4.6、Claude Sonnet 4.6 和 Claude Opus 5。maxmax在不支持的模型上使用的请求会返回错误。
xhigh Claude始终以更深的深度思考。仅限 Claude Opus 5 和 Claude Opus 4.6。
high(默认值) Claude总是在想。为复杂任务提供深度推理。
medium Claude使用适度的思维。对于非常简单的查询,可能会跳过思考。
low Claude最大限度地减少思考。无需思考速度最重要的简单任务。
重要

effort参数必须放置在请求正文中的单独output_config对象内,而不是放置在thinking对象内。放置在effort里面thinking会导致ValidationException.

重要

思维被禁用时的努力上限(Claude Opus 5):Claude Opus 5 支持"thinking": {"type": "disabled"},但当思维被禁用时,output_config.effort上限为。high如果请求xhigh或max努力与思维障碍相结合,将返回invalid_request_error. 此上限还适用于通过对话中间系统消息设定的每回合努力量。要使用xhigh或max努力,请启用自适应思维(默认)或完全省略该thinking参数。

以下示例显示了在使用 InvokeModel API 时如何设置工作量级别:

{ "anthropic_version": "bedrock-2023-05-31", "max_tokens": 16000, "thinking": { "type": "adaptive" }, "output_config": { "effort": "high" }, "messages": [{ "role": "user", "content": "Your prompt here" }] }

在 Converse API 中使用自适应思维

使用 Converse API 时,将thinking和effort参数传递到里面additionalModelRequestFields。以下示例显示了默认努力水平下的适应性思维:

import boto3, json bedrock_runtime = boto3.client(service_name='bedrock-runtime', region_name='us-east-2') response = bedrock_runtime.converse( modelId="us.anthropic.claude-opus-4-6-v1", messages=[{ "role": "user", "content": [{"text": "Explain why the sum of two even numbers is always even."}] }], additionalModelRequestFields={ "thinking": { "type": "adaptive" } } ) print(json.dumps(response["output"], indent=2, default=str))

要指定努力级别,请在以下单独的output_config对象中添加该effort字段additionalModelRequestFields:

response = bedrock_runtime.converse( modelId="us.anthropic.claude-opus-4-6-v1", messages=[{ "role": "user", "content": [{"text": "What is 2 + 2?"}] }], additionalModelRequestFields={ "thinking": { "type": "adaptive" }, "output_config": { "effort": "low" } } )

设置每回合努力量(测试版)

该功能是 AWS 服务条款中定义的测试版服务。在 Claude Fable 5.1 和 Claude Mythos 5.1 中,你可以在对话中途更改努力级别,而不必为整个请求设置一次努力级别。在messages数组中的任意点插入带有output_config.effort值的系统消息。新的努力等级适用于其后的回合。该请求返回 200,响应形状不变。

要使用每回合的努力量,请包括以下anthropic_beta值之一:mid-conversation-output-config-2026-07-01、mid-conversation-effort-2026-08-01per-turn-control-2026-07-01、或per-message-effort-2026-07-01。

{ "anthropic_version": "bedrock-2023-05-31", "anthropic_beta": ["mid-conversation-effort-2026-08-01"], "max_tokens": 16000, "output_config": {"effort": "high"}, "messages": [ {"role": "user", "content": "First question"}, {"role": "assistant", "content": "First answer"}, {"role": "system", "content": [], "output_config": {"effort": "low"}}, {"role": "user", "content": "A simpler follow-up question"} ] }
注意

如果没有列出的测试值,或者在不支持每回合努力的模型output_config上,系统消息中包含的请求将返回400 messages.N.output_config: Extra inputs are not permitted。不支持每回合task_budget,还会返回 400。

提示缓存

使用 adaptive thinking 的连续请求会保留提示的缓存断点。但是,在adaptive和enabled/disabled思维模式之间切换会破坏消息的缓存断点。无论模式如何更改,系统提示和工具定义都将保持缓存状态。

调整思维行为

Claude如果思考的频率或多或少于您的预期,则可以在系统提示符中添加指导:

Extended thinking adds latency and should only be used when it will meaningfully improve answer quality — typically for problems that require multi-step reasoning. When in doubt, respond directly.
警告

Claude转而减少思考频率可能会降低受益于推理的任务的质量。在将基于提示的调整部署到生产环境之前,先衡量对特定工作负载的影响。考虑先用较低的工作量进行测试。

连接器文本摘要(测试版)

在 Claude Fable 5 中,模型在工具调用之间发出的文本(有时称为 “连接器文本” ——例如,“接下来让我检查那个文件...”)在服务器端汇总并作为思维方块而不是纯文本内容块返回。思维方块使用与任何其他思维方块相同的形状(默认omitted显示屏下带有签名的空文本)。

客户影响:

  • 响应形状: Tool-use 来自 Claude Fable 5 的响应可能包含额外的思维方块,其中先前的模型在方块之间发出纯文本。tool_use没有新的内容块类型。最终的助手答案(在所有工具使用完毕后)不受影响,仍为纯文本。

  • Multi-turn 处理:在多回合对话中将这些思维方块原封不动地传回去,处理方式与受保护思维相同(传回时签名已验证;如果发送到其他模型,则静默删除)。

  • 范围:连接器摘要仅在对话中tool_result存在 a 后才适用。新对话中第一次工具调用之前的旁白仍然是纯文本。短文本段可以作为纯文本传递,无需摘要。

此功能已在 Claude Fable 5 的服务器端启用。没有客户选择加入或选择退出。