Skip to content
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

Merged
merged 3 commits into from
Jul 29, 2024

Conversation

bracesproul
Copy link
Collaborator

@bracesproul bracesproul commented Jul 29, 2024

todo: update merge adjacent util func to only merge tool_result types.

Copy link

vercel bot commented Jul 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2024 8:33pm
langchainjs-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2024 8:33pm

Comment on lines 161 to 182
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];
}, []);
}
Copy link
Collaborator Author

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),
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:improvement Medium size change to existing code to handle new use-cases size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant