Chat Completions replay emits an invalid sequence for two messages in one tool-call turn
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
The merge logic lives in Converter.items_to_messages in agents/models/chatcmpl_converter.py, and the SDK comment the report quotes about the rejected sequence sits near it. Start by running the repro snippet from the issue to see the current [assistant(tool_calls), assistant, tool] output. Done means that consecutive same-turn messages fold into the tool-call assistant, the tool result follows immediately, and a later assistant turn stays separate. The existing single-message case should still convert as it does now.
索引モデルが issue の本文から書いたものです。
説明
Please read this first
- Have you read the docs? Yes.
- Have you searched for related issues? Yes. #4727 was fixed for a single message following a streamed tool call by #4728; this reports the remaining multi-message case.
Describe the bug
When replaying a Responses-format history ordered as [function_call, message, message, function_call_output], Converter.items_to_messages merges only the first message into the assistant with tool_calls. The second message becomes a separate assistant message before the tool result. The Chat Completions request therefore contains [assistant(tool_calls), assistant, tool]. The SDK's own comment says this sequence is rejected by the API. A message after a refusal in the same tool turn has the same problem.
The malformed payload was observed in a direct converter probe and in the payload passed by Runner.run to a local mocked chat.completions.create. A live HTTP 400 was not measured; the rejection is inferred from the documented Chat Completions tool-call ordering contract and the error shown in #4727.
Debug information
- Agents SDK version: 0.23.1 (also reproduced on
mainat125efa029b4bfd84238bd2c4fd69c3406f802663). - Related library versions: none required for the direct probe.
- Python version: 3.12.
- Operating system: Windows.
- Model and model provider: Chat Completions adapter; local mock client, no paid API call.
- Does the issue reproduce with the latest Agents SDK release? Yes, v0.23.1.
- Does the issue occur consistently or intermittently? Consistently for this input order.
Relevant observed roles:
user
assistant(content='Let me check the weather.', tool_calls=[call_1])
assistant(content='One moment.')
tool(tool_call_id='call_1', content='sunny')
Repro steps
from agents.models.chatcmpl_converter import Converter
items = [
{"role": "user", "content": "What is the weather?"},
{"id": "fc_1", "call_id": "call_1", "name": "get_weather", "arguments": "{}", "type": "function_call"},
{"id": "msg_1", "type": "message", "role": "assistant", "status": "completed", "content": [{"type": "output_text", "text": "Let me check the weather.", "annotations": []}]},
{"id": "msg_2", "type": "message", "role": "assistant", "status": "completed", "content": [{"type": "output_text", "text": "One moment.", "annotations": []}]},
{"type": "function_call_output", "call_id": "call_1", "output": "sunny"},
]
for message in Converter.items_to_messages(items):
print(message)
On v0.23.1, the second assistant message separates the tool-call assistant from its tool result. A control history with just one assistant message between function_call and function_call_output converts correctly.
Expected behavior
The two same-turn text messages should be merged into a single assistant message with the declared tool_calls, immediately followed by the tool result. A later assistant turn after the tool result should stay separate.
- 主要言語
- Python
- スター
- 30k
- フォーク
- 4.9k
- 平均マージ
- 18時間 13分
- マージ済み PR(30日)
- 215
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
openai/openai-agents-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
openai/openai-agents-python#5348 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
openai/openai-agents-python#5353 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
openai/openai-agents-python#5336 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Finished tool call is dropped when a parallel tool's guardrail trips対応中かも @jbeckwith-oai が 7 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
openai/openai-agents-python#5327 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
openai/openai-agents-python#5322 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
openai/openai-agents-python の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Deltares/imod-python#1940 ·
メンテナーはふだん 1 日以内に返信
-
effort: low prio: low ready
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
digitalfabrik/integreat-cms#4621 ·
メンテナーはふだん 5 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
ioos/compliance-checker#1375 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信