Skip to content

fix: include content field on assistant tool_calls messages - #134

Open
truffle-dev wants to merge 1 commit into
graniet:mainfrom
truffle-dev:fix/openai-tool-message-content
Open

fix: include content field on assistant tool_calls messages#134
truffle-dev wants to merge 1 commit into
graniet:mainfrom
truffle-dev:fix/openai-tool-message-content

Conversation

@truffle-dev

Copy link
Copy Markdown

Assistant messages built from MessageType::ToolUse serialize their tool_calls array but drop the content field entirely. In chat_message_to_openai_message the tool-use arm returns content: None, and because OpenAIChatMessage.content is annotated skip_serializing_if = "Option::is_none", the field never reaches the wire.

Strict OpenAI-compatible providers such as OpenRouter reject an assistant message that carries tool_calls without a content field, so any multi-turn tool loop routed through them fails after the first tool call. The OpenAI schema allows content to be an empty string alongside tool_calls, which is what this emits.

Serialized assistant tool-call message before / after:

before: {"role":"assistant","tool_calls":[...]}
after:  {"role":"assistant","content":"","tool_calls":[...]}

Added a regression test asserting the serialized message keeps both content and tool_calls. Verified it fails on the old None arm and passes with the fix.

Fixes #111

The ToolUse arm of chat_message_to_openai_message returned None for
content. Because OpenAIChatMessage.content is skip_serializing_if =
Option::is_none, that dropped the field from the serialized request.
Strict OpenAI-compatible APIs such as OpenRouter reject an assistant
message that carries tool_calls without a content field, breaking any
multi-turn tool loop through those providers.

Emit the message content string instead, matching the OpenAI schema.

Fixes graniet#111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: tool_calls messages omit content field

1 participant