Skip to content

Separate reasoning summary entries in OpenAI Responses - #7229

Merged
dimitarproynov merged 2 commits into
spring-projects:mainfrom
draviteja:responses-reasoning-summary-entries
Nov 26, 2026
Merged

dimitarproynov merged 2 commits into
spring-projects:mainfrom
draviteja:responses-reasoning-summary-entries

Conversation

@draviteja

@draviteja draviteja commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A reasoning item in the Responses API can carry several summary entries. Each one is a separate paragraph that usually starts with its own bold heading.
OpenAiResponsesChatModel joins these entries with nothing between them, so the last sentence of one entry runs straight into the heading of the next:

...which helps me determine the correct labels for the others.**Analyzing the box puzzle**

Now, the box labeled "apples" can't actually contain apples or be mixed. ...
Therefore, the box labeled "apples" must actually contain oranges.**Exploring box possibilities**

Rendered as Markdown, these headings show up as bold text in the middle of a paragraph, and the whole summary reads as one block.

This happens on both paths:

  • call: ResponsesItemMapper joins the summary entries with an empty string.
  • stream: ResponsesStreamAssembler appends every response.reasoning_summary_text.delta to one running string and ignores the delta's summary_index, so the boundary between entries is lost before the chunks reach the caller.

To reproduce (2.1.0-RC1, spring.ai.openai.chat.api=responses):

var options = OpenAiResponsesChatOptions.builder()
	.model("gpt-5-mini")
	.reasoningEffort("high")
	.reasoningSummary("detailed")
	.build();

ChatResponse response = chatModel.call(new Prompt(
		"Three boxes are labelled \"apples\", \"oranges\" and \"apples and oranges\", and every label is wrong. "
				+ "You may take one fruit out of one box. Explain how to relabel all three boxes.",
		options));

String summary = response.getResult().getMetadata().get(OpenAiResponsesMetadata.REASONING_CONTENT);

Summary text before and after this change:

-...the correct labels for the others.**Analyzing the box puzzle**
+...the correct labels for the others.
+
+**Analyzing the box puzzle**

Change

  • ResponsesItemMapper joins the summary entries of one reasoning item with a blank line (\n\n).
  • ResponsesStreamAssembler tracks the summary_index of the summary deltas. When a delta starts a new entry of the same item, the same separator is prepended to that delta. The raw flux, the aggregated ReasoningPart and the reasoningContent metadata therefore all agree with the non-streaming result.
  • Empty summary entries are skipped on both paths, so they add no extra paragraph break. On the stream path, an empty delta is dropped and does not count as the start of an entry or of an item.

Unchanged:

  • The \n between different reasoning items.
  • Reasoning content text, which is still joined without a separator.

The reasoningContent row of the reference docs is updated to describe both separators.

Tests

Added to ResponsesItemMapperTests:

  • summaryEntriesAreSeparateParagraphsAndEmptyEntriesAreSkipped

Added to ResponsesStreamAssemblerTests:

  • reasoningSummaryDeltasStartANewParagraphForEachEntryWithinAnItem
  • streamedSummaryEntriesAggregateToTheSameSummaryAsTheNonStreamedResponse
  • summaryEntriesThatNeverStreamedComeFromTheCompletedItems

They use a new fixture, reasoning-with-summary-entries.json, with three reasoning items: one whose first entry is empty, one whose only entry is empty, and one ending with an empty entry. The streaming test sends an empty delta for every empty entry and checks that each item's summary, and reasoningContent, match the non-streaming result.

Also checked manually against the OpenAI API with a sample application: with this change, every summary heading starts its own paragraph on both call and stream, where before most of them were glued to the end of the previous sentence.

@draviteja

Copy link
Copy Markdown
Contributor Author

@dimitarproynov dimitarproynov self-assigned this Oct 26, 2026
@dimitarproynov

Copy link
Copy Markdown
Contributor

I'll have a look as soon as I'm able

@dimitarproynov dimitarproynov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

Few remarks below:

@draviteja

Copy link
Copy Markdown
Contributor Author

@dimitarproynov I’ve addressed all your review comments. Could you take another look when you have a moment?

A reasoning item can carry several summary entries, each a separate
paragraph that usually opens with its own bold heading. They were
joined without a separator, both when building the summary of a
called response and when accumulating streamed deltas, so the last
sentence of one entry ran straight into the heading of the next.

Join the entries of one item with a blank line. On the streaming path
the assembler tracks the summary_index of the deltas and prefixes the
first delta of each further entry with the same separator, so the raw
flux, the aggregated ReasoningPart and the reasoningContent metadata
all agree with the non-streaming result.

Empty summary entries are skipped on both paths, and an empty delta is
dropped without opening an entry or an item, so they add no paragraph
break. The separator between different reasoning items and the joining
of reasoning content text are unchanged.

Signed-off-by: Raviteja Daggupati <raviteja5255@gmail.com>
Rename REASONING_SUMMARY_PART_SEPARATOR to
REASONING_SUMMARY_ENTRY_SEPARATOR, to match the summary entries it
separates.

Say "non-streamed" instead of "called" in the javadoc, comments, test
names and test helper, and rename the paragraph test so it starts with
its subject like the tests around it.

Rewrite the comment on the summary-delta separator in
ResponsesStreamAssembler in plain words: when it applies (same
output_index, new summary_index) and why the blank line goes into the
delta itself.

Signed-off-by: Raviteja Daggupati <raviteja5255@gmail.com>
@draviteja
draviteja force-pushed the responses-reasoning-summary-entries branch from 9f34118 to d565123 Compare November 25, 2026 21:29
@dimitarproynov

Copy link
Copy Markdown
Contributor

@draviteja Thank you, again, for your contribution!

@dimitarproynov
dimitarproynov merged commit a3f9257 into spring-projects:main Nov 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants