OpenAIChatCompletionsModel sends max_tokens, which reasoning models reject
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 85/100
Hướng nghiên cứu
Kiểm tra src/agents/models/openai_chatcompletions.py xung quanh dòng 708 trong _fetch_response, nơi max_tokens được đặt. Thêm một kiểm tra sử dụng ChatCmplHelpers.is_openai để gửi max_completion_tokens cho API chính thức. Cập nhật xác nhận max_tokens == 64 trong tests/models/test_openai_chatcompletions_stream.py. Hoàn thành khi script tái hiện in ra max_completion_tokens và bộ test pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 30.4k
- Fork
- 4.9k
- Merge trung bình
- 16 giờ 32 phút
- Pull request đã merge (30 ngày)
- 85
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của openai/openai-agents-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
openai/openai-agents-python#5477 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Voice: default sentence splitter never splits Chinese/Japanese, so TTS waits for the whole replyĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openai/openai-agents-python#5475 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
openai/openai-agents-python#5472 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
OpenAIConversationsSession and OpenAIResponsesCompactionSession ignore set_default_openai_key()Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openai/openai-agents-python#5471 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
openai/openai-agents-python#5468 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của openai/openai-agents-python
Issue tương tự
-
New InternshipĐang mởnew_internship
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
get_graph warns that the oneway column is missing when no way has a oneway tagCó thể đã có người làm @HTenkanen đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cython/cython#8110 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix: security 🔐 style: article/section 📝 system: data-mgmt 🗃️ system: security 🔐 system: software 💻
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
uabrc/uabrc.github.io#1267 ·
-
Link Checker ReportĐang mởBot Type: Bug Type: Documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày