Repository navigation
fix(responses): number bridged chat tool calls 0, 1 and pin the remaining bridge shapes - #46109
Conversation
… choice Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
…shapes Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will not alter performance
|
…ning bridge shapes (BerriAI#46109) Backport of BerriAI#46109 to stable/1.103.x. Cherry-picked from b6df3d7 (main). Adapted to the line: unit tests live under tests/test_litellm/, and the black-only reformat of the existing completion-responses tests is not carried.
…able/1.103.x The line's integration conftest refuses any owned test missing from contracts.json, so the backported BerriAI#46099 and BerriAI#46109 tests get covers marks and manifest entries here; main has no manifest.
TLDR
Problem this solves:
tool_calls[].index0, native chat numbers them 0 and 1[message, message, function_call]through the bridge and nothing else, a customer report (Pylon [Bug]: Gemini returns logprobs, but not in OpenAI format #9888) named a second shape with no testHow it solves it:
convert_response_function_tool_call_to_chat_completion_tool_callnow writes theindexit is passed instead of a hard-coded 0/responsesupstream, each shape non-stream and stream:[commentary, final_answer],[reasoning, message, message, function_call],[message, function_call, function_call]Every test except the two-call non-stream one passes on main, they pin behavior #46099 made correct
User Flow
Before: a developer calling a gpt-5.4 model with two tools gets both calls back with the same index, so a client that keys tool results by index merges them
tools: [get_weather, get_time]and noreasoning_effort, the proxy sends it to the provider's/responseschoices[0].message.tool_callscomes back as[{index 0, get_weather}, {index 0, get_time}]stream: true, or withreasoning_effort: "none"(native chat), returnsindex0 and 1After: the same call returns
index0 and 1, the same as stream and native chattools: [get_weather, get_time]choices[0].message.tool_callscomes back as[{index 0, get_weather}, {index 1, get_time}]Relevant issues
Follow-up to #46099
Linear ticket
LIT-9197
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreScreenshots / Proof of Fix
Local proxy on :4000 with a scripted
/responsesupstream on :8193 that returns[message "Checking both.", function_call get_weather, function_call get_time], registered asopenai/responses/gpt-6-solunder the model namebridge-two-calls. A scripted upstream because a live model only emits two calls in one turn sometimes. The commentary shape was checked against real Azure gpt-5.4-mini in #46099's follow-up run, native chat returns one choice with the preamble and the JSON in onecontent, same as the bridgeRequest body (
two_calls_body.json):{"model":"bridge-two-calls","messages":[{"role":"user","content":"Weather and time in Paris?"}],"tools":[{"type":"function","function":{"name":"get_time","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}},{"type":"function","function":{"name":"get_weather","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}],"cache":{"no-cache":true}}Before (3ce1e44, product code identical to main 4b7b8ef)
curl -s http://127.0.0.1:4000/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @two_calls_body.json | python -c 'import json,sys; b=json.load(sys.stdin); print([(c["index"], c["function"]["name"]) for c in b["choices"][0]["message"]["tool_calls"]])'[(0, 'get_weather'), (0, 'get_time')]pytest tests/integration/providers/test_responses_bridge_incomplete.py -k folds_against this proxy:1 failed, 7 passed, the red one istest_chat_over_responses_deployment_folds_message_and_two_function_calls_into_one_choicewith both calls atindex 0After (4d73c17)
[{"finish_reason": "tool_calls", "index": 0, "message": {"content": "Checking both.", "role": "assistant", "tool_calls": [ {"index": 0, "function": {"arguments": "{\"city\":\"Paris\"}", "name": "get_weather"}, "id": "fc_1", "type": "function"}, {"index": 1, "function": {"arguments": "{\"city\":\"Paris\",\"tz\":\"CET\"}", "name": "get_time"}, "id": "fc_2", "type": "function"}]}}]pytest tests/integration/providers/test_responses_bridge_incomplete.py -k folds_against this proxy:8 passedpytest tests/unit/responses/litellm_completion_transformation/test_litellm_completion_responses.py tests/unit/completion_extras/litellm_responses_transformation/:392 passedLive A/B on real Azure gpt-5.4-mini (Foundry litellm-e2e-suite), two tools, 3 non-stream + 3 stream calls per leg
litellm.completion(model="azure/gpt-5.4-mini", tools=[get_weather, get_time], ...), same prompt, the model called both tools in all 12 callsMain product code (helper writing
"index": 0):This PR (4d73c17):
Stream output is identical on both legs, non-stream now matches it
Mutation
Flipping the helper back to
"index": 0on this branch turns exactly these red and nothing else: the two integ cases oftest_convert_response_function_tool_call_keeps_the_index_it_is_givenwith index 1 and 2,test_convert_response_output_numbers_two_function_calls_zero_and_one, and the integ testtest_chat_over_responses_deployment_folds_message_and_two_function_calls_into_one_choice(3 failed, 389 passedunit,1 failed, 7 passedinteg). Restoring the line brings all of them back to greenTurn two
The same two tool calls sent back through the bridge as an assistant message with
tool_callsindex 0 and 1 plus twotoolmessages reach the scripted upstream asfunction_callandfunction_call_outputitems keyed bycall_id(fc_1,fc_2), the index plays no part in the replayWho reads the field
Google ADK's
apigee_llm.py_upsert_tool_callkeys accumulated tool calls bytool_call["index"]and only falls back to position when the field is missing, and itslite_llm.pycopiesindexstraight through. With the old0, 0the second call lands on the first call's slot. langchain-openai and openai-agents only readindexon stream deltas, openai-python never reads itType
🐛 Bug Fix
✅ Test
Caveats (if any)
Low
\nbetween preamble and answer, the bridge puts nothing, the commentary tests pin the no-separator form as decided on fix(responses): fold bridged Responses output into one chat choice #46099phaseis carried by the scripted upstream and ignored by the converter, the tests only prove it is harmlesssummary_index, so a reasoning item with two summary parts would stream its second part on choice 1. Not changed here, the new stream test uses one summary partFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/63d1473fc9d443ce8d843c168598bfcb
Open in Devin Desktop: https://app.devin.ai/desktop/session/63d1473fc9d443ce8d843c168598bfcb?variant=devin
Requested by: @kerrylu-berri