Skip to content

fix(amazon-bedrock): handle empty activeTools with tool conversation history#7600

Merged
dancer merged 9 commits intomainfrom
js/bedrocks
Jul 28, 2025
Merged

fix(amazon-bedrock): handle empty activeTools with tool conversation history#7600
dancer merged 9 commits intomainfrom
js/bedrocks

Conversation

@dancer
Copy link
Collaborator

@dancer dancer commented Jul 28, 2025

background

Users integrating Amazon Bedrock with multi-step agents hit validation errors when setting activeTools: [] or toolChoice: 'none' in conversations that previously used tools. Bedrock requires toolConfig to be present when conversation contains tool content, but rejects empty tools arrays.

summary

  • add placeholder tool when activeTools is empty but conversation has tool content
  • handle both activeTools: [] and toolChoice: 'none' scenarios
  • include helpful warning about workaround

verification

  • all existing tests pass with updated expectations
  • multi-step agent scenarios work without validation errors
  • placeholder tool doesn't interfere with final responses

tasks

  • placeholder tool logic in bedrock-prepare-tools.ts
  • updated test expectations for both scenarios
  • warning messages for user awareness

future work

  • remove workaround if Amazon Bedrock API supports empty tools with conversation history

related issue #7528

Copy link
Collaborator

@lgrammel lgrammel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will impact llm behavior with a fake tool

)
.filter(
message => message.role === 'system' || message.content.length > 0,
) as typeof prompt;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the type cast needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ts can't prove that filtering maintains the exact prompt type structure, so we need the cast to tell it the result still matches LMV2Prompt

Comment on lines +200 to +207
const hasToolContent = prompt.some(
message =>
'content' in message &&
Array.isArray(message.content) &&
message.content.some(
part => part.type === 'tool-call' || part.type === 'tool-result',
),
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this check needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

messages can contain only tool-call parts (no texts) and then tool messages contain only tool-results parts so after filtertering removes these we would get a empty content: [] array and bedrock rejects that

@dancer dancer merged commit 0893170 into main Jul 28, 2025
9 checks passed
@dancer dancer deleted the js/bedrocks branch July 28, 2025 11:32
@gr2m gr2m added ai/provider provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider labels Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants