Skip to content

fix(responses): number bridged chat tool calls 0, 1 and pin the remaining bridge shapes - #46109

Merged
klu-berri merged 3 commits into
mainfrom
litellm_responses_bridge_commentary_final_answer_test
Oct 13, 2026
Merged

klu-berri merged 3 commits into
mainfrom
litellm_responses_bridge_commentary_final_answer_test

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

How it solves it:

  • convert_response_function_tool_call_to_chat_completion_tool_call now writes the index it is passed instead of a hard-coded 0
  • Six integ tests on the real proxy with a scripted /responses upstream, each shape non-stream and stream: [commentary, final_answer], [reasoning, message, message, function_call], [message, function_call, function_call]
  • Three unit tests, the commentary fold, the two-call fold, and the index pass-through

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

  1. They send POST https://litellm-domain/v1/chat/completions with tools: [get_weather, get_time] and no reasoning_effort, the proxy sends it to the provider's /responses
  2. The model calls both tools in one turn
  3. choices[0].message.tool_calls comes back as [{index 0, get_weather}, {index 0, get_time}]
  4. The same request with stream: true, or with reasoning_effort: "none" (native chat), returns index 0 and 1

After: the same call returns index 0 and 1, the same as stream and native chat

  1. They send the same POST https://litellm-domain/v1/chat/completions with tools: [get_weather, get_time]
  2. The model calls both tools in one turn
  3. choices[0].message.tool_calls comes back as [{index 0, get_weather}, {index 1, get_time}]
  4. Stream and native chat are unchanged and now match

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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Screenshots / Proof of Fix

Local proxy on :4000 with a scripted /responses upstream on :8193 that returns [message "Checking both.", function_call get_weather, function_call get_time], registered as openai/responses/gpt-6-sol under the model name bridge-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 one content, same as the bridge

Request 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)

  1. 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"]])'
  2. Output: [(0, 'get_weather'), (0, 'get_time')]
  3. pytest tests/integration/providers/test_responses_bridge_incomplete.py -k folds_ against this proxy: 1 failed, 7 passed, the red one is test_chat_over_responses_deployment_folds_message_and_two_function_calls_into_one_choice with both calls at index 0

After (4d73c17)

  1. Same curl, output:
[{"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"}]}}]
  1. pytest tests/integration/providers/test_responses_bridge_incomplete.py -k folds_ against this proxy: 8 passed
  2. pytest tests/unit/responses/litellm_completion_transformation/test_litellm_completion_responses.py tests/unit/completion_extras/litellm_responses_transformation/: 392 passed

Live 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 calls

Main product code (helper writing "index": 0):

before-main non-stream 0 | n_choices 1 | idx 0 tool_calls | tool_calls [(0, 'get_weather'), (0, 'get_time')]
before-main non-stream 1 | n_choices 1 | idx 0 tool_calls | tool_calls [(0, 'get_weather'), (0, 'get_time')]
before-main non-stream 2 | n_choices 1 | idx 0 tool_calls | tool_calls [(0, 'get_weather'), (0, 'get_time')]
before-main stream 0 | choice_indices [0] tool_calls | tool_calls [(0, 'get_weather'), (1, 'get_time')]
before-main stream 1 | choice_indices [0] tool_calls | tool_calls [(0, 'get_weather'), (1, 'get_time')]
before-main stream 2 | choice_indices [0] tool_calls | tool_calls [(0, 'get_weather'), (1, 'get_time')]

This PR (4d73c17):

after-tip non-stream 0 | n_choices 1 | idx 0 tool_calls | tool_calls [(0, 'get_weather'), (1, 'get_time')]
after-tip non-stream 1 | n_choices 1 | idx 0 tool_calls | tool_calls [(0, 'get_weather'), (1, 'get_time')]
after-tip non-stream 2 | n_choices 1 | idx 0 tool_calls | tool_calls [(0, 'get_weather'), (1, 'get_time')]
after-tip stream 0 | choice_indices [0] tool_calls | tool_calls [(0, 'get_weather'), (1, 'get_time')]
after-tip stream 1 | choice_indices [0] tool_calls | tool_calls [(0, 'get_weather'), (1, 'get_time')]
after-tip stream 2 | choice_indices [0] tool_calls | tool_calls [(0, 'get_weather'), (1, 'get_time')]

Stream output is identical on both legs, non-stream now matches it

Mutation

Flipping the helper back to "index": 0 on this branch turns exactly these red and nothing else: the two integ cases of test_convert_response_function_tool_call_keeps_the_index_it_is_given with index 1 and 2, test_convert_response_output_numbers_two_function_calls_zero_and_one, and the integ test test_chat_over_responses_deployment_folds_message_and_two_function_calls_into_one_choice (3 failed, 389 passed unit, 1 failed, 7 passed integ). Restoring the line brings all of them back to green

Turn two

The same two tool calls sent back through the bridge as an assistant message with tool_calls index 0 and 1 plus two tool messages reach the scripted upstream as function_call and function_call_output items keyed by call_id (fc_1, fc_2), the index plays no part in the replay

Who reads the field

Google ADK's apigee_llm.py _upsert_tool_call keys accumulated tool calls by tool_call["index"] and only falls back to position when the field is missing, and its lite_llm.py copies index straight through. With the old 0, 0 the second call lands on the first call's slot. langchain-openai and openai-agents only read index on stream deltas, openai-python never reads it

Type

🐛 Bug Fix
✅ Test

Caveats (if any)

Low

  • Native chat puts \n between 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 #46099
  • phase is carried by the scripted upstream and ignored by the converter, the tests only prove it is harmless
  • The stream reasoning path sets the choice index from summary_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 part

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

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

… choice

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

…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

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@devin-ai-integration devin-ai-integration Bot changed the title test(responses): pin bridged commentary plus final answer as one chat choice fix(responses): number bridged chat tool calls 0, 1 and pin the remaining bridge shapes Oct 12, 2026
@codspeed

codspeed Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 31 untouched benchmarks


Comparing litellm_responses_bridge_commentary_final_answer_test (4d73c17) with main (4b7b8ef)

Open in CodSpeed

@klu-berri
klu-berri merged commit b6df3d7 into main Oct 13, 2026
194 of 198 checks passed
@klu-berri
klu-berri deleted the litellm_responses_bridge_commentary_final_answer_test branch October 13, 2026 00:35
mrinal-berri added a commit that referenced this pull request Oct 17, 2026
…dge_stable_1_103_x

fix(responses): backport #46099 and #46109 to stable/1.103.x for v1.103.5
pamanseau pushed a commit to KubeTEE-AI/litellm that referenced this pull request Oct 25, 2026
…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.
pamanseau pushed a commit to KubeTEE-AI/litellm that referenced this pull request Oct 25, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants