Repository navigation
capture: replay a Responses turn's text and tool calls as one message - #1783
Merged
burtenshaw merged 3 commits intoDec 1, 2026
Merged
Conversation
A Responses client sends back a past turn that said something and called tools as a message item followed by its function_call items. They were converted into two chat messages, the text alone and then a content-less message with the calls, so every prompt showed the model assistant turns that only talk. It copied them: on SWE-bench Pro, 25 of 49 Hermes runs ended on a turn such as "Now let me implement the changes:" with no tool call. A text-only assistant message directly followed by a content-less assistant message with tool calls is now one message, as the model generated it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
The docs for this pull request are available at https://openenv.github.io/OpenEnv/pr-preview/pr-1783/ (commit a28eb2a). The preview may take a minute to update and is removed when the pull request closes. |
When the text message of a turn already carried reasoning, a reasoning item before its tool calls was dropped by the merge. It is now appended, the way consecutive reasoning items are joined. The case where only the tool-call half carries reasoning, which no test covered, is pinned too. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A Responses client (Hermes) sends back a past turn that said something and called tools as a
messageitem followed by itsfunction_callitems._convert_input_items_to_messagesturns them into two chat messages: the text alone, then a content-less assistant message with the calls. This joins them into one assistant message, as the model generated it.Type of Change
What happened without it
With the turns split, every prompt shows the model a history of assistant turns that only talk, and the model copies them:
Changes
openai_responses.py:_merge_split_assistant_turns, applied to the converted messages, merges a text-only assistant message that is directly followed by a content-less assistant message with tool calls.reasoning_content, it moves onto the merged message.Test Plan
tests/envs/test_capture_responses_turn_merge.py:The first two fail on
main.169 passed.
ruff format --check,ruff checkandusort checkare clean.Used in production as a runtime patch for Hermes GRPO training and SWE-bench Pro evals.
For reviewers: codex also speaks Responses. A codex turn that produced text and tool calls in one response is merged the same way, which is again what was sampled. If a client ever sends a text-only reply and then, in a separate call with no input in between, a tool-call-only reply, the two would also be merged. I haven't seen that sequence in any harness.
RFC Status
🤖 Generated with Claude Code
Note
Medium Risk
Changes how historical conversation is rendered for all Responses replay paths, which affects model behavior and training/eval prompts; logic is narrow but high-impact for agent harnesses.
Overview
Fixes Responses API → chat replay so a turn that produced assistant text and tool calls in one generation is stored as a single assistant message instead of two (text-only, then tool-only).
_convert_input_items_to_messagesnow post-processes through_merge_split_assistant_turns, which only joins an assistant message withcontentand notool_callswhen it is immediately followed by an assistant message withtool_callsand nocontent, carrying over mergedreasoning_contentwhen needed. Tool-only, text-only, and other sequences are left unchanged.Adds
tests/envs/test_capture_responses_turn_merge.pyfor merge behavior, reasoning attachment, and unchanged edge cases.Reviewed by Cursor Bugbot for commit a28eb2a. Bugbot is set up for automated code reviews on this repo. Configure here.