Repository navigation
Conversation
The OCI streaming path keyed each tool call by its "index", falling back to its position in the chunk. OCI tool calls carry no "index" and each chunk holds one call, so every call landed in slot 0: a second call overwrote the first call's id and name and appended its arguments, json.loads failed, and the response held one call with empty args. The calls were also sorted by name instead of kept in arrival order. Group pieces by index when one is sent, else by id. A piece with a name but no id starts a new call, and a piece with neither continues the last call, the same rule ApigeeLlm uses. Calls now keep the order they arrived in, like the non-streaming path.
copybara-service Bot
pushed a commit
that referenced
this pull request
Nov 10, 2026
Merge #8048 OCIGenAILlm streaming now groups tool-call pieces by index, else by id, and returns the calls in arrival order instead of sorted by name. PiperOrigin-RevId: 1018625954
Collaborator
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
ApigeeLlm)2. Or, if no issue exists, describe the change:
Problem:
OCIGenAILlmstreaming keys each tool call withtc.get("index", tc_idx). OCI tool calls carry noindex(the SDK'sFunctionCallhas onlyid,type,nameandarguments), and each chunk holds one call, so every call lands in slot 0. When the model calls two tools in one turn, the second call overwrites the first call's id and name and its arguments are appended to the first call's.json.loadsthen fails, and the final response holds one call with{}as args: the first call is lost and the second runs with no arguments.The final calls were also sorted by name instead of kept in the order they arrived.
Two calls in separate chunks, the shape
_make_sse_chunksalready builds:Solution:
Group the pieces by
indexwhen one is sent, else byid. A piece with a name but no id starts a new call, and a piece with neither continues the last call. This is the ruleApigeeLlmuses for tool-call chunks without an index (#7645). The calls now come out in arrival order, like the non-streaming path. One call split over several chunks (same index, same id, or the id only on the first piece) still merges into one call.Testing Plan
Unit Tests:
New tests in
tests/unittests/integrations/oci/test_oci_genai_llm.py:test_streaming_parallel_tool_calls_in_separate_chunks, with ids and with empty idstest_streaming_tool_calls_split_across_chunks, forsame_index,same_idandid_first_onlyAll 5 fail on main (
5 failed, 56 passed) and pass with the fix:pyink and isort leave both files unchanged.
Manual End-to-End (E2E) Tests:
I don't have an OCI account, so I could not run this against a live OCI endpoint, and
tests/integration/integrations/ociskips withoutOCI_COMPARTMENT_ID. The unit tests above stand in for E2E: they feedgenerate_content_async(stream=True)the chunk shape from_make_sse_chunks, whose docstring says it was checked against a live OCI Gemini stream, plus the split shapes.Checklist
Additional context
The order change is part of the same fix: once the calls are kept apart, sorting them by name would still reorder a turn's calls, which the non-streaming path does not do.