Skip to content

Stripping function declarations on the last iteration when the history contains tool calls causes a ValidationError #7713

Description

@JeffinSiby

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.

  1. iteration >= MaximumIterationsPerRequest → PrepareOptionsForLastIteration (FunctionInvokingChatClient.cs).
  2. 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.
  3. 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.
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue describes a behavior which is not expected - a bug.untriaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions