Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-duplicate-tool-parts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': patch
---

Fixed duplicate tool parts when model calls an unavailable tool. The `tool-input-start` chunk creates a static part without a `dynamic` flag, but the subsequent `tool-input-error` chunk arrives with `dynamic: true`, causing a second `dynamic-tool` part to be created with the same `toolCallId`. This led to providers like Amazon Bedrock rejecting the message for duplicate tool use IDs.
7 changes: 6 additions & 1 deletion packages/ai/src/ui/process-ui-message-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,12 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
}

case 'tool-input-error': {
if (chunk.dynamic) {
const partialToolCall = state.partialToolCalls[chunk.toolCallId];
const dynamic = partialToolCall
? partialToolCall.dynamic
: chunk.dynamic;

if (dynamic) {
updateDynamicToolPart({
toolCallId: chunk.toolCallId,
toolName: chunk.toolName,
Expand Down
Loading