-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
anthropic[patch]: Proper handling of multi tool result messages #6257
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
function _mergeAdjacentMessages( | ||
messages: AnthropicMessageParam[] | ||
): AnthropicMessageParam[] { | ||
return messages.reduce((acc: AnthropicMessageParam[], current, index) => { | ||
if (index === 0) { | ||
return [current]; | ||
} | ||
|
||
const previous = acc[acc.length - 1]; | ||
|
||
if ( | ||
previous.role === current.role && | ||
Array.isArray(previous.content) && | ||
Array.isArray(current.content) | ||
) { | ||
previous.content = previous.content.concat(current.content); | ||
return acc; | ||
} | ||
|
||
return [...acc, current]; | ||
}, []); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @jacoblee93 this is the new util which fixes the bug
} | ||
}); | ||
return { | ||
messages: _mergeAdjacentMessages(formattedMessages), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and @jacoblee93 it's called here
todo: update merge adjacent util func to only merge tool_result types.