Skip to content

[SDK V5][Amazon Bedrock] Hitting "The toolConfig field must be defined when using toolUse and toolResult content blocks." when setting toolChoice: 'none' #7528

@brendan-kellam

Description

@brendan-kellam

Description

Heya - When using streamText with Amazon Bedrock, if a conversation has prior tool calls, any subsequent step with no active tools (activeTools: [] or toolChoice: none) will fail. This only happens with Bedrock and no other provider I have tested.

Steps to Reproduce:

  1. Use streamText with a Bedrock model and a tool.
  2. In the prepareStep callback, set activeTools to an empty array for the second turn of the conversation to force a text-only response.
  3. The call fails when the agent tries to generate the final answer.

Minimal Code Example:

const aws = createAmazonBedrock();

const stream = streamText({
    model: aws('anthropic.claude-3-5-sonnet-20241022-v2:0'),
    tools: {
        weather: tool({
            description: 'Get the weather in a location',
            inputSchema: z.object({ city: z.string() }),
            execute: async ({ city }) => ({
                result: `The weather in ${city} is 20°C.`,
            }),
        }),
    },
    stopWhen: [
        stepCountIs(5)
    ],
    prepareStep: ({ stepNumber }) => {
        if (stepNumber > 0) {
            return {
                activeTools: [] // or `toolChoice: 'none'`
            };
        }

        return undefined;
    },
    toolChoice: 'auto',
    prompt: 'What is the weather in Toronto, Calgary, and Vancouver?',
});

Expected Behavior:

The request should succeed, and the model should generate a final text response without calling any tools.

Actual Behavior:

The API call fails with the error: The toolConfig field must be defined when using toolUse and toolResult content blocks.

AI SDK Version

  • ai: 5.0.0-beta.26
  • @ai-sdk/amazon-bedrock: 3.0.0-beta.9
  • @ai-sdk/react:2.0.0-beta.26

Metadata

Metadata

Assignees

Labels

ai/providerrelated to a provider package. Must be assigned together with at least one `provider/*` labelbugSomething isn't working as documentedprovider/amazon-bedrockIssues related to the @ai-sdk/amazon-bedrock provider

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions