Skip to content

Commit 46594d2

Browse files
fix(go/plugins/compat-oai): Pass tool call ID if available (#3248)
1 parent 9659106 commit 46594d2

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

go/plugins/compat_oai/generate.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,14 @@ func (g *ModelGenerator) WithMessages(messages []*ai.Message) *ModelGenerator {
100100
if !p.IsToolResponse() {
101101
continue
102102
}
103+
// Use the captured tool call ID (Ref) if available, otherwise fall back to tool name
104+
toolCallID := p.ToolResponse.Ref
105+
if toolCallID == "" {
106+
toolCallID = p.ToolResponse.Name
107+
}
108+
103109
tm := openai.ToolMessage(
104-
// NOTE: Temporarily set its name instead of its ref (i.e. call_xxxxx) since it's not defined in the ai.ToolResponse struct.
105-
p.ToolResponse.Name,
110+
toolCallID,
106111
anyToJSONString(p.ToolResponse.Output),
107112
)
108113
oaiMessages = append(oaiMessages, tm)
@@ -369,6 +374,7 @@ func (g *ModelGenerator) generateComplete(ctx context.Context) (*ai.ModelRespons
369374
var toolRequestParts []*ai.Part
370375
for _, toolCall := range choice.Message.ToolCalls {
371376
toolRequestParts = append(toolRequestParts, ai.NewToolRequestPart(&ai.ToolRequest{
377+
Ref: toolCall.ID,
372378
Name: toolCall.Function.Name,
373379
Input: jsonStringToMap(toolCall.Function.Arguments),
374380
}))
@@ -397,9 +403,13 @@ func convertToolCalls(content []*ai.Part) []openai.ChatCompletionMessageToolCall
397403
}
398404

399405
func convertToolCall(part *ai.Part) openai.ChatCompletionMessageToolCallParam {
406+
toolCallID := part.ToolRequest.Ref
407+
if toolCallID == "" {
408+
toolCallID = part.ToolRequest.Name
409+
}
410+
400411
param := openai.ChatCompletionMessageToolCallParam{
401-
// NOTE: Temporarily set its name instead of its ref (i.e. call_xxxxx) since it's not defined in the ai.ToolRequest struct.
402-
ID: (part.ToolRequest.Name),
412+
ID: (toolCallID),
403413
Function: (openai.ChatCompletionMessageToolCallFunctionParam{
404414
Name: (part.ToolRequest.Name),
405415
}),

0 commit comments

Comments
 (0)