AgentV2 (dify-agent) sends empty-content system prompts and empty tool descriptions to Bedrock, causing ValidationException

在 Dify 1.16.0 的 AgentV2(dify-agent)后端中,使用 AWS Bedrock(如通过 Bedrock Converse API 调用 Claude)并在 Agent 上挂载了当前轮次未使用的 Skill 时,dify-agent 会把空的 system prompt 文

快速结论:在 Dify 1.16.0 的 AgentV2(dify-agent)后端中,使用 AWS Bedrock(如通过 Bedrock Converse API 调用 Claude)并在 Agent 上挂载了当前轮次未使用的 Skill 时,dify-agent 会把空的 system prompt 文本块以及空字符串的工具描述发给 Bedrock,触发 ValidationException(AgentV2 (dify-agent) sends empty-content system prompts and empty tool descriptions to Bedrock, causing ValidationException)。优先排查 dify-agent 侧是否把空 system prompt 与空 tool description 原样透传。

适用环境:Dify 1.16.0(AgentV2 / dify-agent 后端);Self Hosted(Docker);模型提供方为 AWS Bedrock(例如通过 Bedrock Converse API 使用 Anthropic Claude)。Issue 未提供操作系统、Python、CUDA、显卡等具体版本信息。

最快修复方案:暂无确认的一步修复方案。Issue 中报告的临时做法是在容器启动时对 dify_agent/adapters/llm/model.py 打运行时补丁(通过 docker/docker-compose.override.yaml);讨论中建议在 _map_model_request_to_prompt_messages() 的 SystemPromptPart 分支加入 if part.content.strip() 过滤,并把 _map_tool_definitions_to_prompt_tools() 中 tool_definition.description or "" 的回退值改为 tool_definition.name 或非空占位文本,但截至该 Issue 讨论尚未确认上游修复。另提到 open PR #39704 覆盖了 system 消息过滤部分,未覆盖空工具描述问题。

注意事项:运行时补丁属于对镜像内源码的临时修改,升级 Dify 或重建容器后可能失效,需重新应用;Issue 讨论未给出该补丁的正式验证结论。PR #39704 尚未合入且主要针对 vLLM/Qwen 场景,未经验证不能视为已修复 Bedrock 问题。

问题场景

用户自托管 Dify 1.16.0,配置 AgentV2(dify-agent)Agent 并使用 AWS Bedrock 模型(如 Anthropic Claude via Bedrock Converse API),同时给 Agent 挂载了一个或多个 Skills,其中至少一个 Skill 在当前轮次未被引用或使用。运行 Agent 发起 Bedrock 请求时,Bedrock 因文本内容块为空返回 ValidationException,Agent 运行失败。另一相关场景:dify-agent 内部使用的某个工具没有设置 description,dify-agent 回退为空字符串,Bedrock 同样拒绝 toolSpec.description。

报错原文

AgentV2 (dify-agent) sends empty-content system prompts and empty tool descriptions to Bedrock, causing ValidationException

ValidationException
toolSpec.description

原因分析

问题集中在 dify-agent/src/dify_agent/adapters/llm/model.py 的两条代码路径:

1. _map_model_request_to_prompt_messages() 对每个 SystemPromptPart 无条件追加 SystemPromptMessage,没有像 _map_messages_to_prompt_messages() 那样用 if part.content.strip() 过滤空指令消息。因此来自未引用 Skill 的空内容 system prompt 被原样转发到 Bedrock,被拒。这是最可能的原因之一。

2. _map_tool_definitions_to_prompt_tools() 使用 description=tool_definition.description or "" 构造 PromptMessageTool,当内部工具定义没有描述时发送空字符串,Bedrock Converse API 不接受空的 toolSpec.description。

环境排查

  • 确认 Dify 版本是否为 1.16.0,后端是否为 AgentV2 / dify-agent。
  • 确认部署方式为 Self Hosted(Docker),并确认实际运行镜像内的 dify-agent/src/dify_agent/adapters/llm/model.py 内容与 Issue 中描述的代码一致。
  • 确认模型提供方是否为 AWS Bedrock,以及是否走 Bedrock Converse API。
  • 检查 Agent 挂载的 Skills 列表,确认是否存在当前轮次未被使用的 Skill(可能产生空 system prompt)。
  • 检查 Agent 内部使用的工具定义是否缺少 description。

解决步骤

  1. 先按 Issue 提供的复现路径确认问题:为 AgentV2 挂载至少一个当前轮次不使用的 Skill,使用 Bedrock 模型运行,观察是否出现 ValidationException。
  2. 检查 dify-agent/src/dify_agent/adapters/llm/model.py 中 _map_model_request_to_prompt_messages() 的 SystemPromptPart 分支,确认是否缺少 if part.content.strip() 过滤。
  3. 检查 _map_tool_definitions_to_prompt_tools() 中是否仍使用 tool_definition.description or "" 作为回退。
  4. 如需临时恢复运行,可优先尝试按 Issue 中的做法,在容器启动时对该文件打运行时补丁(通过 docker/docker-compose.override.yaml):为 SystemPromptPart 分支增加空内容过滤,并把空工具描述回退为 tool_definition.name 或非空占位文本。该做法在 Issue 中被报告为可用的临时规避,但非上游正式修复。
  5. 关注 PR #39704 及后续针对空工具描述的修复 PR 是否合入,合入后升级 Dify 并移除临时补丁。

验证方法

应用补丁或升级后,使用相同的 AgentV2 配置(含未使用 Skill 与缺少 description 的工具)再次对 Bedrock 发起请求,确认不再出现 ValidationException;同时在日志中确认发送的 system prompt 与工具定义中不含空内容或空字符串描述。

参考来源

langgenius/dify #40003

langgenius/dify PR #39704

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

这个方案解决了吗?

celebrityanime
celebrityanime
文章: 33110

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注