fix: skip empty assistant message in tool call translation (#2132)
When assistant has tool_calls but no text content, the translator emitted an empty message into the Responses API input array before function_call items. The API then couldn't match function_call_output to its function_call by call_id, returning: No tool output found for function call ... Only emit assistant messages that have content parts. Tool-call-only messages now produce function_call items directly. Added 9 tests for tool calling translation covering single/parallel calls, multi-turn conversations, name shortening, empty content edge cases, and call_id integrity.
This commit is contained in:
@@ -197,7 +197,12 @@ func ConvertOpenAIRequestToCodex(modelName string, inputRawJSON []byte, stream b
|
||||
}
|
||||
}
|
||||
|
||||
out, _ = sjson.SetRaw(out, "input.-1", msg)
|
||||
// Don't emit empty assistant messages when only tool_calls
|
||||
// are present — Responses API needs function_call items
|
||||
// directly, otherwise call_id matching fails (#2132).
|
||||
if role != "assistant" || len(gjson.Get(msg, "content").Array()) > 0 {
|
||||
out, _ = sjson.SetRaw(out, "input.-1", msg)
|
||||
}
|
||||
|
||||
// Handle tool calls for assistant messages as separate top-level objects
|
||||
if role == "assistant" {
|
||||
|
||||
Reference in New Issue
Block a user