Skip to content

Conversation

@ajason
Copy link
Contributor

@ajason ajason commented Feb 2, 2026

This PR updates the serialization of tool message content to comply with the OpenAI API specification (which requires content to be a string) and ensures compatibility with DeepSeek API (https://api-docs.deepseek.com/api/create-chat-completion content of a tool message must be a string ).

Changes

  • Changed tool message content from .blocks([...]) (array) to .text(...) (string).
  • Implemented correct serialization for StructuredSegment (JSON):
  • ImageSegment is converted to a placeholder string "<image>" as binary/image content cannot be represented in a plain string tool response. @mattt: Image segments are now omitted, which seems to be a more aligned with other implementations

Impact

This fixes allows the library to work correctly with strict OpenAI-compatible APIs like DeepSeek.

ajason and others added 2 commits February 2, 2026 14:52
DeepSeek API expects tool message content to be a string, not an array.
Changed from .blocks() to .text() for tool messages.

Also ensures structured tool outputs (JSON) are correctly serialized to JSON strings
instead of using debug descriptions.
Drop image segments rather than emitting <image>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the OpenAI language model implementation to serialize tool message content as strings instead of block arrays, ensuring compatibility with strict OpenAI-compatible APIs like DeepSeek that require tool message content to be a string per the OpenAI API specification.

Changes:

  • Introduced convertSegmentsToToolContentString() function to serialize transcript segments as plain strings for tool messages
  • Updated all three locations where tool messages are created to use .text() with string content instead of .blocks() with array content
  • Text and structured segments are converted to string format, while image segments are omitted from tool message content

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mattt
Copy link
Owner

mattt commented Feb 4, 2026

@ajason Thank you for opening this PR! I made a couple changes (most notably, omitting image segments instead of emitting "<image>"), but otherwise this is good to go.

@mattt mattt merged commit c77ed79 into mattt:main Feb 4, 2026
9 checks passed
@ajason ajason deleted the fix-deepseek-tool-content branch February 4, 2026 10:39
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.

2 participants