OpenAIChatCompletionsModel sends max_tokens, which reasoning models reject
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 85/100
調査の方向性
src/agents/models/openai_chatcompletions.py の _fetch_response 内の708行目付近を調べ、max_tokens が設定されている箇所を確認する。ChatCmplHelpers.is_openai を使用して公式APIに max_completion_tokens を送信するチェックを追加する。tests/models/test_openai_chatcompletions_stream.py 内の max_tokens == 64 アサーションを更新する。reproスクリプトが max_completion_tokens を出力し、テストスイートが通過したら完了。
索引モデルが issue の本文から書いたものです。
説明
Found while testing LLM provider integrations in agent frameworks: an automated tool flags candidates and each one is reproduced before it is reported. Reproduced on cd26bbb.
Please read this first
- Have you read the docs? Yes, Models.
- Have you searched for related issues? Yes. #679 proposed switching to
max_completion_tokensfor every endpoint and was closed as stale without review.
Describe the bug
OpenAIChatCompletionsModel sends ModelSettings.max_tokens as the Chat Completions max_tokens parameter, also when the client points at api.openai.com. OpenAI deprecated max_tokens in favor of max_completion_tokens, and its reasoning models (o-series, and the GPT-5 family the same way) reject max_tokens with a 400. So an agent that sets ModelSettings(max_tokens=...) and runs a reasoning model through Chat Completions (OpenAIChatCompletionsModel, set_default_openai_api("chat_completions") or OpenAIProvider(use_responses=False)) fails on its first model call.
The other paths already translate the setting: OpenAIResponsesModel sends it as max_output_tokens, and LiteLLM and Any-LLM remap it to max_completion_tokens themselves. In OpenAIChatCompletionsModel._fetch_response the key is fixed: https://github.com/openai/openai-agents-python/blob/cd26bbbc52847845fde73b9952b51e62e2bcbdc0/src/agents/models/openai_chatcompletions.py#L708
Debug information
- Agents SDK version: 0.24.0 (main at cd26bbb)
- Related library versions (optional, e.g.
any-llm,litellm, orpydantic):openai3.29.0 - Python version: 3.12.4
- Operating system: Linux
- Model and model provider: OpenAI
o4-minithrough Chat Completions (alsoo3, thegpt-5family and similar) - Does the issue reproduce with the latest Agents SDK release? Yes, the code path is unchanged on main.
- Does the issue occur consistently or intermittently? Consistently.
Output of the script below:
https://api.openai.com/v1/chat/completions o4-mini {'max_tokens': 256}
The mock transport only records the request; I did not call the live API. The Chat Completions reference says max_tokens "is now deprecated in favor of max_completion_tokens, and is not compatible with o-series models".
Repro steps
import asyncio, json
try:
import httpx2 as httpx # openai>=3 ships its own httpx fork
except ImportError:
import httpx
from openai import AsyncOpenAI
from agents import Agent, ModelSettings, OpenAIChatCompletionsModel, Runner, set_tracing_disabled
set_tracing_disabled(True)
def handler(request):
body = json.loads(request.content)
print(request.url, body["model"], {k: body[k] for k in ("max_tokens", "max_completion_tokens") if k in body})
return httpx.Response(200, json={"id": "c1", "object": "chat.completion", "created": 0, "model": body["model"],
"choices": [{"index": 0, "finish_reason": "stop", "message": {"role": "assistant", "content": "Hello!"}}]})
client = AsyncOpenAI(api_key="sk-test", http_client=httpx.AsyncClient(transport=httpx.MockTransport(handler)))
agent = Agent(name="assistant", model=OpenAIChatCompletionsModel(model="o4-mini", openai_client=client),
model_settings=ModelSettings(max_tokens=256))
asyncio.run(Runner.run(agent, "Say hello."))
Expected behavior
When the client targets the official endpoint, ModelSettings.max_tokens is sent as max_completion_tokens and the run works on reasoning models.
Something like this in _fetch_response would do it, keeping max_tokens for OpenAI-compatible servers that only know the older name and letting an explicit extra_args["max_completion_tokens"] win. The max_tokens == 64 assertion in tests/models/test_openai_chatcompletions_stream.py (official base URL, gpt-5.4-mini) would change with it.
+ if model_settings.max_tokens is not None and ChatCmplHelpers.is_openai(self._get_client()):
+ create_kwargs["max_tokens"] = omit
+ if "max_completion_tokens" not in (model_settings.extra_args or {}):
+ create_kwargs["max_completion_tokens"] = model_settings.max_tokens
- 主要言語
- Python
- スター
- 30.4k
- フォーク
- 4.9k
- 平均マージ
- 19時間 5分
- マージ済み PR(30日)
- 90
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
openai/openai-agents-python のほかの issue
-
Docs: `tool_choice="required"` can select a state-changing tool when the needed one is not shownオープン
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
openai/openai-agents-python#5461 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
openai/openai-agents-python#5460 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
openai/openai-agents-python#5459 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
openai/openai-agents-python#5458 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
openai/openai-agents-python#5451 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
openai/openai-agents-python の issue をすべて見る
似ている issue
-
URLValidator ignores an explicit empty scheme allowlist対応中かも @IlyaKhalafi が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
tortoise/tortoise-orm#2393 ·
メンテナーはふだん 2 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
frappe/frappe_docker#2046 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
complete_box_iou_loss / complete_box_iou: NaN gradients for zero-height boxes, NaN for point boxesオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
AXI SMU SPEC
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
tenstorrent/tt-oca-harness#3556 ·
メンテナーはふだん 1 日以内に返信