@@ -325,6 +325,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
325325 currentContent := ""
326326 toolCalls := make([]message.ToolCall, 0)
327327 msgToolCalls := make(map[int64]openai.ChatCompletionMessageToolCall)
328+ toolMap := make(map[string]openai.ChatCompletionMessageToolCall)
328329 for openaiStream.Next() {
329330 chunk := openaiStream.Current()
330331 // Kujtim: this is an issue with openrouter qwen, its sending -1 for the tool index
@@ -332,7 +333,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
332333 chunk.Choices[0].Delta.ToolCalls[0].Index = 0
333334 }
334335 acc.AddChunk(chunk)
335− for _, choice := range chunk.Choices {
336+ for i, choice := range chunk.Choices {
336337 reasoning, ok := choice.Delta.JSON.ExtraFields["reasoning"]
337338 if ok && reasoning.Raw() != "" {
338339 reasoningStr := ""
@@ -361,6 +362,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
361362 if tool.ID == toolCall.ID {
362363 existingToolCall.Function.Arguments += toolCall.Function.Arguments
363364 msgToolCalls[toolCall.Index] = existingToolCall
365+ toolMap[existingToolCall.ID] = existingToolCall
364366 found = true
365367 }
366368 }
@@ -370,6 +372,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
370372 } else {
371373 existingToolCall.Function.Arguments += toolCall.Function.Arguments
372374 msgToolCalls[toolCall.Index] = existingToolCall
375+ toolMap[existingToolCall.ID] = existingToolCall
373376 }
374377 } else {
375378 newToolCall = true
@@ -394,7 +397,14 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
394397 Arguments: toolCall.Function.Arguments,
395398 },
396399 }
400+ toolMap[toolCall.ID] = msgToolCalls[toolCall.Index]
401+
402+ }
403+ toolCalls := []openai.ChatCompletionMessageToolCall{}
404+ for _, tc := range toolMap {
405+ toolCalls = append(toolCalls, tc)
397406 }
407+ acc.Choices[i].Message.ToolCalls = toolCalls
398408 }
399409 }
400410 }