Repository navigation
Replay the phase of assistant messages over the Responses API, add GenerateOptions::store - #71
Merged
Merged
Conversation
…enerateOptions::store` The Responses API gives an assistant message a `phase`: `commentary` for a preamble before tool calls, `final_answer` for the answer. A client that replays the history by itself has to send each message back with its phase: without it a preamble can be taken for the final answer. The parser reduced a message to its text, and the request builder rebuilt the assistant messages without the field. Now the parser records the phase of a message as a `ProviderContentPart` right before the text of the message, next to the `reasoning` items that it records already, and the builder sends the text that follows such a part as a message of its own with that phase. A message without a phase is built as before. Add `GenerateOptions::store`. A Responses API request always said `store: false`, and a Chat Completions request could not say it at all, while OpenAI stores Chat Completions by default for new accounts. Nothing changes when the option is not set: a Responses API request says `false`, and a Chat Completions request does not say. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
alexey-milovidov
added a commit
to ClickHouse/ClickHouse
that referenced
this pull request
Dec 4, 2026
…es API The Responses API of OpenAI gives a message of the model a `phase`: `commentary` for a preamble before tool calls, `final_answer` for the answer. The AI agent of the client replays the whole conversation with every request, and it has to send each message back with its phase: without it a preamble can be taken for the final answer. The phase was lost: the SDK reduced a message to its text. - The `contrib/ai-sdk-cpp` submodule is moved to ClickHouse/ai-sdk-cpp#71, which is one commit on top of the `main` of the SDK. Its parser records the phase of a message as a part of the provider right before the text of the message, and its request builder sends the text back as a message with that phase. - `AIAgent::makeAssistantMessage` kept the text of a step once, where it began. A step with two messages would give the text of both the phase of the first, so every text stays where it is, and the texts share the cap of a step. - The answer of a turn was kept as a text alone. It is kept with the parts of the provider as well, like a step with tool calls, so that it goes back as `final_answer`. - Another model gets the conversation without the phases, as it gets it without the `reasoning` items: `? model` drops what only the provider understands. The SDK change also adds `GenerateOptions::store`, and a Chat Completions request to OpenAI itself says `store: false` now, as a Responses API request does. A compatible service at a custom `base_url` is not told, because it may refuse a parameter that it does not know. The documentation says so. #136766 (comment) #136766 (comment) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.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.
Related: ClickHouse/ClickHouse#136766
The
phaseof assistant messages. The Responses API gives an assistant message aphase:commentaryfor a preamble before tool calls,final_answerfor the answer. The guide of OpenAI says that a client that replays the history by itself has to preserve the phase of every message, and that a dropped phase can make a preamble be taken for the final answer.The Responses client replays the history by itself, and it lost the phase: the parser reduced a message to its text, and the request builder rebuilt the assistant messages without the field.
Now the parser records the phase of a message as a
ProviderContentPart({"type": "message", "phase": ...}) right before the text of the message, next to thereasoningitems that it records already. The request builder sends the text that follows such a part as a message of its own with that phase. A message without a phase is built as before, and other providers ignore the part, as they ignore thereasoningitems.GenerateOptions::store. A Responses API request always saidstore: false, and a Chat Completions request could not say it at all, while OpenAI stores Chat Completions by default for new accounts. The new option lets the caller say it. Nothing changes when it is not set: a Responses API request saysfalse, and a Chat Completions request does not say, because a compatible service may not know the parameter.Tests:
OpenAIResponsesParserTest.KeepsThePhaseOfAMessageBeforeItsText,OpenAIResponsesRequestTest.ReplaysThePhaseOfAssistantMessages,MessagesWithoutPhaseStayAsTheyWere,StoresOnlyWhenTheCallerSays,OpenAIClientTest.SaysWhetherToStoreOnlyWhenTheCallerDoes.🤖 Generated with Claude Code
Note
Medium Risk
Changes multi-turn tool-loop request shape for GPT-6 Responses clients; incorrect phase replay could alter model behavior, but scope is limited to OpenAI Responses parsing/building with solid test coverage.
Overview
Fixes OpenAI Responses API history replay by preserving assistant message
phase(commentaryvsfinal_answer) so pre-tool preamble is not mistaken for the final answer. The parser now emits aProviderContentPartwith{"type":"message","phase":...}immediately before the message text; the request builder turns the following text into a separate assistant message that includes thatphase, alongside existingreasoningreplay.Adds optional
GenerateOptions::store: Responses requests still default tostore: falsebut honorstore: truewhen set; Chat Completions only sendsstorewhen the caller sets it, avoiding breakage on compatible APIs. Docs and unit tests cover phase round-trip, mixed phased/unphased content, and store behavior for both builders.Reviewed by Cursor Bugbot for commit b5f7935. Bugbot is set up for automated code reviews on this repo. Configure here.