Fix tool message content format for DeepSeek API compatibility#99
Merged
mattt merged 2 commits intomattt:mainfrom Feb 4, 2026
Merged
Fix tool message content format for DeepSeek API compatibility#99mattt merged 2 commits intomattt:mainfrom
mattt merged 2 commits intomattt:mainfrom
Conversation
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>
There was a problem hiding this comment.
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.
Owner
|
@ajason Thank you for opening this PR! I made a couple changes (most notably, omitting image segments instead of emitting |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR updates the serialization of
toolmessage content to comply with the OpenAI API specification (which requirescontentto 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
toolmessage content from.blocks([...])(array) to.text(...)(string).StructuredSegment(JSON):@mattt: Image segments are now omitted, which seems to be a more aligned with other implementationsImageSegmentis converted to a placeholder string"<image>"as binary/image content cannot be represented in a plain string tool response.Impact
This fixes allows the library to work correctly with strict OpenAI-compatible APIs like DeepSeek.