-
Notifications
You must be signed in to change notification settings - Fork 413
Description
Describe the bug
The OpenAI compatibility layer in Genkit incorrectly swaps the content
and tool_call_id
fields when creating tool response messages. The parameters to openai.ToolMessage()
are passed in the wrong order, causing the tool call ID to appear in the content field and the response data to appear in the tool_call_id field.
Error message from AWS Bedrock:
Validation error: tool_call_id field must match pattern [a-zA-Z0-9_-]+ and be ≤64 characters
Current malformed output:
{
"role": "tool",
"content": "tooluse_B8G0zOhpTIKkZKFc_DRtdQ", // Wrong: This is the tool ID
"tool_call_id": "{\"conditions\":\"Clear\",...}" // Wrong: This is the response data
}
Impact
The tool calling library is not usable at all.
To Reproduce
Steps to reproduce the behavior:
- Use Genkit with the OpenAI compatibility layer
- Make a request that triggers tool usage
- Observe the generated tool response message
Code showing the bug:
// Current incorrect implementation swaps the parameters
openai.ToolMessage(toolCallID, anyToJSONString(p.ToolResponse.Output))
Expected behavior
Tool response messages should have the correct field values according to the OpenAI API specification:
{
"role": "tool",
"content": "{\"conditions\":\"Clear\",...}", // Should be the response data
"tool_call_id": "tooluse_B8G0zOhpTIKkZKFc_DRtdQ" // Should be the tool ID
}
The correct code should be:
// Correct parameter order: content first, then toolCallID
openai.ToolMessage(anyToJSONString(p.ToolResponse.Output), toolCallID)
Screenshots
N/A
Runtime (please complete the following information):
- OS: All (Linux, MacOS, Windows)
- Version: Current main branch
Go version
- All versions affected (logic error, not version-specific)
Additional context
- OpenAI SDK signature:
func ToolMessage[T string | []ChatCompletionContentPartTextParam](content T, toolCallID string)
- This bug breaks compatibility with strict validation backends like AWS Bedrock
- PR with fix: fix(compat_oai): correct parameter order in ToolMessage call #3504
Metadata
Metadata
Assignees
Labels
Type
Projects
Status