fix: use authoritative final arguments for OpenAI Responses tool calls#1734
Open
toffee-desuwa wants to merge 1 commit into
Open
fix: use authoritative final arguments for OpenAI Responses tool calls#1734toffee-desuwa wants to merge 1 commit into
toffee-desuwa wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: c63e71b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Related Issue
Resolve #1455
Problem
See linked issue. Both Responses adapters'
yieldFinalArgumentsSuffix()only accept the final tool-call arguments when they equal, or are a byte-prefix of, the accumulated streamed delta. A Responses-compatible provider that returns corrected full JSON infunction_call_arguments.done/output_item.donethat is not a prefix of the streamed partial makes the adapter throw and aborts the whole agent turn.What changed
Both Responses adapters (
packages/kosong/src/providers/openai-responses.tsandpackages/agent-core-v2/src/app/llmProtocol/providers/openai-responses.ts) now buffer tool-call arguments per stream index instead of committing the tool call from the streamed deltas. Authority order:output_item.done.item.arguments>function_call_arguments.done.arguments> accumulated delta (used only when both are absent). A single complete, indexedtool_call_partis emitted at item/response completion.Behavior change: tool-call arguments are now emitted once at
output_item.done/ end of stream rather than streamed per delta. The consumers are append-only (target.arguments + argumentsPart, with no primitive to replace already-appended text), so a corrective non-prefix final cannot be un-applied downstream — buffering is the only correct fix, and it matches the authority order the linked issue recommends. A guard also rejects starting a newfunction_callheader while an unindexed call is still unresolved; it is only reachable for non-conforming providers that omit bothitem_idandoutput_index, and it turns a previously silent argument clobber into a fail-loud error.Tests (Vitest) cover: final arguments overriding the streamed delta,
output_item.doneprecedence, done-absent fallback to the accumulated delta, and parallel tool-call indices not cross-streaming.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.