Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/goose/src/providers/formats/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ pub fn format_messages(messages: &[Message], image_format: &ImageFormat) -> Vec<
converted["content"] = json!(text_array.join("\n"));
}

// Some strict OpenAI-compatible providers require "content" to be present
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just leave this line of this comment describing the reason for the code.

// (even as null) when tool_calls are provided. See #6717.
if message.role == Role::Assistant
&& converted.get("tool_calls").is_some()
&& converted.get("content").is_none()
{
converted["content"] = json!(null);
}
Comment on lines +250 to +257
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description claims two new tests were added (test_format_messages_tool_calls_without_text_includes_content_null / ...with_text_keeps_content_string), but those tests don’t appear anywhere in the repo; either add them or update the description to match what’s actually included.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — PR description updated to match the actual test names. The original tests were deleted per @katzdave's request, and two new focused tests have been added: test_format_messages_tool_calls_only_sets_content_null and test_format_messages_tool_calls_with_text_keeps_content_string.

Comment on lines +252 to +257
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new behavior (forcing content: null when an assistant message only contains tool calls) isn’t covered by existing tests; please add/extend a unit test (e.g., update test_format_messages_complex or add a dedicated case) to assert spec[..]["content"].is_null() for assistant tool-call-only messages and that mixed text+tool calls keeps content as a string.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added two tests in the latest commit (cef2a90): test_format_messages_tool_calls_only_sets_content_null asserts content is present and null for assistant tool-call-only messages. test_format_messages_tool_calls_with_text_keeps_content_string asserts mixed text+tool calls keeps content as a string.


if converted.get("content").is_some() || converted.get("tool_calls").is_some() {
output.insert(0, converted);
}
Expand Down