The toolConfig field must be defined when using toolUse and toolResult content blocks
Self Checks
- [X] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [X] I have searched for existing issues search for existing issues, including closed ones.
- [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
- [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
- [X] Please do not modify this template :) and fill in all the required fields.
Dify version
0.7.0
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
I Use Amazon Bedrock and Claude3.5 Sonnet in the Agent.
Agent uses 5 tools
- webscraperwebscraper
- codesimple_code
- timecurrent_time
- githubgithub_repositories
- firecrawlscrape
- googlegoogle_search
Some time Agent was failed because the above error will occur when switching from having a tool to without a tool after using the tool.
[bedrock] Error: ValidationException: The toolConfig field must be defined when using toolUse and toolResult content blocks.
This is log stream of Bedrock API on the Cloudwatch logs.
{
"schemaType": "ModelInvocationLog",
"schemaVersion": "1.0",
"timestamp": "2024-08-16T00:10:39Z",
"accountId": "account_id",
"identity": {
"arn": "arn:aws:sts::account_id:assumed-role/DifyOnAwsStack-ApiServiceTaskTaskRole06F87EBE-aaRvf0jNQata/34b83c25d18a449a88a67efd56d05b73"
},
"region": "us-west-2",
"requestId": "50f42cca-5c85-499c-8957-d11761ed95cd",
"operation": "ConverseStream",
"modelId": "anthropic.claude-3-5-sonnet-20240620-v1:0",
"errorCode": "ValidationException"
}
✔️ Expected Behavior
Amazon Bedrock Converse API was succeeded
❌ Actual Behavior
I got this error on the browser.
data: {"event": "error", "conversation_id": "a33d622c-9789-4549-8624-f1a0b55b05a2", "message_id": "e8c15ca2-2d84-49fd-844d-b3a2659a42ac", "created_at": 1723768034, "code": "completion_request_error", "status": 400, "message": "[bedrock] Error: ValidationException: The toolConfig field must be defined when using toolUse and toolResult content blocks."}
Hey there, @fsatsuki! I'm a bot designed to help you with bug reports, questions, and becoming a contributor. I'm here to assist you while you wait for a human maintainer.
To resolve the ValidationException error in Dify version 0.7.0 when using Amazon Bedrock and Claude3.5 Sonnet in the Agent, you need to ensure that the toolConfig field is defined when using toolUse and toolResult content blocks. This can be done by adding the toolConfig to the parameters if the model supports tool use.
Here is the relevant code snippet that shows how to define the toolConfig:
if model_info['support_tool_use'] and tools:
parameters['toolConfig'] = self._convert_converse_tool_config(tools=tools)
Make sure that the tools parameter is passed correctly and that the toolConfig is set up properly using the _convert_converse_tool_config method.
Here is the method to convert the tool configuration:
def _convert_converse_tool_config(self, tools: Optional[list[PromptMessageTool]] = None) -> dict:
tool_config = {}
configs = []
if tools:
for tool in tools:
configs.append(
{
"toolSpec": {
"name": tool.name,
"description": tool.description,
"inputSchema": {
"json": tool.parameters
}
}
}
)
tool_config["tools"] = configs
return tool_config
Ensure that the tools parameter is correctly populated and passed to the _invoke method. This will help in defining the toolConfig field and resolving the ValidationException error [1].
To continue talking to Dosu, mention @dosu.
Is this issue resolved?
I have encountered the same problem, please fix it as soon as possible, thank you!!!!
same problem and happens a lot especially when the agent tries to use tools for complex questions.
This issue is caused by the Agent exceeding the maximum limit of 5 tool calls. The same problem occurs with Anthropic's model. We're currently looking into how we can make adjustments.