@@ -100,9 +100,14 @@ func (g *ModelGenerator) WithMessages(messages []*ai.Message) *ModelGenerator {
100
100
if ! p .IsToolResponse () {
101
101
continue
102
102
}
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
+
103
109
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 ,
106
111
anyToJSONString (p .ToolResponse .Output ),
107
112
)
108
113
oaiMessages = append (oaiMessages , tm )
@@ -369,6 +374,7 @@ func (g *ModelGenerator) generateComplete(ctx context.Context) (*ai.ModelRespons
369
374
var toolRequestParts []* ai.Part
370
375
for _ , toolCall := range choice .Message .ToolCalls {
371
376
toolRequestParts = append (toolRequestParts , ai .NewToolRequestPart (& ai.ToolRequest {
377
+ Ref : toolCall .ID ,
372
378
Name : toolCall .Function .Name ,
373
379
Input : jsonStringToMap (toolCall .Function .Arguments ),
374
380
}))
@@ -397,9 +403,13 @@ func convertToolCalls(content []*ai.Part) []openai.ChatCompletionMessageToolCall
397
403
}
398
404
399
405
func convertToolCall (part * ai.Part ) openai.ChatCompletionMessageToolCallParam {
406
+ toolCallID := part .ToolRequest .Ref
407
+ if toolCallID == "" {
408
+ toolCallID = part .ToolRequest .Name
409
+ }
410
+
400
411
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 ),
403
413
Function : (openai.ChatCompletionMessageToolCallFunctionParam {
404
414
Name : (part .ToolRequest .Name ),
405
415
}),
0 commit comments