Skip to content

fix(api): Responses reasoning items are the next turn's reasoning, not something it said - #2628

Open
chaitanya0305 wants to merge 1 commit into
exo-explore:mainfrom
chaitanya0305:fix/responses-reasoning-as-reasoning-content
Open

chaitanya0305 wants to merge 1 commit into
exo-explore:mainfrom
chaitanya0305:fix/responses-reasoning-as-reasoning-content

Conversation

@chaitanya0305

Copy link
Copy Markdown

Motivation

Codex and other Responses API clients send the previous turns back as input items, including reasoning items. The Responses adapter turned each reasoning item into its own assistant message, with the reasoning as its content, and the function_call that follows was merged into that message. As a result:

  • the model reads its own reasoning as text it said to the user;
  • the prompt no longer matches what the model generated. For Qwen3, the turn was generated as <think>\n...\n</think>\n\n<tool_call>..., but it was re-rendered as ...\n<tool_call>.... The prefix cache therefore misses from that turn onward, on every request of an agent loop;
  • a reasoning item followed by an assistant message became two assistant turns in a row.

Repro: send this input to /v1/responses and render the converted messages with Qwen/Qwen3-0.6B's chat template:

[
  {"type": "message", "role": "user", "content": "List the files."},
  {"type": "reasoning", "summary": [{"type": "summary_text", "text": "I should call ls."}]},
  {"type": "function_call", "call_id": "call_1", "name": "shell", "arguments": "{\"cmd\": \"ls\"}"},
  {"type": "function_call_output", "call_id": "call_1", "output": "a.py b.py"}
]

Before:

<|im_start|>assistant
I should call ls.
<tool_call>
{"name": "shell", "arguments": {"cmd": "ls"}}
</tool_call><|im_end|>

After:

<|im_start|>assistant
<think>
I should call ls.
</think>

<tool_call>
{"name": "shell", "arguments": {"cmd": "ls"}}
</tool_call><|im_end|>

Changes

  • A reasoning item now opens an assistant turn with content: "" and reasoning_content set to the reasoning text. Consecutive reasoning items are concatenated.
  • A following function_call (or other tool call item) joins that turn through the existing _append_tool_call.
  • A following assistant message fills in the turn's content instead of starting a new assistant turn.

Why It Works

reasoning_content is the field that the chat templates (Qwen3, GLM, DeepSeek, ...) and exo's own prompt encoders read for a turn's reasoning. The Chat Completions adapter (reasoning_content) and the Claude adapter (thinking blocks) already pass reasoning that way. Responses requests now take the same path.

Test Plan

Manual Testing

  • Converted the request above with responses_request_to_text_generation and rendered it with the Qwen/Qwen3-0.6B tokenizer's chat template; output before and after is shown above.

Automated Testing

  • TestReasoningInputItems in src/exo/api/tests/test_openai_responses_api.py covers a reasoning item followed by a tool call and one followed by an assistant message. Both tests fail on main and pass with this change.
  • ruff check, ruff format --check and basedpyright are clean on the changed files.

…t something it said

A client that sends reasoning items back (Codex does, every turn) had each one
rendered as an assistant message whose content is the reasoning, and a following
function_call merged into it. The model then reads its own reasoning as text it
said aloud, and the prompt no longer matches what it generated (e.g. Qwen3's
<think> block), so the prefix cache misses at that turn on every request.

A reasoning item now starts the assistant turn that follows it, as
reasoning_content, the way the Chat Completions and Claude adapters pass
reasoning to the chat template.

Signed-off-by: Chaitanya Deshpande <dcchaitanyadeshpande@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant