anthropics / anthropics/anthropic-sdk-python

Python SDK: _transform_recursive blocking event loop on large message payloads

Đang mở
#1,195 6 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
3.9k
Fork
853
Merge trung bình
1 ngày 18 giờ
Pull request đã merge (30 ngày)
11

Mô tả

We profiled our FastAPI gateway (which runs an agent orchestration loop using the Anthropic Python SDK) and found that _transform_recursive in anthropic/_utils/_transform.py consumes ~6.6% of total CPU time during heavy workloads.

The function recursively walks the entire messages + tools payload doing type introspection (get_type_hints, is_typeddict, is_union_type) at every level of nesting. For Messages API types, this produces zero changes — no key renames, no date formatting. The transform allocates new dicts at every level and copies every key-value pair, producing an identical structure.

Additionally, AsyncMessages.stream() calls the synchronous maybe_transform (not async_maybe_transform), so the entire recursive walk blocks the event loop.

We're currently working around this by passing messages and tools via extra_body so the transform only runs on empty placeholders. Has this been reported as a known issue? Is there a better recommended approach?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.