Skip to content

fix(models): route interleaved interactions function-call deltas by step index - #6834

Open
chelsealong wants to merge 1 commit into
google:mainfrom
chelsealong:fix-interactions-interleaved-fc-deltas-6832
Open

fix(models): route interleaved interactions function-call deltas by step index#6834
chelsealong wants to merge 1 commit into
google:mainfrom
chelsealong:fix-interactions-interleaved-fc-deltas-6832

Conversation

@chelsealong

Copy link
Copy Markdown
Contributor

Summary

Fixes #6832.

The Interactions streaming converter attached arguments_delta and step.stop
events to state.parts[-1] (the most recently started part) instead of the
function-call step identified by the event's index. When multiple
function-call steps are interleaved, argument deltas for an earlier step were
appended to the last-started call, concatenating their raw JSON strings. At
step.stop this produces invalid JSON (e.g. {"a": 1}{"b": 2}
JSON_PARSE_ERROR), and the earlier call is finalized with no arguments —
effectively swapping/merging function names and arguments in the final
response.

Fix

  • Add an fc_parts_by_index mapping to _StreamState, populated at
    StepStart from the step's index.
  • Route arguments_delta and step.stop to the matching function-call part
    via a small _resolve_streaming_function_call_part helper.
  • Retain the existing "last started function call" behavior as a fallback for
    events that carry no index, so single-call streaming is unchanged.

Testing Plan

  • Added test_interleaved_function_call_streaming_routes_by_index, which
    starts two calls (get_weather at index 0, get_time at index 1), interleaves
    their argument deltas, then stops both, asserting each call finalizes with its
    own arguments.
  • Verified the test fails without the fix: reverting only the source change
    makes the new test fail with get_weather.args == None and the log shows the
    corruption directly — arg_str: {"city": "Paris"}{"zone": "UTC"} (both deltas
    concatenated onto the last call).
  • Full file passes with the fix:
    pytest tests/unittests/models/test_interactions_utils.py143 passed;
    including the related processor tests → 158 passed.
  • Lint: pyink --check and isort --check-only both clean on the two changed
    files.

AI assistance disclosure

This change was prepared with AI assistance (Claude). A human reviewed the
diff, the reproduction, and the test evidence above before submission.

…tep index

The Interactions streaming converter attached arguments_delta and
step.stop events to state.parts[-1] instead of the function-call step
identified by the event's index. When multiple function-call steps are
interleaved, deltas for an earlier step were appended to the most
recently started call, concatenating their raw JSON and producing
invalid arguments (or swapped/merged names) in the final response.

Track function-call parts by step index in _StreamState and route
arguments_delta and step.stop to the matching step, retaining the
existing last-part fallback for events without an index.

Fixes google#6832
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.

fix(interactions): route interleaved function-call deltas by step index

2 participants