Skip to content

fix(sdk): convert structured message parts to request payloads - #3900

Open
rocke2020 wants to merge 2 commits into
volcengine:mainfrom
rocke2020:fix/sdk-serialize-message-parts
Open

fix(sdk): convert structured message parts to request payloads#3900
rocke2020 wants to merge 2 commits into
volcengine:mainfrom
rocke2020:fix/sdk-serialize-message-parts

Conversation

@rocke2020

@rocke2020 rocke2020 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

TL;DR: Python SDK clients now convert dataclass-backed message parts into JSON-compatible request payload data before httpx performs the final JSON encoding, so the documented TextPart workflow no longer raises TypeError.

Summary

The fix preserves existing dict inputs while converting structured Part objects to the server wire shape.

  • Convert TextPart, ContextPart, and ToolPart dataclasses into JSON-compatible dictionaries in the standalone SDK.
  • Reshape ImagePart into the required nested image_url payload.
  • Apply the same conversion to the main package compatibility HTTP clients without depending on a newly released SDK version.
  • Add standalone and cross-package SyncHTTPClient regression coverage with real httpx JSON encoding.

Fixes #3890

Verification

The exact issue input now reaches the mocked transport as valid JSON, including mixed text, image, and tool parts.

  • .venv/bin/ruff check ... — passed.
  • Focused SDK/client tests — 56 passed, 1 deselected.
  • Standalone SDK suite — 108 passed, 1 deselected.
  • Exact SyncHTTPClient MockTransport probe — PASS; one request with text,image_url,tool parts.
  • uv build --wheel sdk/python — built one wheel; uv.lock unchanged.

The deselected test_glob_normalizes_scope_uri is an existing upstream expectation mismatch: current upstream code sends the default node_limit=256, while that upstream test still expects no node_limit. This PR does not change that path.

@rocke2020 rocke2020 changed the title fix(sdk): serialize structured message parts fix(sdk): convert structured message parts to request payloads Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

[Bug]: [Python-SDK] TypeError: Object of type TextPart is not JSON serializable when calling client.add_message

1 participant