Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode:...

2025年12月09日 21:37 状态: processing

🚨 错误信息

InvokeModelWithResponseStream: operation error Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode: 400, RequestID: 747567f9-836c-46d5-8037-90a4cd7cf342, ValidationException: ***.***.***.***.type: Expected `thinking` or `redacted_thinking`, but found `text`. When `thinking` is enabled, a final `assistant` message must start with a thinking block (preceeding the lastmost set of `tool_use` and `tool_result` blocks). We recommend you include thinking blocks from previous turns. To avoid this requirement, disable `thinking`. Please consult our documentation at https://***.com/***/***/***/*** (request id: 2025120921333567800283386BAOY1A) (request id: 20251209213322372892787jNZht1Qh) (request id: 20251209213322282580305PnXa0Gqx) (request id: 20251209213218667666118RZLqlbei)

🤖 AI解决方案

错误分析报告

1. 错误翻译

原文:ValidationException: ***.***.***.***.type: Expected `thinking` or `redacted_thinking`, but found `text`. When `thinking` is enabled, a final `assistant` message must start with a thinking block.
译文:验证异常:期望 `thinking` 或 `redacted_thinking` 类型,但找到的是 `text`。当启用 `thinking` 功能时,最终的 `assistant` 消息必须以思考块开头。

2. 原因分析

这是 AWS Bedrock 运行时服务的格式验证错误。当启用了 thinking 功能时,AI 助手的响应必须遵循特定的消息格式要求 - 必须以思考块开头,但实际返回的是普通文本内容。

3. 解决方案

方法一:禁用 thinking 功能
{
  "thinking": {
    "enabled": false
  }
}

方法二:修正消息格式

{
  "messages": [
    {
      "role": "assistant",
      "content": [
        {
          "thinking": "这是思考过程...",
          "type": "thinking"
        },
        {
          "text": "这是最终回复内容",
          "type": "text"
        }
      ]
    }
  ]
}

4. ️ 预防措施

  • 启用 thinking 时严格遵循格式:确保 assistant 消息始终以 thinking 块开头,后跟 text 块
  • 文档参考:仔细查阅 AWS Bedrock 官方文档中关于消息格式和 thinking 功能的具体要求

---
如需进一步分析,请提供更多上下文信息或相关代码片段