[1.x] Keep the provider call id when replaying an AG-UI tool result

Merged
CH
7d ago
+95-1

Fixes #1240.

Replaying AG-UI history dropped the provider call id. OpenAI rejected the next turn with Missing required parameter: 'input[N].call_id'. Chat-completions providers sent a tool call id that no longer matched its result.

The stream puts the call id on TOOL_CALL_RESULT.messageId and the item id on the tool call. fromMessages() rebuilt the call from the item id only. The tool result still carried the message id, so the two sides disagreed.

fromMessages() now copies the tool message id onto the call when the call has no result id. Anthropic is unchanged: it pairs on the tool call id, which is still the toolCallId.

A tool message with no id leaves the result id empty, and an existing result id is left as it is.

Tests

  • The call's result id becomes the tool message id, including a hydrated conversation and a CopilotKit run.
  • A tool message with no id leaves the result id empty.
  • OpenAI receives the same call_id on the function_call and the function_call_output.
  • Groq receives the same id on the assistant tool call and the tool message.

The OpenAI replay test fails on 1.x before this change: the recorded function_call has no call_id, and the function_call_output has call_id: call_1.

Made with Cursor