Skip to content

Keep thinking models' reasoning across agent turns on vLLM - #463

Closed
gregorybchris wants to merge 1 commit into
mainfrom
chrisg/agents-reasoning-replay
Closed

gregorybchris wants to merge 1 commit into
mainfrom
chrisg/agents-reasoning-replay

Conversation

@gregorybchris

@gregorybchris gregorybchris commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Toward #461. Thinking models served by vLLM now keep their reasoning across agent turns in the openai_agents scaffold. Before this, Qwen3.5 with thinking on ended every agent run after one tool call.

Cause

Two gaps between vLLM 0.19.1 and openai-agents 0.20:

  1. The SDK dropped the reasoning. vLLM returns reasoning-parser output in message.reasoning, and the SDK reads only reasoning_content.
  2. Earlier turns lost their reasoning. The SDK replays reasoning into later requests only for DeepSeek models by default. For other models, earlier assistant turns went back to the chat template with empty think blocks. Qwen3.5 then put its next tool call inside an unclosed <think> block. The reasoning parser classified the whole thing as reasoning with tool_calls=[], and the SDK treated that as the final answer.

Changes

  • patch_openai_agents_for_vllm (inference/utils.py): the SDK's converter now reads reasoning as reasoning_content when only the former is present, so the model's reasoning becomes a reasoning item. The patch is idempotent and separate from the existing strict patch.
  • replay_own_reasoning (harness/scaffolds/openai_agents.py): this is passed as the SDK's should_replay_reasoning_content hook. It replays a reasoning item when the current model produced it, or when the item's origin is unknown. It applies only to self-hosted servers, using the same check the scaffold already uses for chat_template_kwargs. Managed APIs keep the SDK default, because they would reject the extra field.

Runs with thinking off are unaffected, because there is no reasoning to replay.

Tests

TestReasoningReplay in tests/core/harness/test_openai_agents_scaffold.py:

  • Two-turn agent run against a scripted chat endpoint:
    • turn 1 returns vLLM-style reasoning plus a tool call,
    • the test asserts the turn-2 request carries that reasoning as reasoning_content for a self-hosted provider, and omits it for a managed one.
  • Converter patch: turns reasoning into a reasoning item.
  • Replay rule: replay_own_reasoning replays the model's own reasoning and items of unknown origin, but not another model's.

Five of the six new tests fail without the source change. The one that passes is the managed-provider case, which is unchanged by design.

  • uv run ruff check src/ tests/ and uv run ruff format --check src/ tests/: clean.
  • uv run ty check src/ alembic/: same two diagnostics as main.
  • uv run pytest tests/ --ignore=tests/integration: 3306 passed, 35 skipped. The scaffold tests (24 passed) run with --extra agents.

Verification on Beaker

This change is not enough on its own. SWE-bench Verified (#445) with this change applied, Qwen3.5-9B, the same 20 instances (every 25th), with reasoning_parser=qwen3 and max_model_len=131072:

Run Resolved Empty patch How runs ended
Thinking on 0/20 20/20 all complete, after one tool call (median trajectory: 2 entries)
Thinking off (control) 13/20 2/20 5 submitted, 15 max_turns

With thinking on, every run still ends after its first tool call, the same symptom as before. The unit tests show the reasoning is now carried into the next request on self-hosted servers. That isn't what stops the run, though, or this change doesn't take effect on vLLM.

Next step: a one-instance run with vLLM request and response logging (enable_log_requests, enable_log_outputs) to see the second turn's request and response directly. Converted to draft until that's resolved.

🤖 Generated with Claude Code

vLLM returns reasoning parser output as `reasoning`, which openai-agents
only reads as `reasoning_content`, and the SDK replays reasoning into later
turns only for DeepSeek models. With Qwen3.5 thinking enabled this made the
model put its second tool call inside an unclosed think block, ending every
agent run after one tool call.

Read either field, and replay a model's own reasoning on self-hosted
servers. Managed APIs keep the SDK default.

Fixes #461

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@gregorybchris
gregorybchris requested a review from a team as a code owner October 13, 2026 00:08
@gregorybchris gregorybchris mentioned this pull request Oct 13, 2026
8 of 12 tasks
@gregorybchris
gregorybchris marked this pull request as draft October 13, 2026 01:42
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