Skip to content

[Go] OpenAI compatibility layer swaps content and tool_call_id in tool response messages #3559

@panbanda

Description

@panbanda

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:

  1. Use Genkit with the OpenAI compatibility layer
  2. Make a request that triggers tool usage
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggo

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions