Description
Summary
FunctionInvokingChatClient removes every AIFunctionDeclaration from ChatOptions.Tools on the final iteration (added in #7207) so the inner client can't return a tool call nobody will execute.
That shape is is invalid on Amazon Bedrock's Converse API, which requires toolConfig whenever any message contains a toolUse/toolResult block. This means that on Bedrock, every conversation that uses a tool and then reaches MaximumIterationsPerRequest fails with:
Amazon.BedrockRuntime.Model.ValidationException:
The toolConfig field must be defined when using toolUse and toolResult content blocks.
Reproduction Steps
Repro
Any FunctionInvokingChatClient over AWS.Bedrock.MEAI with at least one AIFunction registered, driven until the iteration cap is hit.
- iteration >= MaximumIterationsPerRequest → PrepareOptionsForLastIteration (FunctionInvokingChatClient.cs).
- Every registered tool is an AIFunction, hence an AIFunctionDeclaration, so the tool is not AIFunctionDeclaration filter keeps nothing: remainingTools stays null, options.Tools = null, and options.ToolMode = null.
|
options.Tools = remainingTools; |
- The Bedrock client builds toolConfig only when
options?.Tools is { Count: > 0 } (https://github.com/aws/aws-dotnet-ai/blob/main/src/AWS.Bedrock.MEAI/BedrockChatClient.cs#L931)), so ToolConfig stays null and the field is omitted from the payload.
- Bedrock rejects the request: history has tool blocks, payload has no toolConfig.
Expected behavior
There should be no ValidationException from Bedrock.
Actual behavior
Amazon.BedrockRuntime.Model.ValidationException:
The toolConfig field must be defined when using toolUse and toolResult content blocks.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Description
Summary
FunctionInvokingChatClient removes every AIFunctionDeclaration from ChatOptions.Tools on the final iteration (added in #7207) so the inner client can't return a tool call nobody will execute.
That shape is is invalid on Amazon Bedrock's Converse API, which requires toolConfig whenever any message contains a toolUse/toolResult block. This means that on Bedrock, every conversation that uses a tool and then reaches MaximumIterationsPerRequest fails with:
Reproduction Steps
Repro
Any FunctionInvokingChatClient over AWS.Bedrock.MEAI with at least one AIFunction registered, driven until the iteration cap is hit.
extensions/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs
Line 1078 in 5682e2b
options?.Tools is { Count: > 0 }(https://github.com/aws/aws-dotnet-ai/blob/main/src/AWS.Bedrock.MEAI/BedrockChatClient.cs#L931)), so ToolConfig stays null and the field is omitted from the payload.Expected behavior
There should be no ValidationException from Bedrock.
Actual behavior
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response