智能体
dev.to ·
@Interro
修复 Bedrock ToolResult 顺序错误
文章描述了一类 Bedrock 工具调用故障(INC-004):工具执行成功,但下一条消息因 toolResult ID 与前置 toolUse 顺序不匹配而被 Bedrock 拒绝。该问题在工具并行执行时容易触发,因为异步完成顺序不等于协议顺序,checkpoint 恢复或中间件也可能打乱结果块。修复方法是依据 assistant 的 toolUseId 序列推导结果顺序,为缺失结果填充显式错误块,并在发送给服务商前校验组装好的消息;建议至少测试逆序完成、单个结果缺失、checkpoint 恢复乱序三种场景,不要依赖字典插入顺序或 future 完成顺序。
AI推荐理由 这是一篇针对 AWS Bedrock 工具调用协议的具体工程实践文章,指出了并行工具执行时 toolResult 顺序与 toolUseId 序列不匹配导致请求被拒的问题(INC-004),并给出可操作的修复思路:按 assistant 的 toolUseId 顺序重排结果、为缺失结果填充显式错误块、发送前校验消息,并建议覆盖逆序完成、结果缺失、checkpoint 恢复乱序三类测试。对使用 Bedrock + LangGraph 等 Agent 框架的开发者有直接参考价值。局限在于内容来自个人技术博客,未提供官方文档或可复现的完整代码/日志证据,属于经验性总结而非官方规范。
72
正文
A tool executed successfully, but Bedrock rejected the next message because toolResult IDs did not match the preceding toolUse order.
INC-004 is easy to create when tools run in parallel. Async completion order is not protocol order, and checkpoint restore or middleware can shuffle result blocks.
The fix is to derive result order from the assistant's toolUseId sequence, fill missing results with explicit error blocks, and validate the assembled message before sending it to the provider.
Test at least three cases:
Results complete in reverse order.
One result is missing.
A checkpoint restores shuffled results.
Do not rely on dictionary insertion order or the order in which futures complete. The provider contract owns the final ordering rule.
Run a source review with:
prevention-scanner scan . --format json
Enter fullscreen mode
Exit fullscreen mode
Read the full INC-004 incident.
AI #AWS #Bedrock #LangGraph