Skip to content

fix: use authoritative final arguments for OpenAI Responses tool calls#1734

Open
toffee-desuwa wants to merge 1 commit into
MoonshotAI:mainfrom
toffee-desuwa:fix/openai-responses-final-arguments
Open

fix: use authoritative final arguments for OpenAI Responses tool calls#1734
toffee-desuwa wants to merge 1 commit into
MoonshotAI:mainfrom
toffee-desuwa:fix/openai-responses-final-arguments

Conversation

@toffee-desuwa

Copy link
Copy Markdown

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 in function_call_arguments.done / output_item.done that 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.ts and packages/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, indexed tool_call_part is 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 new function_call header while an unindexed call is still unresolved; it is only reachable for non-conforming providers that omit both item_id and output_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.done precedence, done-absent fallback to the accumulated delta, and parallel tool-call indices not cross-streaming.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c63e71b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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

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.

openai_responses should treat final function-call arguments as authoritative

1 participant