Repository navigation
fix(oci): support cohere tool-result turns and citation document ids - #46181
Open
aashutosh-yadav wants to merge 1 commit into
Open
aashutosh-yadav wants to merge 1 commit into
aashutosh-yadav wants to merge 1 commit into
Conversation
Contributor
Merging this PR will not alter performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
OCI rejects a cohere chat request that sets `message` while the last
chatHistory entry carries tool results with a 400 ("cannot specify
message if the last entry in chat history contains tool results"). Lift
trailing tool-result messages into top-level `toolResults` with an empty
`message`, keep the user and chatbot turns in `chatHistory`, and convert
every message 1:1 instead of reordering or dropping turns.
Also fix a crash parsing cohere citations: OCI's SDK exposes the field
as `documentIds` while the model read `document_ids`, so any citation
broke attribute access. Bind the alias explicitly.
Regression tests cover both directions: the request payload shape for a
tool-result turn, and the citation document ids alias.
aashutosh-yadav
force-pushed
the
litellm_oci_cohere_tool_result_turns
branch
from
October 13, 2026 18:07
afb0dea to
1e5807b
Compare
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:
messageis set and the lastchatHistoryentry holds tool resultsdocumentIdsbut the model readsdocument_idsHow it solves it:
toolResultsfield with an emptymessage, and the user and chatbot turns stay inchatHistorydocumentIdsas the wire alias fordocument_idsUser Flow
Before: a developer running an agent loop against
cohere.command-a-03-2025on OCI gets a 400 on the turn after a tool call, and cited answers crash parsingtoolmessage lastmessageto the last user text and leaves the tool result inchatHistorydocument_idsAfter: the same loop continues past the tool call and cited answers parse
toolmessage lastmessage="", the results in top-leveltoolResults, andchatHistoryending in the assistant tool call, with the user question keptdocumentIdsRelevant issues
Fixes #46157
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/llms/oci/ -q(424 passed, 5 skipped)Screenshots / Proof of Fix
A live call to OCI was not run: the author had no OCI credentials, so no real provider request with cost is included. The evidence instead is the exact payload that would have been signed and sent, dumped offline before and after, plus the regression tests added here, and both halves fail on the old code. A reviewer with an OCI compartment can reproduce the 400 fix by replaying the After payload shape below.
Before (merge base)
OCIChatConfig.sign_requestto printrequest_data["chatRequest"]messageset to the user question andchatHistory= [CHATBOT, TOOL], the shape OCI answers 400 todocument_idsAfter (1e5807b)
message="", results in top-leveltoolResults, andchatHistory= [USER, CHATBOT]Type
🐛 Bug Fix
Caveats (if any)
Medium
Low
chatHistorynow keeps the last user turn instead of dropping it, the old helper behavior, so history grows by one entry versus the previous shapecohere_messages_pt_v2request shape, and the two need to settle on oneFinal Attestation