Non-streaming Chat Completions run fails when provider usage has null token counts (streaming handles it since #1179)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
openai_chatcompletions.py の非ストリーミングの get_response 使用構築から始め、chatcmpl_stream_handler.py の null カウント処理と比較してください。any_llm_model.py の対応する Usage 構築を確認し、自己完結型の httpx.MockTransport 再現を実行してください。非ストリーミング実行が完了し、欠落しているトークン数についてゼロを報告すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
With OpenAIChatCompletionsModel, a non-streaming run fails when the provider's usage has a null token count. This happens even though the model returned a valid answer. The streaming path already accepts the same payload: since #1179, chatcmpl_stream_handler.py maps None to 0 (usage.prompt_tokens or 0, …). The non-streaming get_response in openai_chatcompletions.py still passes response.usage.prompt_tokens / completion_tokens / total_tokens straight into Usage(...), so pydantic rejects None.
any_llm_model.py builds Usage the same way.
Debug information
- Agents SDK version:
main@ 8e435004 (0.22.3) - Python version: 3.13
- Operating system: macOS
- Model and model provider:
OpenAIChatCompletionsModelagainst an OpenAI-compatible server (mocked below) - Does the issue reproduce with the latest Agents SDK release? Yes
- Does the issue occur consistently or intermittently? Consistently, whenever a token count is
null
pydantic_core._pydantic_core.ValidationError: 1 validation error for Usage
output_tokens
Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType]
Repro steps
Self-contained; the HTTP call is mocked with httpx.MockTransport.
import asyncio
import httpx
from openai import AsyncOpenAI
from agents import Agent, Runner, OpenAIChatCompletionsModel, set_tracing_disabled
set_tracing_disabled(True)
def handler(request: httpx.Request) -> httpx.Response:
return httpx.Response(200, json={
"id": "r1", "object": "chat.completion", "created": 1, "model": "m",
"choices": [{"index": 0, "finish_reason": "stop",
"message": {"role": "assistant", "content": "hi"}}],
# Some OpenAI-compatible providers send null token counts
"usage": {"prompt_tokens": 10, "completion_tokens": None, "total_tokens": 10},
})
client = AsyncOpenAI(api_key="x", base_url="http://test/v1",
http_client=httpx.AsyncClient(transport=httpx.MockTransport(handler)))
agent = Agent(name="a", model=OpenAIChatCompletionsModel(model="m", openai_client=client))
print(asyncio.run(Runner.run(agent, "hi")).final_output)
The same payload streamed through Runner.run_streamed completes and reports input_tokens=10.
Expected behavior
The run should complete the same way as the streaming path: treat the missing counts as 0 (... or 0) in openai_chatcompletions.get_response and any_llm_model.
I used an AI assistant (Claude Code) to help find and reproduce this; I ran the repro myself on main.
- 主要言語
- Python
- スター
- 29.8k
- フォーク
- 4.8k
- 平均マージ
- 2日 7時間
- マージ済み PR(30日)
- 205
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
openai/openai-agents-python のほかの issue
-
feature:sessions
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
openai/openai-agents-python#4827 · コメント 12 件 ·
メンテナーはふだん 1 日以内に返信
openai/openai-agents-python の issue をすべて見る
似ている issue
-
namespace operations
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
EclipseFdn/open-vsx.org#13573 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
collective/icalendar#1854 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
rancher/rancher-ai-agent#412 ·
メンテナーはふだん 6 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
TUDelftGeodesy/DePSI#134 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
HenriquesLab/rxiv-maker#335 ·