Repository navigation
Conversation
…BerriAI#46157) - Pop trailing CohereToolMessage entries from chatHistory into top-level toolResults and clear message on tool-result turns, preventing OCI 400 'cannot specify message if last entry in chat history contains tool results' - Add toolResults field to CohereChatRequest - Update CohereCitation to accept camelCase documentIds alias as returned by OCI - Add comprehensive unit tests covering single and parallel multi-turn tool responses and citation validation
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
5 of 6 tasks
5 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Problem this solves:
400 invalid request: cannot specify message if the last entry in chat history contains tool results.documentIdswhileCohereCitationrequireddocument_ids.How it solves it:
OCIChatConfig.transform_request, when the conversation ends with tool messages, trailingCohereToolMessageentries are popped fromchatHistoryinto top-leveltoolResults, and top-levelmessageis set to"".toolResultsfield toCohereChatRequest.CohereCitation, addedmodel_config = ConfigDict(populate_by_name=True)and declareddocument_idswith aliasdocumentIdsand default[].User Flow
Before: an application executing multi-turn tool calling with an OCI Cohere model crashes on the second turn with HTTP 400 or response validation failure
role: "tool"result.400 invalid request: cannot specify message if the last entry in chat history contains tool results.Response cannot be casted to CohereChatResult: Field required: chatResponse.citations.0.document_ids.After: the second turn succeeds and returns the final assistant answer
role: "tool"result.transform_requestmaps trailing tool outputs totoolResultsand setsmessage="", which OCI accepts.CohereCitationparses camelCasedocumentIdsfrom OCI seamlessly and returns the completedModelResponse.Relevant issues
Fixes #46157
Pre-Submission checklist
Type
🐛 Bug Fix