@@ -340,6 +340,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
340 toolCalls := make([]message.ToolCall, 0)
340 toolCalls := make([]message.ToolCall, 0)
341 msgToolCalls := make(map[int64]openai.ChatCompletionMessageToolCall)
341 msgToolCalls := make(map[int64]openai.ChatCompletionMessageToolCall)
342 toolMap := make(map[string]openai.ChatCompletionMessageToolCall)
342 toolMap := make(map[string]openai.ChatCompletionMessageToolCall)
343+ toolCallIDMap := make(map[string]string)
343 for openaiStream.Next() {
344 for openaiStream.Next() {
344 chunk := openaiStream.Current()
345 chunk := openaiStream.Current()
345 // Kujtim: this is an issue with openrouter qwen, its sending -1 for the tool index
346 // Kujtim: this is an issue with openrouter qwen, its sending -1 for the tool index
@@ -367,6 +368,15 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
367 currentContent += choice.Delta.Content
368 currentContent += choice.Delta.Content
368 } else if len(choice.Delta.ToolCalls) > 0 {
369 } else if len(choice.Delta.ToolCalls) > 0 {
369 toolCall := choice.Delta.ToolCalls[0]
370 toolCall := choice.Delta.ToolCalls[0]
371+ if strings.HasPrefix(toolCall.ID, "functions.") {
372+ exID, ok := toolCallIDMap[toolCall.ID]
374+ newID := uuid.NewString()
375+ toolCallIDMap[toolCall.ID] = newID
370 newToolCall := false
380 newToolCall := false
371 if existingToolCall, ok := msgToolCalls[toolCall.Index]; ok { // tool call exists
381 if existingToolCall, ok := msgToolCalls[toolCall.Index]; ok { // tool call exists
372 if toolCall.ID != "" && toolCall.ID != existingToolCall.ID {
382 if toolCall.ID != "" && toolCall.ID != existingToolCall.ID {