Skip to content

Comments

fix(streaming): expose "toolCallResultId" in the streamed data#908

Open
joao-salomao wants to merge 2 commits intoprism-php:mainfrom
joao-salomao:fix-expose-tool-call-result-id
Open

fix(streaming): expose "toolCallResultId" in the streamed data#908
joao-salomao wants to merge 2 commits intoprism-php:mainfrom
joao-salomao:fix-expose-tool-call-result-id

Conversation

@joao-salomao
Copy link

Description

Add tool_call_result_id (the call_id from the model's function call) to the ToolResultEvent::toArray() payload so clients can use it when replaying tool-call history.

The OpenAI Responses API ties function_call_output to a model tool call via call_id. When replaying conversations, each function_call_output must use the same call_id the model returned. Prism’s ToolResult already stores this as toolCallResultId, but ToolResultEvent::toArray() does not expose it.

Without it, clients that need to replay history (e.g. chat UIs that send prior turns back to the API) cannot reliably link tool results to tool calls. They end up with custom SSE/stream adapters that add tool_call_result_id from $event->toolResult->toolCallResultId:

// In buildConversationMessages – we use resultId to build Prism messages for replay
foreach ($toolCallsData as $tc) {
    $id = $tc->toolId;
    $resultId = $tc->resultId;  // Must come from the model's call_id
    // ...

    $toolResults[] = new ToolResult(
        toolCallId: $id,
        toolName: $name,
        args: $arguments,
        result: $result,
        toolCallResultId: $resultId  // Required for Responses API matching
    );
}

The frontend receives tool results via ToolResultEvent, so it needs tool_call_result_id in toArray() to store it and send it back as resultId when replaying history.

Breaking Changes

None

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.

1 participant