Skip to content

Conversation

@ajason
Copy link

@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.

Impact

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

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.
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.

1 participant