Repository navigation
fix(oci): make Cohere {{trace}} judges work (re-land #30646, lint-clean) - #30780
fede-kamel wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@Sameerlite @mateo-berri this re-lands #30646, which got swept up in the batch stabilization revert (commit 15a7c68) rather than for anything specific to it. I folded in the greptile-review empty-message guard that had been applied on top of the original merge. It is lint-clean against the current Would appreciate a re-review when you have a moment |
Greptile SummaryThe PR re-lands the OCI Cohere tool-calling fixes on the current staging tip and removes the dead tool-history representation identified previously.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/llms/oci/chat/cohere.py | Builds USER/CHATBOT history separately from current-turn tool results and removes use of the obsolete tool-history model. |
| litellm/llms/oci/chat/transformation.py | Emits OCI Cohere continuation requests with top-level tool results and an empty message. |
| litellm/llms/oci/common_utils.py | Maps JSON-schema arrays and objects to OCI-compatible lowercase collection type names. |
| litellm/types/llms/oci.py | Adds top-level tool results, relaxes optional response metadata, and removes the previously reported dead CohereToolMessage type. |
| tests/test_litellm/llms/oci/chat/test_oci_cohere_tool_calls.py | Verifies the corrected first-turn and tool-result continuation request shapes. |
| tests/test_litellm/llms/oci/test_oci_coverage_boost.py | Covers tool-result extraction and tool-grounded response parsing. |
Reviews (5): Last reviewed commit: "fix(oci): make Cohere {{trace}} judges w..." | Re-trigger Greptile
b2a7502 to
9959751
Compare
|
Addressed the Greptile finding: removed the now-unreachable |
|
@greptileai please re-review; the latest commit removes the dead |
|
@Sameerlite @mateo-berri — this re-lands #30646 (rolled back in the batch revert |
9faf989 to
6437b81
Compare
|
@fede-kamel Can you rebase this to litellm_internal_staging correctly? I can many unintentional changes |
|
Thanks for the contribution! Greptile scored 5/5 and CI is green — the code itself looks solid. The remaining issue is that the diff includes ~80 unintentional files (README, Bedrock, vertex_ai, proxy_server, etc.) beyond the OCI scope. Could you do a clean rebase onto |
9959751 to
50169f3
Compare
|
@Sameerlite done — rebased cleanly onto The out-of-scope files came from the branch having been based on
No out-of-scope files remain. CI is re-running on the clean head ( |
50169f3 to
c25510d
Compare
|
@Sameerlite rebased onto the current The diff remains scoped to the same 8 OCI files as before. Verified locally against the rebased state:
Since you'd already reviewed the code as solid (Greptile 5/5, CI green) before the conflicts appeared, this should be ready to land whenever you get a chance. Thanks! |
c25510d to
f0b467b
Compare
|
@Sameerlite rebased onto the current litellm_internal_staging tip again. The conflicts were from the lint sweeps that landed since July (the new LIT010 Final-on-locals rule, typing modernization, and the litellm/types ruff exclusion removal); there were no semantic changes to the OCI Cohere files upstream, so the fix itself is unchanged. The diff remains scoped to the same 8 OCI files. Verified locally after the rebase: full OCI unit suite 372 passed, ruff format clean, and the strict, type discipline, and basedpyright gates all within budget. Should be ready to land whenever you get a chance |
|
@greptileai please re-review; the rebase onto the current litellm_internal_staging tip adapted the fix to the new lint rules (Final on locals, modernized typing), no semantic changes. Re-verified live against OCI GenAI in us-chicago-1 at f0b467b: the branch passes all four Cohere tool integration tests (array-param tools and tool-result continuations on cohere.command-latest and cohere.command-a-03-2025), while the same tests on the unpatched litellm_internal_staging tip fail 3 of 4 with the HTTP 500 and continuation errors this PR fixes, so the re-land is still needed |
|
@greptileai review |
|
Hi — we are blocked on this re-land for our OCI GenAI (me-riyadh-1) deployment: with the current main-stable / main-latest images, multi-turn chained tool-calling through the OCI/Cohere adapter fails on the continuation turn (OCI 400 "cannot specify message if the last entry in chat history contains tool results") because the transform still sends a populated top-level message with tool results in chatHistory instead of hoisting to top-level toolResults + empty message. We verified the raw OCI Signature-v1 shape (top-level toolResults) chains fine. Since none of the published tags (stable/latest/v1.97.0/main-latest) carry this change, we would appreciate a release once it lands — we will re-verify immediately against our probe and confirm chained tool-calling works end-to-end. Happy to help test the re-land if useful. |
f0b467b to
2d4989f
Compare
|
Thanks for verifying the toolResults shape against the API. Rebased onto today's staging tip and live tests pass; release timing is up to the maintainers |
|
@Sameerlite rebased onto the current staging tip with the diff still scoped to the OCI files. A user above is blocked on this |
|
@greptileai please re-review; the rebase adapts to the current staging tip and renames one helper for the basedpyright budget, no semantic changes |
2d4989f to
48cb695
Compare
|
Rebased onto current staging and conflicts are resolved. Five of this PR's regression tests fail on staging without it, so the fix is still needed |
12980a9 to
02da067
Compare
…ic tool-calling continuation) Re-lands BerriAI#30646, which was rolled back in a batch stabilization revert (commit 15a7c68), with the greptile-review empty-message guard folded in. Three OCI Cohere transform bugs broke MLflow {{trace}} judges: 1. Tool parameter types: a JSON-schema `array` param mapped to the bare string "List" in OCI_JSON_TO_PYTHON_TYPES, and OCI's Cohere backend returns HTTP 500 on a bare "List". Mapped the collection types to the lowercase builtins list/dict. 2. Agentic tool-calling continuation (request side): after a tool runs, litellm pulled the last user message into the top-level `message` and emitted the tool result as a TOOL entry in chatHistory. OCI rejects that ("cannot specify message if the last entry in chat history contains tool results"), and an empty message alone is also rejected ("message must be at least 1 token long or tool results must be specified"). OCI carries the current turn's results in a dedicated top-level `toolResults` field. The transform now sends an empty message, keeps the user turn in chatHistory, and puts results in `toolResults`, matching the langchain-oracle reference. Tool results are no longer chatHistory entries. 3. Response parsing: tool-grounded answers carry citations with `documentIds` (camelCase) and no `document_ids`, which made the required CohereCitation.document_ids field sink the whole response parse. That field (and CohereSearchQuery.generation_id) is now optional. Verified live against us-chicago-1 (cohere.command-a-03-2025 and command-latest), single and multi-round tool loops. Adds unit regressions on the transformed request shape and citation parsing, plus gated integration tests for the continuation.
02da067 to
89d82ad
Compare
|
Rebased onto main at 88ea40e (head now 89d82ad). Conflicts in cohere.py, transformation.py and types/llms/oci.py (upstream extract_text_content rename, LiteLLMBaseModel, typing passes) resolved keeping this PR's shape; two new helpers now take/return Sequence for the type-discipline budget. Local, Python 3.12: pytest tests/unit/llms/oci (484 passed, 5 skipped), ruff check/format, ruff-strict/type-discipline/test-quality gates vs main, basedpyright on changed files (277→275) — all green; the failing misc shard was the unrelated interactions OpenAPI test. Overlaps #46157 and open PRs #46159/#46161/#46181 on the tool-result turn; unique here: the List/Dict parameter-type 500 fix, optional generation_id, and no TOOL chatHistory entries. |
|
@Sameerlite this re-lands #30646 (the Cohere {{trace}} judge fix you merged in June), which was rolled back in the batch stabilization revert |
|
@Sameerlite @yuneng-berri a nudge on this one: it re-lands #30646, the Cohere |
TLDR
Problem this solves:
How it solves it:
list/dictmessageplus top-leveltoolResultschatHistory, drops TOOL entriesdocument_idsand search-querygeneration_idoptionalUser Flow
Before: a developer running an MLflow {{trace}} judge against an OCI Cohere model through the gateway sees every judge run fail
cohere-judgewith aget_spantool whoseattributes_to_fetchparameter is a JSON-schema arrayAfter: the same requests complete and the judge scores the trace
get_spanentry intool_callsRelevant issues
Re-lands #30646, which was rolled back in a batch stabilization revert (commit
15a7c687) along with several unrelated PRs. The greptile-review hardening applied on top of the original merge is folded in. A user in this PR's thread is currently blocked on this fix for their OCI GenAI deployment and independently verified the top-leveltoolResultsrequest shape against the raw OCI APIThe three underlying bugs, all hit by judges that send tools and run an agentic tool-calling loop:
arrayparameter mapped to the bare string"List", which OCI's Cohere backend rejects with a 500. The mapping now emits the lowercase builtinslist/dictmessageand emitted the tool result as a TOOL entry inchatHistory, which OCI rejects. OCI carries the current turn's results in a dedicated top-leveltoolResultsfield, so the transform now sends an emptymessage, keeps the user turn inchatHistory, and puts results intoolResults, matching the langchain-oracle referencedocumentIdsand nodocument_ids, which sank the whole parse becauseCohereCitation.document_idswas required. That field andCohereSearchQuery.generation_idare now optionalLatest push rebases onto the current
litellm_internal_stagingtip (d5b91b94d3) and renames one cross-module helper to stay under the basedpyright private-usage budget, with no semantic changes. Verified locally at the new tip:ruff format --checkclean, all three budget gates pass, the OCI unit suite passes (372 tests), and the four gated live Cohere tool integration tests pass against real OCI GenAILinear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Live proxy against real OCI GenAI in us-chicago-1, credentials supplied via the
OCI_*environment variables so no secrets appear in requests. Config:Payloads, identical on both sides:
Before (d5b91b9)
Tool with an array-typed parameter
curl -s -w "\nHTTP_STATUS:%{http_code}\n" http://localhost:4000/v1/chat/completions -H "Content-Type: application/json" -d @case1_array_param.json{"error":{"message":"litellm.APIConnectionError: OciException - { \"code\": \"500\", \"message\": \"Internal Server Error.\" }. Received Model Group=cohere-judge\nAvailable Model Group Fallbacks=None","type":null,"param":null,"code":"500"}} HTTP_STATUS:500Tool-result continuation
curl -s -w "\nHTTP_STATUS:%{http_code}\n" http://localhost:4000/v1/chat/completions -H "Content-Type: application/json" -d @case2_continuation.json{"error":{"message":"litellm.APIConnectionError: OciException - { \"code\": \"400\", \"message\": \"{\\\"id\\\":\\\"/48465B6E3414EB5CEF9FBF24621B9CE5/4D91F9296C2336B8AD0BE45678E34977\\\",\\\"message\\\":\\\"invalid request: cannot specify message if the last entry in chat history contains tool results\\\"}\" }. Received Model Group=cohere-judge\nAvailable Model Group Fallbacks=None","type":null,"param":null,"code":"500"}} HTTP_STATUS:500After (2d4989f)
Tool with an array-typed parameter
curl -s -w "\nHTTP_STATUS:%{http_code}\n" http://localhost:4000/v1/chat/completions -H "Content-Type: application/json" -d @case1_array_param.json{"id":"chatcmpl-0bbf5260-da75-4971-851e-d36e26861cf5","created":1786994440,"model":"cohere-judge","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"I will use the get_span tool to find out how many spans are in the trace.","role":"assistant","tool_calls":[{"function":{"arguments":"{}","name":"get_span"},"id":"call_8a39c5fb17cbc97d37f08b4c","type":"function"}]}}],"usage":{"completion_tokens":23,"prompt_tokens":21,"total_tokens":44}} HTTP_STATUS:200Tool-result continuation
curl -s -w "\nHTTP_STATUS:%{http_code}\n" http://localhost:4000/v1/chat/completions -H "Content-Type: application/json" -d @case2_continuation.json{"id":"chatcmpl-2678a086-7e6e-4d69-bb32-c1443534728d","created":1786994442,"model":"cohere-judge","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"There are 47 spans in the trace.","role":"assistant"}}],"usage":{"completion_tokens":10,"prompt_tokens":36,"total_tokens":46}} HTTP_STATUS:200Type
Bug Fix
Caveats (if any)
tool_choice, a pre-existing limitation, omit the paramFinal Attestation