anthropics / anthropics/anthropic-sdk-python

Python SDK: _transform_recursive blocking event loop on large message payloads

オープン
#1,195 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
3.9k
フォーク
853
平均マージ
1日 18時間
マージ済み PR(30日)
11

説明

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?

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。